From d92c91147aef0a58795d8d51811bc4cb9c805b13 Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 29 Oct 2019 16:58:09 +0100 Subject: [PATCH 1/3] 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. --- .../linux-systemd/ejabberd-influxdb.service | 2 +- influx.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/contrib/init/linux-systemd/ejabberd-influxdb.service b/contrib/init/linux-systemd/ejabberd-influxdb.service index bade80f..4ac487e 100644 --- a/contrib/init/linux-systemd/ejabberd-influxdb.service +++ b/contrib/init/linux-systemd/ejabberd-influxdb.service @@ -4,7 +4,7 @@ Description=ejabberd2influxdb [Service] Type=simple User=nobody -Group=nobody +Group=nogroup ExecStart=/opt/ejabberd-metrics/influx.py Restart=always RestartSec=5s 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() From 2f9f36835c09db538ccc2fd67097a8ee693bb1cb Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 29 Oct 2019 17:01:24 +0100 Subject: [PATCH 2/3] moar clients * add some more clients and acronyms to the list + add requirements file --- ejabberdrpc.py | 8 +++++++- requirements.txt | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100755 => 100644 ejabberdrpc.py create mode 100644 requirements.txt diff --git a/ejabberdrpc.py b/ejabberdrpc.py old mode 100755 new mode 100644 index cee769b..93717f8 --- a/ejabberdrpc.py +++ b/ejabberdrpc.py @@ -29,10 +29,16 @@ class EjabberdMetrics(): "Conv6ations for Sum7": ["Conversations with IPv6"], "Conversations": [], "Pix-Art Messenger": [], + "Gajim": ["gajim", "Gajim"], + "Psi+": [], "jitsi": [], - "dino": [], + "Dino": ["dino", "Dino"], "poezio": [], + "profanity": [], + "Xabber": [], + "ChatSecure": ["chatsecure"] } + for client, names in clientmap.items(): for c in names: if c in resource: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d923c8d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +influxdb>=5.2.0 \ No newline at end of file From c66226cb33026ff29ee033d7412c33bb27995e4c Mon Sep 17 00:00:00 2001 From: nico Date: Tue, 29 Oct 2019 20:07:25 +0100 Subject: [PATCH 3/3] * misinterpreted assignment --- ejabberdrpc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ejabberdrpc.py b/ejabberdrpc.py index 93717f8..f1215e9 100644 --- a/ejabberdrpc.py +++ b/ejabberdrpc.py @@ -29,10 +29,10 @@ class EjabberdMetrics(): "Conv6ations for Sum7": ["Conversations with IPv6"], "Conversations": [], "Pix-Art Messenger": [], - "Gajim": ["gajim", "Gajim"], + "Gajim": ["gajim"], "Psi+": [], "jitsi": [], - "Dino": ["dino", "Dino"], + "Dino": ["dino"], "poezio": [], "profanity": [], "Xabber": [],