aboutsummaryrefslogtreecommitdiffstats
path: root/influx.py
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2019-12-07 14:48:25 +0100
committerMartin/Geno <geno+dev@fireorbit.de>2019-12-07 14:48:25 +0100
commit9c33cf856b7fc51300f7c803195a8b75f7fa127e (patch)
tree580d2a3cfe59d67762cbc2a1ceb885a8e615576a /influx.py
parente3e3222f203d8ec209bd63d1229090472ef7ba49 (diff)
systemd compliance
+ add possibility to customize db name via config file + file path configurations are dealt with dynamically * at least Debian does not feature a group called nobody it is called nogroup I am not sure if other systems feature a group called nobody.
Diffstat (limited to 'influx.py')
-rw-r--r--influx.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/influx.py b/influx.py
index fcf2f41..049bef0 100644
--- a/influx.py
+++ b/influx.py
@@ -3,6 +3,7 @@
import json
import time
+import os
from influxdb import InfluxDBClient
@@ -57,7 +58,7 @@ class Influx:
data.append("{m},vhost={vh} registered={v}i {ts}".format(m=name, vh= vhost, v=self._metrics.get_registered(vhost),ts=cur_ts))
data.append("{m},vhost={vh} muc={v}i {ts}".format(m=name, vh= vhost, v=self._metrics.get_muc(vhost), ts=cur_ts))
- # vhost statistics on their repsective node
+ # vhost statistics on their respective node
for node in self._metrics.get_nodes():
cur_ts = self._timestamp()
for k, v in self._metrics.get_online_by_status(node=node, vhost=vhost).items():
@@ -73,24 +74,26 @@ class Influx:
data.append(self._parse("ejabberd_online_client_ipversion", k, v, cur_ts, {"vhost": vhost, "node": node, "ipversion": k, "client": cl}))
# write output to database
- self.client.write_points(data, database='custom', time_precision='ms', batch_size=10000, protocol='line')
+ self.client.write_points(data, time_precision='ms', batch_size=10000, protocol='line')
+
if __name__ == "__main__":
- with open("config.json", "r", encoding="utf-8") as f:
- login = json.load(f)
+ # load config
+ path = os.path.dirname(__file__)
+ with open("/".join([path, "config.json"]), "r", encoding="utf-8") as f:
+ config = json.load(f)
# init global handler
- metrics = EjabberdMetrics("http://localhost:4560", login)
- client = InfluxDBClient(host='localhost', port=8086, database='custom')
+ metrics = EjabberdMetrics("http://localhost:4560", config['login'])
+ client = InfluxDBClient(host='localhost', port=8086, database=config['database'], retries=5)
# create database only once
- client.create_database('custom')
+ client.create_database(config['database'])
# init influx class
influx = Influx(metrics, client)
while True:
- # TODO this will fail when the connection drops try except maybe?
metrics.update()
influx.writeMetrics()