From abc26e487580dd298d6d9623db968707fd784558 Mon Sep 17 00:00:00 2001 From: Vitaliy Skrypnyk <2773025+vitaliy-sk@users.noreply.github.com> Date: Mon, 27 Jul 2020 22:09:31 +0300 Subject: [PATCH] Add json config --- config.json | 14 ++++++++++++++ keentic_influxdb_exporter.py | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..b16162c --- /dev/null +++ b/config.json @@ -0,0 +1,14 @@ +{ + "endpoint" : "http://192.168.1.1:79/rci", + "interval_sec" : 10, + "metrics" : [ + { + "command": "processes", + "tags_level" : [ 1 ] + }, + { + "command": "ip hotspot", + "tags_level" : [ ] + } + ] +} \ No newline at end of file diff --git a/keentic_influxdb_exporter.py b/keentic_influxdb_exporter.py index 7e89614..f492a94 100644 --- a/keentic_influxdb_exporter.py +++ b/keentic_influxdb_exporter.py @@ -3,20 +3,22 @@ import time import requests from typing import Dict + from value_normalizer import normalize_data, isvalidmetric class KeeneticCollector(object): - def __init__(self, endpoint, request, tags_levels): + def __init__(self, endpoint, command, tags_levels): self._endpoint = endpoint - self._request = request + self._command = command self._tags_levels = tags_levels def collect(self): - response = json.loads(requests.get(self._endpoint).content.decode('UTF-8')) - prefix = self._request.split(' ') + url = '{}/show/{}'.format(self._endpoint, self._command.replace(' ', '/')) + response = json.loads(requests.get(url).content.decode('UTF-8')) + prefix = self._command.split(' ') metrics = self.recursive_iterate(response, prefix, [], {}, 0) for metric in metrics: @@ -81,7 +83,15 @@ class KeeneticCollector(object): if __name__ == '__main__': - (KeeneticCollector('http://192.168.1.1:79/rci/show/processes', 'processes', [1])).collect() - # (KeeneticCollector('http://192.168.1.1:79/rci/show/processes', 'processes', [1])).collect() + configuration = json.load(open("config.json", "r")) + endpoint = configuration['endpoint'] + metrics = configuration['metrics'] - # while True: time.sleep(1) + collectors = [] + + for metric in metrics: + collectors.append( KeeneticCollector(endpoint, metric['command'], metric['tags_level']) ) + + while True: + for collector in collectors: collector.collect() + time.sleep(configuration['interval_sec'])