From 55fc3e1ce53aa1d95b3656a92d552e11e506b9f2 Mon Sep 17 00:00:00 2001 From: Phillipe Smith Date: Tue, 2 Mar 2021 18:19:36 -0300 Subject: [PATCH] Fix issue #11 --- README.md | 3 +++ rundeck_exporter.py | 42 +++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 091282b..a3b7e7a 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,9 @@ docker run --rm -d -p 9620:9620 -e RUNDECK_TOKEN=$RUNDECK_TOKEN rundeck_exporter ``` ## Changelog +`2.2.4`: +* Fix issue Regarding execution status #11 - Modified GaugeMetricFamily location in the function get_project_executions + `2.2.3`: * Fix issue invalid API request #10 - Added warning message for API version < 25 diff --git a/rundeck_exporter.py b/rundeck_exporter.py index 4c26c74..46aa4d9 100755 --- a/rundeck_exporter.py +++ b/rundeck_exporter.py @@ -145,34 +145,34 @@ def get_project_executions(self, project: dict): else: project_executions = self.request_data_from(endpoint) - duration_metrics = GaugeMetricFamily( - 'rundeck_project_execution_duration_seconds', - f'Rundeck Project {project_name} Execution Duration', - labels=['project_name', 'job_id', 'job_name'] - ) - - start_metrics = GaugeMetricFamily( - 'rundeck_project_start_timestamp', - f'Rundeck Project {project_name} Start Timestamp', - labels=['project_name', 'job_id', 'job_name'] - ) - - metrics = GaugeMetricFamily( - 'rundeck_project_execution_status', - f'Rundeck Project {project_name} Execution Status', - labels=['project_name', 'job_id', 'job_name', 'status'] - ) - for project_execution in project_executions['executions']: job_info = project_execution.get('job', {}) job_id = job_info.get('id', 'None') job_name = job_info.get('name', 'None') - if not project_executions or job_id in jobs_list: + if job_id in jobs_list: continue jobs_list.append(job_id) + start_metrics = GaugeMetricFamily( + 'rundeck_project_start_timestamp', + f'Rundeck Project {project_name} Start Timestamp', + labels=['project_name', 'job_id', 'job_name'] + ) + + duration_metrics = GaugeMetricFamily( + 'rundeck_project_execution_duration_seconds', + f'Rundeck Project {project_name} Execution Duration', + labels=['project_name', 'job_id', 'job_name'] + ) + + metrics = GaugeMetricFamily( + 'rundeck_project_execution_status', + f'Rundeck Project {project_name} Execution Status', + labels=['project_name', 'job_id', 'job_name', 'status'] + ) + # Job start/end times job_start_time = project_execution.get('date-started', {}).get('unixtime', 0) job_end_time = project_execution.get('date-ended', {}).get('unixtime', 0) @@ -215,7 +215,7 @@ def get_project_executions(self, project: dict): value ) - project_executions_status.append(metrics) + project_executions_status.append(metrics) except Exception: # nosec pass @@ -348,7 +348,7 @@ def collect(self): for executions in project_executions: for execution in executions: if execution is not None: - yield(execution) + yield execution @staticmethod def exit_with_msg(msg: str, level: str):