Skip to content

Commit

Permalink
Fixed metrics collection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
C1299593 Phillipe Smith Carvalho Chaves committed Sep 24, 2019
1 parent 6b0ea2f commit a9c8296
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

36 changes: 18 additions & 18 deletions rundeck_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit a9c8296

Please sign in to comment.