Skip to content

Commit

Permalink
Fix project executions query recentFilter (#69)
Browse files Browse the repository at this point in the history
* feat: update version

* feat(#68): add --rundeck.projects.executions.filter param

* fix: change rundeck.projects.executions.filter default value

* fix(#68): change rundeck.projects.executions.filter default value

* fix: rollback rundeck.projects.filter arg

* docs: update CHANGELOG.md
  • Loading branch information
phsmith authored May 30, 2023
1 parent 82b203a commit a28043e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
50 changes: 28 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.6.0] - 2023-05-30

### Added
- Issue [#68](https://github.com/phsmith/rundeck_exporter/issues/68), added new argument `rundeck.projects.executions.filter`

## [2.5.2] - 2023-05-02

### Changed
- Update Dockerfile and Makefile to support the new VERSION file

### Fixed
- Fixed rundeck_project_execution_duration_seconds metric return values from milliseconds to seconds.
- Fixed rundeck_project_execution_duration_seconds metric return values from milliseconds to seconds

## [2.5.1] - 2023-05-02

### Added
- Added VERSION file

### Fixed
- Fixed issue #65, rundeck_project_execution_duration_seconds metric reporting wrong values. Instead of using the job `averageDuration` attribute, now the value is calculated based on the `start time` and `end time`.
- Fixed issue [#65](https://github.com/phsmith/rundeck_exporter/issues/65), rundeck_project_execution_duration_seconds metric reporting wrong values. Instead of using the job `averageDuration` attribute, now the value is calculated based on the `start time` and `end time`

## [2.5.0] - 2022-09-29

### Added
- Added new metric rundeck_project_executions_total
- Added new metric `rundeck_project_executions_total`

### Fixed
- Fixed issue #59, unable to pass the RUNDECK_PROJECTS_FILTER environment variables
- Fixed issue [#59](https://github.com/phsmith/rundeck_exporter/issues/59), unable to pass the RUNDECK_PROJECTS_FILTER environment variables

## [2.4.14] - 2022-07-21

Expand All @@ -42,12 +47,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.4.13] - 2022-07-19

### Added
- Increased project executions max limit results to 250. Details on issue #56
- Increased project executions max limit results to 250. Details on issue [#56](https://github.com/phsmith/rundeck_exporter/issues/56)

## [2.4.12] - 2022-07-04

### Fixed
- Fixed issue #55, support for Python 3.6
- Fixed issue [#55](https://github.com/phsmith/rundeck_exporter/issues/55), support for Python 3.6

## [2.4.11] - 2022-06-11

Expand All @@ -65,18 +70,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.4.9] - 2022-05-09
### Fixed
- Fixed version
- Fixed issue #42, avoid duplicating metric definitions by @WilsonSunBritten in https://github.com/phsmith/rundeck_exporter/pull/46
- Fixed issue [#42](https://github.com/phsmith/rundeck_exporter/issues/42), avoid duplicating metric definitions by @WilsonSunBritten in https://github.com/phsmith/rundeck_exporter/pull/46

## [2.4.8] - 2022-05-09
### Fixed
- Fixed issue #42, avoid duplicating metric definitions by @WilsonSunBritten in https://github.com/phsmith/rundeck_exporter/pull/43
- Fixed issue [#42](https://github.com/phsmith/rundeck_exporter/issues/42), avoid duplicating metric definitions by @WilsonSunBritten in https://github.com/phsmith/rundeck_exporter/pull/43

## [2.4.7] - 2022-04-20
### Changed
- Changed the job_execution_duration calc to get info from job attribute `averageDuration`

### Fixed
- Fixed issue #40, negative job_execution_duration value
- Fixed issue [#40](https://github.com/phsmith/rundeck_exporter/issues/40), negative job_execution_duration value

## [2.4.6] - 2022-03-05
### Added
Expand All @@ -86,14 +91,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `node` label from metrics

### Fixed
- Fixed issue #34 Put RUNDECK_URL into the label instance
- Fixed issue [#34](https://github.com/phsmith/rundeck_exporter/issues/34) Put RUNDECK_URL into the label instance

## [2.4.5] - 2022-03-03
### Added
- Added `node` label in metrics

### Fixed
- Fixed issue #34 Put RUNDECK_URL into the label instance
- Fixed issue [#34](https://github.com/phsmith/rundeck_exporter/issues/34) Put RUNDECK_URL into the label instance

## [2.4.4] - 2022-02-25
### Removed
Expand All @@ -104,7 +109,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added rundeck.username and RUNDECK_PASSWORD env support for Rundeck API versions older than 24

### Fixed
- Fixed issue #27 rundeck_scheduler_quartz_scheduledJobs not showing up
- Fixed issue [#27](https://github.com/phsmith/rundeck_exporter/issues/27) rundeck_scheduler_quartz_scheduledJobs not showing up

## [2.4.2] - 2022-02-22
### Added
Expand Down Expand Up @@ -141,23 +146,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.3.0] - 2021-04-15
### Fixed
- Fixed issue #16 - Added options --rundeck.cpu.stats, --rundeck.memory.stats and --version
- Fixed issue [#16](https://github.com/phsmith/rundeck_exporter/issues/16) - Added options --rundeck.cpu.stats, --rundeck.memory.stats and --version

## [2.2.6] - 2021-03-31
### Fixed
- Fixed issue #14 - Fixed the info about running status
- Fixed issue [#14](https://github.com/phsmith/rundeck_exporter/issues/14) - Fixed the info about running status

## [2.2.5] - 2021-03-22
### Fixed
- Fixed issue #13 - Added new label execution_id to rundeck_project_execution_status metrics
- Fixed issue [#13](https://github.com/phsmith/rundeck_exporter/issues/13) - Added new label execution_id to rundeck_project_execution_status metrics

## [2.2.4] - 2021-03-02
### Fixed
- Fixed issue Regarding execution status #11 - Modified GaugeMetricFamily location in the function get_project_executions
- Fixed issue Regarding execution status [#11](https://github.com/phsmith/rundeck_exporter/issues/11) - Modified GaugeMetricFamily location in the function get_project_executions

## [2.2.3] - 2021-02-26
### Fixed
- Fixed issue invalid API request #10 - Added warning message for API version < 25
- Fixed issue invalid API request [#10](https://github.com/phsmith/rundeck_exporter/issues/10) - Added warning message for API version < 25

## [2.2.2] - 2021-01-05
### Fixed
Expand All @@ -169,15 +174,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.2.0] - 2020-11-28
### Fixed
- Fixed issue Last Run #5 - Merged @h4wkmoon patch that adds rundeck_project_start_timestamp metric
- Fixed issue Last Run [#5](https://github.com/phsmith/rundeck_exporter/issues/5) - Merged @h4wkmoon patch that adds rundeck_project_start_timestamp metric

## [2.1.0] - 2020-11-04
### Added
- Added pull request Fixed order labels and values the same way in execution metrics #3
- Added pull request Fixed order labels and values the same way in execution metrics [#3](https://github.com/phsmith/rundeck_exporter/issues/3)

### Fixed
- Fixed issue Long Running Jobs #2 - Added metric rundeck_project_execution_duration_seconds
- Fixed issue Project executions metrics not show all jobs info #4
- Fixed issue [#2](https://github.com/phsmith/rundeck_exporter/issues/2), Long Running Jobs. Added metric rundeck_project_execution_duration_seconds
- Fixed issue [#4](https://github.com/phsmith/rundeck_exporter/issues/4), Project executions metrics not show all jobs info

## [2.0.0] - 2020-08-12
### Added
Expand Down Expand Up @@ -228,7 +233,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.5.2...HEAD
[unreleased]: https://github.com/phsmith/rundeck_exporter/compare/v2.6.0...HEAD
[2.6.0]: https://github.com/phsmith/rundeck_exporter/compare/v2.5.2...v2.6.0
[2.5.2]: https://github.com/phsmith/rundeck_exporter/compare/v2.5.1...v2.5.2
[2.5.1]: https://github.com/phsmith/rundeck_exporter/compare/v2.5.0...v2.5.1
[2.5.0]: https://github.com/phsmith/rundeck_exporter/compare/v2.4.14...v2.5.0
Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ The rundeck_exporter supports the following paramenters:
```
$ ./rundeck_exporter.py --help

usage: rundeck_exporter.py [-h] [--debug] [-v] [--host RUNDECK_EXPORTER_HOST] [--port RUNDECK_EXPORTER_PORT] [--rundeck.url RUNDECK_URL] [--rundeck.skip_ssl]
[--rundeck.api.version RUNDECK_API_VERSION] [--rundeck.username RUNDECK_USERNAME] [--rundeck.projects.executions]
[--rundeck.projects.executions.limit RUNDECK_PROJECTS_EXECUTIONS_LIMIT] [--rundeck.projects.executions.cache]
[--rundeck.projects.filter RUNDECK_PROJECTS_FILTER [RUNDECK_PROJECTS_FILTER ...]] [--rundeck.cached.requests.ttl RUNDECK_CACHED_REQUESTS_TTL]
[--rundeck.cpu.stats] [--rundeck.memory.stats]
usage: rundeck_exporter.py [-h] [--debug] [-v] [--host RUNDECK_EXPORTER_HOST] [--port RUNDECK_EXPORTER_PORT] [--rundeck.url RUNDECK_URL] [--rundeck.skip_ssl] [--rundeck.api.version RUNDECK_API_VERSION] [--rundeck.username RUNDECK_USERNAME] [--rundeck.projects.executions]
[--rundeck.projects.executions.filter RUNDECK_PROJECT_EXECUTIONS_FILTER] [--rundeck.projects.executions.limit RUNDECK_PROJECTS_EXECUTIONS_LIMIT] [--rundeck.projects.executions.cache]
[--rundeck.projects.filter RUNDECK_PROJECTS_FILTER [RUNDECK_PROJECTS_FILTER ...]] [--rundeck.cached.requests.ttl RUNDECK_CACHED_REQUESTS_TTL] [--rundeck.cpu.stats] [--rundeck.memory.stats]

Rundeck Metrics Exporter

Expand All @@ -124,6 +122,8 @@ options:
Rundeck User with access to the system information.
--rundeck.projects.executions
Get projects executions metrics.
--rundeck.projects.executions.filter RUNDECK_PROJECT_EXECUTIONS_FILTER
Project executions filter by a period of time. Can be in: [s]: seconds, [n]: minutes, [h]: hour, [d]: day, [w]: week, [m]: month, [y]: year. Default: 5n.
--rundeck.projects.executions.limit RUNDECK_PROJECTS_EXECUTIONS_LIMIT
Project executions max results per query. Default: 20.
--rundeck.projects.executions.cache
Expand Down Expand Up @@ -152,12 +152,27 @@ Optionally, it's possible to pass the following environment variables to the run
| RUNDECK_SKIP_SSL | <ul><li>True</li><li>False (default)</li></ul> | Skip SSL certificate check. |
| RUNDECK_PROJECTS_EXECUTIONS | <ul><li>True</li><li>False (default)</li></ul> | Get projects executions metrics. |
| RUNDECK_PROJECTS_FILTER | | Get executions only from listed projects e.g. "project-1 project-2 ..." |
| RUNDECK_PROJECT_EXECUTIONS_FILTER | Default: 5n | Project executions filter by a period of time. Can be in: **[s]**: seconds, **[n]**: minutes, **[h]**: hour, **[d]**: day, **[w]**: week, **[m]**: month, **[y]**: year. |
| RUNDECK_PROJECTS_EXECUTIONS_LIMIT | Default: 20 | Projects executions max results per query |
| RUNDECK_PROJECTS_EXECUTIONS_CACHE | <ul><li>True</li><li>False (default)</li></ul> | Cache requests for project executions metrics query. |
| RUNDECK_CACHED_REQUESTS_TTL | Default: 120 | Rundeck cached requests expiration time. |
| RUNDECK_CPU_STATS | <ul><li>True</li><li>False (default)</li></ul> | Show Rundeck CPU usage stats |
| RUNDECK_MEMORY_STATS | <ul><li>True</li><li>False (default)</li></ul> | Show Rundeck memory usage stats |

### Example

```sh
$ RUNDECK_TOKEN=xxxxxxxx ./rundeck_exporter.py \
--host=0.0.0.0 \
--rundeck.url=http://localhost:4440 \
--rundeck.skip_ssl \
--rundeck.cpu.stats \
--rundeck.memory.stats \
--rundeck.projects.filter="project-1 project-2 project-n" \
--rundeck.projects.executions \
--rundeck.projects.executions.filter=5n
```

<details>
<summary>
Output example:
Expand Down Expand Up @@ -446,6 +461,7 @@ Optionally, it's possible to pass the following environment variables to the run
```
</details>
<br/>

#### Running with Docker

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.6.0
19 changes: 14 additions & 5 deletions rundeck_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
__app__ = 'rundeck_exporter'
__version__ = open('VERSION').read()

print(__version__)

# Disable InsecureRequestWarning
requests.urllib3.disable_warnings()

Expand Down Expand Up @@ -118,6 +116,15 @@ class RundeckMetricsCollector(object):
default=literal_eval(getenv('RUNDECK_PROJECTS_EXECUTIONS', 'False').capitalize()),
action='store_true'
)
args_parser.add_argument('--rundeck.projects.executions.filter',
dest='rundeck_project_executions_filter',
help='''
Get the latest project executions filtered by time period.
Can be in: [s]: seconds, [n]: minutes, [h]: hour, [d]: day, [w]: week, [m]: month, [y]: year.
Default: 5n.
''',
default=getenv('RUNDECK_PROJECTS_EXECUTIONS_FILTER', '5n')
)
args_parser.add_argument('--rundeck.projects.executions.limit',
dest='rundeck_projects_executions_limit',
help='Project executions max results per query. Default: 20.',
Expand All @@ -134,7 +141,8 @@ class RundeckMetricsCollector(object):
dest='rundeck_projects_filter',
help='Get executions only from listed projects (delimiter = space).',
default=getenv('RUNDECK_PROJECTS_FILTER', []),
nargs='+'
nargs='+',
required=False
)
args_parser.add_argument('--rundeck.cached.requests.ttl',
dest='rundeck_cached_requests_ttl',
Expand Down Expand Up @@ -167,7 +175,7 @@ class RundeckMetricsCollector(object):

def __init__(self):
if self.args.version:
print(f'{__app__} {__version__}')
print(f'{__app__} v{__version__}', end='')
exit(0)

if not self.args.rundeck_url \
Expand Down Expand Up @@ -229,7 +237,8 @@ def get_project_executions(self, project: dict):
project_name = project['name']
project_execution_records = list()
project_executions_limit = self.args.rundeck_projects_executions_limit
endpoint = f'/project/{project_name}/executions?recentFilter=1d&max={project_executions_limit}'
project_executions_filter = self.args.rundeck_project_executions_filter
endpoint = f'/project/{project_name}/executions?recentFilter={project_executions_filter}&max={project_executions_limit}'
endpoint_running_executions = f'/project/{project_name}/executions/running?recentFilter=1d&max={project_executions_limit}'

try:
Expand Down

0 comments on commit a28043e

Please sign in to comment.