Skip to content

Commit

Permalink
feat: add new metric rundeck_project_executions_total
Browse files Browse the repository at this point in the history
  • Loading branch information
phsmith committed Sep 29, 2022
1 parent b7884d3 commit 4d10c54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.5.0] - 2022-09-29

### Added
- Added new metric rundeck_project_executions_total

### Fixed
- Fixed issue #59, unable to pass the RUNDECK_PROJECTS_FILTER environment variables

## [2.4.14] - 2022-07-21

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ Optionally, it's possible to pass the following environment variables to the run
rundeck_project_execution_status{execution_id="7375",execution_type="scheduled",instance_address="localhost:4440",job_group="",job_id="3fcc1617-74d4-422b-b7cf-bd3123b3f97c",job_name="Fail after 60s",project_name="Test",status="failed",user="admin"} 1.0
rundeck_project_execution_status{execution_id="7375",execution_type="scheduled",instance_address="localhost:4440",job_group="",job_id="3fcc1617-74d4-422b-b7cf-bd3123b3f97c",job_name="Fail after 60s",project_name="Test",status="aborted",user="admin"} 0.0
rundeck_project_execution_status{execution_id="7375",execution_type="scheduled",instance_address="localhost:4440",job_group="",job_id="3fcc1617-74d4-422b-b7cf-bd3123b3f97c",job_name="Fail after 60s",project_name="Test",status="unknown",user="admin"} 0.0
# HELP rundeck_project_executions_total Rundeck Project ProjectName Total Executions
# TYPE rundeck_project_executions_total counter
rundeck_project_executions_total{instance_address="localhost:4440",project_name="Test"} 300.0
```
</details>

Expand Down
25 changes: 20 additions & 5 deletions rundeck_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__author__ = 'Phillipe Smith'
__author_email__ = '[email protected]'
__app__ = 'rundeck_exporter'
__version__ = '2.4.13'
__version__ = '2.5.0'

# Disable InsecureRequestWarning
requests.urllib3.disable_warnings()
Expand Down Expand Up @@ -237,6 +237,10 @@ def get_project_executions(self, project: dict):
project_executions_running_info = self.request_data_from(endpoint_running_executions)
project_executions_info = self.request_data_from(endpoint)

project_executions_total = {
'project': project_name,
'total_executions': project_executions_info['paging']['total']
}
project_executions = (project_executions_running_info.get('executions', [])
+ project_executions_info.get('executions', []))

Expand Down Expand Up @@ -279,10 +283,10 @@ def get_project_executions(self, project: dict):
RundeckProjectExecutionRecord(default_metrics + [status], value, RundeckProjectExecution.STATUS)
)

except Exception: # nosec
pass
except Exception as error: # nosec
logging.error(error)

return project_execution_records
return project_execution_records, project_executions_total


"""
Expand Down Expand Up @@ -468,7 +472,17 @@ def collect(self):
labels=default_labels + ['status']
)

for project_execution_record_group in project_execution_records:
project_executions_total_metrics = CounterMetricFamily(
'rundeck_project_executions_total',
f'Rundeck Project ProjectName Total Executions',
labels=self.default_labels + ['project_name']
)

for project_execution_record_group, project_executions_total in project_execution_records:
project_executions_total_metrics.add_metric(
self.default_labels_values + [project_executions_total['project']],
project_executions_total['total_executions']
)
for project_execution_record in project_execution_record_group:
if project_execution_record.execution_type == RundeckProjectExecution.START:
project_start_metrics.add_metric(project_execution_record.tags, project_execution_record.value)
Expand All @@ -480,6 +494,7 @@ def collect(self):
yield project_start_metrics
yield project_duration_metrics
yield project_metrics
yield project_executions_total_metrics

@staticmethod
def exit_with_msg(msg: str, level: str):
Expand Down

0 comments on commit 4d10c54

Please sign in to comment.