Isilon / isilon_data_insights_connector

Connector to fetch stats from OneFS and push them to InfluxDB/Grafana
MIT License
74 stars 36 forks source link

Support for InfluxDB 2.0 #106

Open xniega-be opened 3 years ago

xniega-be commented 3 years ago

It seems that there are changes between InfluxDB 1.7 and 2.0. Our working system stopped functioning when the influx repo in our internal mirror was changed to 2.0. Will there be support for the new InfluxDB soon or should we revert to backups?

tkops commented 2 years ago

I have got the same problem. InfluxDB2 was completely redesigned. no longer works with databases but with buckets. There is e.g. no "create database" in the API anymore.

tenortim commented 2 years ago

Hi, sorry for the huge delays. Yes, InfluxDB 2 is incompatible with version 1 in a lot of ways. Currently, I am only support version 1. I have spent a little time looking at 2, but don't have any timeline for support. I'm more interested by the Rust rewrite (Iox), but that's a ways off. In general, I'd ask folks to politely ask their IT people to mirror both InffluxDB 1.x and 2.x because they're quite different and 1.x is still fully supported.

moma8468 commented 1 year ago

Possible cheap workaround (until you support this properly with InfluxDB 2.0 compliant client) would be to use telegraf to expose influxdb 1.x listener and pipe that toward influxdb 2.0. The problem here is that telegraf input plugin requires line protocol, which means that your tool would need to feed data in proper format.

Would it be possible to implement addition config option to support changing the write protocol?

tenortim commented 1 year ago

I added InfluxDB 2.0 collection support in a branch in my alternative Golang-based collector, gostats. I haven't made that the main branch because I feel that the dashboards should also be rewritten in Flux and that's a more substantial effort. But if you want a collector that can already target InfluxDB 2.x, you may wish to check out my go-based collector instead.

moma8468 commented 1 year ago

Thank you for responding. 👍 A little update from my side: I tried to force the protocol to be line, but it failed miserably. So my suggestion is not valid workaround at the moment. The upstream library requires different format for points (array of string) and is in archived state, so I gave up on that.

I will give a go client a try and let you know.

petew-nfx commented 6 months ago

You. can write to InfluxDB 2.0 if you use the influxdb_client library rather than influxdb library. Then patch influxdb_plugin.py with below.

NOTE: I have not tested the database creation. YMMV

7,9c7,9
< from influxdb import InfluxDBClient
< from influxdb.exceptions import InfluxDBServerError, InfluxDBClientError
< from ast import literal_eval
---
> from influxdb_client import InfluxDBClient
> from influxdb_client.client.exceptions import InfluxDBError
> from influxdb_client.client.write_api import SYNCHRONOUS
14a15
> import os
44,47c45
<     Instantiate an InfluxDBClient. The expected inputs are the host/address and
<     port of the InfluxDB and the name of the database to use. If the database
<     does not exist then it will be created. If the fourth arg is "auth" then it
<     will prompt the user for the InfluxDB's username and password.
---
>     InfluxDB settings passed in via environment variables.
49,55c47,51
<     influxdb_host = argv[0]
<     influxdb_port = int(argv[1])
<     influxdb_name = argv[2]
<     influxdb_ssl = False
<     influxdb_verifyssl = False
<     influxdb_username = "root"
<     influxdb_password = "root"
---
>     influxdb_url = os.getenv("INFLUX_URL")
>     influxdb_token = os.getenv("INFLUX_TOKEN")
>     influxdb_org = os.getenv("INFLUX_ORG")
>     global influxdb_bucket
>     influxdb_bucket = os.getenv("INFLUX_BUCKET")
57,66d52
<     if len(argv) > 3:
<         if argv[3] == "auth":
<             influxdb_username = input("InfluxDB username: ")
<             influxdb_password = getpass.getpass("Password: ")
<         else:
<             influxdb_username = argv[3]
<             influxdb_password = argv[4]
<             influxdb_ssl = literal_eval(argv[5])
<             influxdb_verifyssl = literal_eval(argv[6])
<
68,74c54,57
<         "Connecting to: %s@%s:%d database:%s ssl=%s verify_ssl=%s.",
<         influxdb_username,
<         influxdb_host,
<         influxdb_port,
<         influxdb_name,
<         influxdb_ssl,
<         influxdb_verifyssl,
---
>         "Connecting to: %s org: %s bucket: %s.",
>         influxdb_url,
>         influxdb_org,
>         influxdb_bucket,
78,86c61,62
<     g_client = InfluxDBClient(
<         host=influxdb_host,
<         port=influxdb_port,
<         database=influxdb_name,
<         username=influxdb_username,
<         password=influxdb_password,
<         ssl=influxdb_ssl,
<         verify_ssl=influxdb_verifyssl
<     )
---
>     client = InfluxDBClient(url=influxdb_url,token=influxdb_token,org=influxdb_org)
>     g_client = client.write_api(write_options=SYNCHRONOUS)
88,98d63
<     create_database = True
<     try:
<         databases = g_client.get_list_database()
<     except (requests.exceptions.ConnectionError, InfluxDBClientError) as exc:
<         print(
<             "Failed to connect to InfluxDB server at %s:%s "
<             "database: %s.\nERROR: %s"
<             % (influxdb_host, str(influxdb_port), influxdb_name, str(exc)),
<             file=sys.stderr,
<         )
<         sys.exit(1)
100,109d64
<     for database in databases:
<         if database["name"] == influxdb_name:
<             create_database = False
<             break
<
<     if create_database is True:
<         LOG.info("Creating database: %s.", influxdb_name)
<         g_client.create_database(influxdb_name)
<
<
289a245
>         LOG.debug("Points to write: %s\n%s", _get_point_names(write_points), write_points)
291c247
<             g_client.write_points(write_points)
---
>             g_client.write(influxdb_bucket, record=write_points)
293c249
<         except InfluxDBServerError as svr_exc:
---
>         except InfluxDBError as svr_exc:
295c251
<                 "InfluxDBServerError: %s\nFailed to write points: %s",
---
>                 "InfluxDBError: %s\nFailed to write points: %s",
299,304d254
<         except InfluxDBClientError as client_exc:
<             LOG.error(
<                 "InfluxDBClientError writing points: %s\n" "Error: %s",
<                 _get_point_names(write_points),
<                 str(client_exc),
<             )