From a9c82960be092e311423d555de863bf5a3a22055 Mon Sep 17 00:00:00 2001 From: C1299593 Phillipe Smith Carvalho Chaves Date: Tue, 24 Sep 2019 16:01:58 -0300 Subject: [PATCH] Fixed metrics collection bug --- README.md | 5 ++++- rundeck_exporter.py | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 081222d..2735127 100644 --- a/README.md +++ b/README.md @@ -134,4 +134,7 @@ docker run --rm -d -p 9620:9620 rundeck_exporter \ `v1.1.0`: * Support for environment variables * Better excpetions treatment -* Changes on rundeck_system_stats metrics names + +`v1.1.1`: +* Fixed metrics collection bug + diff --git a/rundeck_exporter.py b/rundeck_exporter.py index 09e05a5..6b225a1 100755 --- a/rundeck_exporter.py +++ b/rundeck_exporter.py @@ -56,25 +56,11 @@ class RundeckMetricsCollector(object): def __init__(self): - ssl_verify = False if str(args.rundeck_skip_ssl) in ['1', 'yes', 'True'] else True + self.ssl_verify = False if str(args.rundeck_skip_ssl) in ['1', 'yes', 'True'] else True if not args.rundeck_url or not args.rundeck_token: self.exit_with_msg('Rundeck URL and Token are required.') - self.get_system_info = self.request_data( - args.rundeck_url, - 'system/info', - args.rundeck_token, - ssl_verify - ) - - self.get_metrics = self.request_data( - args.rundeck_url, - 'metrics/metrics', - args.rundeck_token, - ssl_verify - ) - def request_data(self, rundeck_url: str, endpoint: str, token: str, verify: bool = True) -> dict: try: response = requests.get( @@ -94,12 +80,26 @@ def request_data(self, rundeck_url: str, endpoint: str, token: str, verify: bool return error def collect(self): + get_system_info = self.request_data( + args.rundeck_url, + 'system/info', + args.rundeck_token, + self.ssl_verify + ) + + get_metrics = self.request_data( + args.rundeck_url, + 'metrics/metrics', + args.rundeck_token, + self.ssl_verify + ) + rundeck_system_info = InfoMetricFamily('rundeck_system', 'Rundeck system info') - rundeck_system_info.add_metric([], {x: str(y) for x, y in self.get_system_info['system']['rundeck'].items()}) + rundeck_system_info.add_metric([], {x: str(y) for x, y in get_system_info['system']['rundeck'].items()}) yield rundeck_system_info - for stat, stat_values in self.get_system_info['system']['stats'].items(): + for stat, stat_values in get_system_info['system']['stats'].items(): for counter, value in stat_values.items(): if counter == 'unit': continue @@ -122,7 +122,7 @@ def collect(self): 'Rundeck counters metrics', labels=['status']) - for metric, metric_value in self.get_metrics.items(): + for metric, metric_value in get_metrics.items(): if not isinstance(metric_value, dict): continue