Additional optional configuration settings are:
:interval: Time between reports to InfluxDB. Default 5 seconds.
-:database: InfluxDB database name. Default "ceph"
+:database: InfluxDB database name. Default "ceph". You will need to create this database and grant write privileges to the configured username or the username must have admin privileges to create it.
:port: InfluxDB server port. Default 8086
try:
from influxdb import InfluxDBClient
+ from influxdb.exceptions import InfluxDBClientError
except ImportError:
InfluxDBClient = None
password = self.get_config("password", default="")
client = InfluxDBClient(host, port, username, password, database)
- databases_avail = client.get_list_database()
- if database not in databases_avail:
- self.log.info("Creating database '{0}'".format(database))
- client.create_database(database)
- client.write_points(self.get_df_stats(), 'ms')
- client.write_points(self.get_daemon_stats(), 'ms')
+ # using influx client get_list_database requires admin privs, instead we'll catch the not found exception and inform the user if db can't be created
+ try:
+ client.write_points(self.get_df_stats(), 'ms')
+ client.write_points(self.get_daemon_stats(), 'ms')
+ except InfluxDBClientError as e:
+ if e.code == 404:
+ self.log.info("Database '{0}' not found, trying to create (requires admin privs). You can also create manually and grant write privs to user '{1}'".format(database,username))
+ client.create_database(database)
+ else:
+ raise
def shutdown(self):
self.log.info('Stopping influx module')
interval = 5
self.log.debug("sleeping for %d seconds",interval)
self.event.wait(interval)
-
\ No newline at end of file
+