From a3bffa8995600b8ce922b8ebb682963dadced769 Mon Sep 17 00:00:00 2001 From: Phillipe Smith Date: Mon, 11 Mar 2024 16:28:47 -0300 Subject: [PATCH] feat: add new metric rundeck_project_nodes_total (#86) --- CHANGELOG.md | 7 ++++++- README.md | 3 +++ rundeck_exporter.py | 31 ++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9209650..36bebdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.6.5] - 2024-03-011 +### Added +- Issue [#85](https://github.com/phsmith/rundeck_exporter/issues/85), added new metric `rundeck_project_nodes_total`. + ## [2.6.4] - 2024-03-05 ### Added - Issue [#83](https://github.com/phsmith/rundeck_exporter/issues/83), added new `--no_checks_in_passive_mode` argument and `RUNDECK_EXPORTER_NO_CHECKS_IN_PASSIVE_MODE=` env var introduced to keep the rundeck_exporter idle while the Rundeck host is in `passive` execution mode. @@ -258,7 +262,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release -[unreleased]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.4...HEAD +[unreleased]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.5...HEAD +[2.6.5]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.4...v2.6.5 [2.6.4]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.3...v2.6.4 [2.6.3]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.2...v2.6.3 [2.6.2]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.1...v2.6.2 diff --git a/README.md b/README.md index adfa86b..183c4f2 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,9 @@ $ RUNDECK_TOKEN=xxxxxxxx ./rundeck_exporter.py \ # 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 + # HELP rundeck_project_nodes_total Rundeck project nodes total + # TYPE rundeck_project_nodes_total gauge + rundeck_project_nodes_total{instance_address="localhost:4440",project_name="Test"} 1.0 ``` diff --git a/rundeck_exporter.py b/rundeck_exporter.py index 6928e22..71f2ff7 100755 --- a/rundeck_exporter.py +++ b/rundeck_exporter.py @@ -27,7 +27,7 @@ __author__ = 'Phillipe Smith' __author_email__ = 'phsmithcc@gmail.com' __app__ = 'rundeck_exporter' -__version__ = '2.6.4' +__version__ = '2.6.5' # Disable InsecureRequestWarning requests.urllib3.disable_warnings() @@ -308,6 +308,17 @@ def get_project_executions(self, project: dict): return project_execution_records, project_executions_total + """ + Method to get Rundeck projects nodes info + """ + def get_project_nodes(self, project: dict): + project_name = project['name'] + endpoint = f'/project/{project_name}/resources' + project_nodes = self.request_data_from(endpoint) + project_nodes_info = {project['name']: list(project_nodes.values())} + + return project_nodes_info + """ Method to get Rundeck system stats @@ -468,8 +479,8 @@ def collect(self): else: projects = self.request_data_from(endpoint) - with ThreadPoolExecutor() as threadpool: - project_execution_records = threadpool.map(self.get_project_executions, projects) + with ThreadPoolExecutor(thread_name_prefix='project_executions') as project_executions_threadpool: + project_execution_records = project_executions_threadpool.map(self.get_project_executions, projects) default_labels = self.default_labels + [ 'project_name', @@ -523,6 +534,20 @@ def collect(self): yield project_metrics yield project_executions_total_metrics + with ThreadPoolExecutor(thread_name_prefix='project_nodes') as project_nodes_threadpool: + project_nodes_records = project_nodes_threadpool.map(self.get_project_nodes, projects) + project_nodes_total = GaugeMetricFamily( + name='rundeck_project_nodes_total', + documentation='Rundeck project nodes total', + labels=self.default_labels + ['project_name'] + ) + + for project_nodes in project_nodes_records: + for project, nodes in project_nodes.items(): + project_nodes_total.add_metric(self.default_labels_values + [project], len(nodes)) + + yield project_nodes_total + @staticmethod def exit_with_msg(msg: str, level: str): getattr(logging, level)(msg)