Skip to content

Commit

Permalink
Fix issue #16 - Added options --rundeck.[cpu,memory].stats and --version
Browse files Browse the repository at this point in the history
  • Loading branch information
phsmith committed Apr 15, 2021
1 parent f77253b commit eb25beb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ docker run --rm -d -p 9620:9620 -e RUNDECK_TOKEN=$RUNDECK_TOKEN rundeck_exporter
```

## Changelog
`2.3.0`:
* Fix issue #16 - Added options --rundeck.cpu.stats, --rundeck.memory.stats and --version

`2.2.6`:
* Fix issue #14 - Fixed the info about running status

Expand Down
44 changes: 38 additions & 6 deletions rundeck_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
REGISTRY
)

__author__ = 'Phillipe Smith'
__author_email__ = '[email protected]'
__app__ = 'rundeck_exporter'
__version__ = '2.3.0'

# Disable InsecureRequestWarning
requests.urllib3.disable_warnings()

Expand All @@ -33,6 +38,10 @@ class RundeckMetricsCollector(object):
default=getenv('RUNDECK_EXPORTER_DEBUG', False),
action='store_true'
)
args_parser.add_argument('-v', '--version',
help='Shows rundeck_exporter current release version.',
action='store_true'
)
args_parser.add_argument('--host',
help=f'Host binding address. Default: {default_host}.',
metavar="RUNDECK_EXPORTER_HOST",
Expand Down Expand Up @@ -85,6 +94,18 @@ class RundeckMetricsCollector(object):
type=int,
default=getenv('RUNDECK_CACHED_REQUESTS_TTL', 120)
)
args_parser.add_argument('--rundeck.cpu.stats',
dest='rundeck_cpu_stats',
help='Show Rundeck CPU usage stats',
action='store_true',
default=getenv('RUNDECK_CPU_STATS', False)
)
args_parser.add_argument('--rundeck.memory.stats',
dest='rundeck_memory_stats',
help='Show Rundeck memory usage stats',
action='store_true',
default=getenv('RUNDECK_MEMORY_STATS', False)
)

args = args_parser.parse_args()

Expand All @@ -97,6 +118,10 @@ class RundeckMetricsCollector(object):
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=loglevel)

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

if not self.args.rundeck_url or not self.rundeck_token:
self.exit_with_msg(msg='Rundeck URL and Token are required.', level='critical')

Expand Down Expand Up @@ -140,7 +165,6 @@ def get_project_executions(self, project: dict):
endpoint = f'/project/{project_name}/executions?recentFilter=1d'
endpoint_running_executions = f'/project/{project_name}/executions/running?recentFilter=1d'


try:
if self.args.rundeck_projects_executions_cache:
project_executions_running_info = self.cached_request_data_from(endpoint_running_executions)
Expand Down Expand Up @@ -237,14 +261,22 @@ def get_project_executions(self, project: dict):
"""
def get_system_stats(self, system_info: dict):
for stat, stat_values in system_info['system']['stats'].items():
if stat in ['cpu', 'memory']:
continue

for counter, value in stat_values.items():
if counter in ['unit', 'duration']:
continue
elif stat == 'uptime' and counter == 'since':
value = value['epoch']
elif stat == 'cpu':
if self.args.rundeck_cpu_stats and isinstance(value, dict):
counter = f'{counter}_ratio'
value = value['average']
else:
continue
elif stat == 'memory':
if self.args.rundeck_memory_stats:
counter = f'{counter}_bytes'
else:
continue

rundeck_system_stats = GaugeMetricFamily(
f'rundeck_system_stats_{stat}_{counter}',
Expand Down Expand Up @@ -331,8 +363,8 @@ def collect(self):
"""
if api_version >= self.args.rundeck_api_version < 25:
logging.warning(f'Unsupported API version "{self.args.rundeck_api_version}" '
+ f'for API request: /api/{self.args.rundeck_api_version}/metrics/metrics. '
+ 'Minimum supported version is 25')
+ f'for API request: /api/{self.args.rundeck_api_version}/metrics/metrics. '
+ 'Minimum supported version is 25')
else:
metrics = self.request_data_from('/metrics/metrics')

Expand Down

0 comments on commit eb25beb

Please sign in to comment.