From a5a39958cc37f1415457d8361d7bcde5c1d34325 Mon Sep 17 00:00:00 2001 From: genofire Date: Sat, 7 Dec 2019 16:01:03 +0100 Subject: improve configuration (with default values) - also for testing ejabberdrpc.py --- prometheus.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'prometheus.py') diff --git a/prometheus.py b/prometheus.py index e534f16..dfca7d4 100755 --- a/prometheus.py +++ b/prometheus.py @@ -86,9 +86,25 @@ class Prometheus(): t.start() if __name__ == "__main__": - metrics = EjabberdMetrics("http://[::1]:4560") + import os + import json + + # load config + path = os.path.dirname(__file__) + with open("/".join([path, "config.json"]), "r", encoding="utf-8") as f: + config = json.load(f) + + + url = config['url'] if "url" in config else "http://[::1]:5280/api" + login = config['login'] if "login" in config else None + api = config['api'] if "api" in config else "rest" + + prom_port = config['prometheus_port'] if "prometheus_port" in config else 8080 + prom_refresh = config['prometheus_refresh'] if "prometheus_refresh" in config else 10 + + metrics = EjabberdMetrics(url, login, api) prom = Prometheus(metrics) - prom.listen(8080) + prom.listen(prom_port) while True: metrics.update() - time.sleep(10) + time.sleep(prom_refresh) -- cgit v1.2.3-18-g5258