mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-01 14:08:34 +03:00
glances_influxdb.py: use client for InfluxDB v0.8.x
To use the API for 0.8.x, the legacy client has to be imported explicitly. Fix bad continuation.
This commit is contained in:
parent
571b9eb999
commit
58a1361769
@ -30,8 +30,10 @@ except ImportError: # Python 2
|
||||
from glances.core.glances_logging import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
from influxdb import InfluxDBClient, client
|
||||
from influxdb.influxdb08 import InfluxDBClient as InfluxDBClient_Legacy
|
||||
from influxdb import InfluxDBClient
|
||||
from influxdb.client import InfluxDBClientError
|
||||
from influxdb.influxdb08 import InfluxDBClient as InfluxDBClient08
|
||||
from influxdb.influxdb08.client import InfluxDBClientError as InfluxDBClientError08
|
||||
|
||||
|
||||
class Export(GlancesExport):
|
||||
@ -93,19 +95,18 @@ class Export(GlancesExport):
|
||||
password=self.password,
|
||||
database=self.db)
|
||||
get_all_db = [i['name'] for i in db.get_list_database()]
|
||||
except client.InfluxDBClientError as e:
|
||||
try:
|
||||
# https://github.com/influxdb/influxdb-python/issues/138
|
||||
logger.info("Trying fallback to InfluxDB v0.8")
|
||||
db = InfluxDBClient_Legacy(host=self.host,
|
||||
port=self.port,
|
||||
username=self.user,
|
||||
password=self.password,
|
||||
database=self.db)
|
||||
get_all_db = [i['name'] for i in db.get_list_database()]
|
||||
except Exception:
|
||||
logger.critical("Can not connect to InfluxDB database '%s' (%s)" % (self.db, e))
|
||||
sys.exit(2)
|
||||
except InfluxDBClientError:
|
||||
# https://github.com/influxdb/influxdb-python/issues/138
|
||||
logger.info("Trying fallback to InfluxDB v0.8")
|
||||
db = InfluxDBClient08(host=self.host,
|
||||
port=self.port,
|
||||
username=self.user,
|
||||
password=self.password,
|
||||
database=self.db)
|
||||
get_all_db = [i['name'] for i in db.get_list_database()]
|
||||
except InfluxDBClientError08 as e:
|
||||
logger.critical("Cannot connect to InfluxDB database '%s' (%s)" % (self.db, e))
|
||||
sys.exit(2)
|
||||
|
||||
if self.db in get_all_db:
|
||||
logger.info(
|
||||
@ -122,12 +123,7 @@ class Export(GlancesExport):
|
||||
name = self.prefix + '.' + name
|
||||
# logger.info(self.prefix)
|
||||
# Create DB input
|
||||
data = [
|
||||
{
|
||||
"name": name,
|
||||
"columns": columns,
|
||||
"points": [points]
|
||||
}]
|
||||
data = [{'name': name, 'columns': columns, 'points': [points]}]
|
||||
# Write input to the InfluxDB database
|
||||
try:
|
||||
self.client.write_points(data)
|
||||
|
Loading…
Reference in New Issue
Block a user