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:
Alessio Sergi 2015-05-16 23:56:16 +02:00
parent 571b9eb999
commit 58a1361769

View File

@ -30,8 +30,10 @@ except ImportError: # Python 2
from glances.core.glances_logging import logger from glances.core.glances_logging import logger
from glances.exports.glances_export import GlancesExport from glances.exports.glances_export import GlancesExport
from influxdb import InfluxDBClient, client from influxdb import InfluxDBClient
from influxdb.influxdb08 import InfluxDBClient as InfluxDBClient_Legacy from influxdb.client import InfluxDBClientError
from influxdb.influxdb08 import InfluxDBClient as InfluxDBClient08
from influxdb.influxdb08.client import InfluxDBClientError as InfluxDBClientError08
class Export(GlancesExport): class Export(GlancesExport):
@ -93,19 +95,18 @@ class Export(GlancesExport):
password=self.password, password=self.password,
database=self.db) database=self.db)
get_all_db = [i['name'] for i in db.get_list_database()] get_all_db = [i['name'] for i in db.get_list_database()]
except client.InfluxDBClientError as e: except InfluxDBClientError:
try: # https://github.com/influxdb/influxdb-python/issues/138
# https://github.com/influxdb/influxdb-python/issues/138 logger.info("Trying fallback to InfluxDB v0.8")
logger.info("Trying fallback to InfluxDB v0.8") db = InfluxDBClient08(host=self.host,
db = InfluxDBClient_Legacy(host=self.host, port=self.port,
port=self.port, username=self.user,
username=self.user, password=self.password,
password=self.password, database=self.db)
database=self.db) get_all_db = [i['name'] for i in db.get_list_database()]
get_all_db = [i['name'] for i in db.get_list_database()] except InfluxDBClientError08 as e:
except Exception: logger.critical("Cannot connect to InfluxDB database '%s' (%s)" % (self.db, e))
logger.critical("Can not connect to InfluxDB database '%s' (%s)" % (self.db, e)) sys.exit(2)
sys.exit(2)
if self.db in get_all_db: if self.db in get_all_db:
logger.info( logger.info(
@ -122,12 +123,7 @@ class Export(GlancesExport):
name = self.prefix + '.' + name name = self.prefix + '.' + name
# logger.info(self.prefix) # logger.info(self.prefix)
# Create DB input # Create DB input
data = [ data = [{'name': name, 'columns': columns, 'points': [points]}]
{
"name": name,
"columns": columns,
"points": [points]
}]
# Write input to the InfluxDB database # Write input to the InfluxDB database
try: try:
self.client.write_points(data) self.client.write_points(data)