Commit e28e81f6 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Réactivation d'influxdb

parent 037e997b
......@@ -151,19 +151,61 @@ def main():
# Write to postgres database
conn = psycopg2.connect(dbname=cfg['postgres']['database'], user=cfg['postgres']['user'], host=cfg['postgres']['host'], password=cfg['postgres']['password'], port=cfg['postgres']['port'])
cur = conn.cursor()
execute_values(cur,
if 'postgres' in cfg:
logger.info('Writing to postgres database')
conn = psycopg2.connect(dbname=cfg['postgres']['database'], user=cfg['postgres']['user'], host=cfg['postgres']['host'], password=cfg['postgres']['password'], port=cfg['postgres']['port'])
cur = conn.cursor()
execute_values(cur,
"""INSERT INTO datastats (network, year, type, size, is_permanent, date) VALUES %s""",
statistics,
"(%(network)s, %(year)s, %(type)s, %(size)s, %(is_permanent)s, %(date)s)")
logger.debug("Coucou, terminé")
conn.commit()
conn.close()
conn = psycopg2.connect(dbname=cfg['postgres']['database'], user=cfg['postgres']['user'], host=cfg['postgres']['host'], password=cfg['postgres']['password'], port=cfg['postgres']['port'])
cur = conn.cursor()
cur.execute("select * from datastats")
logger.debug(cur.fetchall())
conn.commit()
if 'influxdb' in cfg:
logger.info('Writing in influxdb')
influxdb_json_data = []
# Compose json data
record_time = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())
for stat in statistics:
influxdb_json_data.append(
{"measurement": cfg['influxdb']['measurement'],
"tags": {
"year": stat['year'],
"network": stat['network'],
"permanent": stat['is_permanent'],
"type": stat['type'],
"date": today
},
"time": record_time,
"fields": {
"size": stat['size']
}
}
)
logger.info(pformat(influxdb_json_data))
# Now, send this data to influxdb
try:
logger.info("Sending data to influxdb")
logger.debug("host = "+cfg['influxdb']['server'])
logger.debug("port = "+str(cfg['influxdb']['port']))
logger.debug("database = "+cfg['influxdb']['database'])
logger.debug("username = "+cfg['influxdb']['user'])
client = InfluxDBClient(host = cfg['influxdb']['server'],
port = cfg['influxdb']['port'],
database = cfg['influxdb']['database'],
username = cfg['influxdb']['user'],
password = cfg['influxdb']['password'],
ssl = cfg['influxdb']['ssl'],
verify_ssl = cfg['influxdb']['verify_ssl']
)
client.write_points(influxdb_json_data)
except Exception as e:
logger.error("Unexpected error writing data to influxdb")
logger.error(e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment