Skip to content

Commit

Permalink
Fix issues #2, #3 and #4
Browse files Browse the repository at this point in the history
  • Loading branch information
phsmith committed Nov 4, 2020
1 parent 490af45 commit a665add
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 10 deletions.
21 changes: 17 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
FROM python:alpine

LABEL version="1.2.0" \
description="Rundeck metrics exporter to Prometheus" \
maintainer="Phillipe Smith <[email protected]>"
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

RUN pip install prometheus-client requests cachetools
LABEL maintainer="Phillipe Smith <[email protected]>" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Rundeck Exporter" \
org.label-schema.description="Rundeck metrics exporter for Prometheus" \
org.label-schema.url="https://hub.docker.com/r/phsmith/rundeck-exporter" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/phsmith/rundeck_exporter" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"

RUN pip install --no-cache-dir \
cachetools==4.1.1 \
prometheus-client==0.8.0 \
requests==2.24.0

COPY rundeck_exporter.py /usr/bin

Expand Down
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PROJECT_NAME = $(notdir $(PWD))

.SILENT: push

default: build

build:
docker run --rm -i hadolint/hadolint:latest < Dockerfile

docker build \
--rm \
--network host \
--tag="$(PROJECT_NAME):$(VERSION)" \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg VERSION="$(VERSION)" .

clean:
docker rmi --force $(PROJECT_NAME):$(VERSION)

push:
[ -z "$(git status --short --untracked-files=no)" ] && (echo -e "\nNeed to commit changes before push.\n"; exit 1)
git tag -d latest
git tag latest
git push origin :latest
git tag "v$(VERSION)"
git push --all

debug:
docker run --rm -it $(PROJECT_NAME):$(VERSION) /bin/sh

run:
docker run --rm $(PROJECT_NAME):$(VERSION) \
--host 0.0.0.0 \
--rundeck.skip_ssl
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ rundeck_services_ExecutionService_executionSuccessMeter_total 268.0
# HELP rundeck_api_requests_requestTimer_total Rundeck timers metrics
# TYPE rundeck_api_requests_requestTimer_total counter
rundeck_api_requests_requestTimer_total 39419.0
# HELP rundeck_project_execution_status Rundeck Project servcom_install Execution Duration
# TYPE rundeck_project_execution_duration_seconds gauge
rundeck_project_execution_duration_seconds{job_id="servcom_install",job_name="Servcom Client",project_name="servcom_install"} 6000.0
# HELP rundeck_project_execution_status Rundeck Project servcom_install Execution Status
# TYPE rundeck_project_execution_status gauge
rundeck_project_execution_status{job_id="servcom_install",job_name="Servcom Client",project_name="servcom_install",status="succeeded"} 1.0
Expand All @@ -175,6 +178,9 @@ rundeck_project_execution_status{job_id="servcom_install",job_name="Servcom Clie
# HELP rundeck_project_execution_status Rundeck Project servcom_install Execution Status
# TYPE rundeck_project_execution_status gauge
rundeck_project_execution_status{job_id="servcom_install",job_name="Servcom Client",project_name="servcom_install",status="unknown"} 0.0
# HELP rundeck_project_execution_status Rundeck Project oracle_client_install Execution Druation
# TYPE rundeck_project_execution_duration_seconds gauge
rundeck_project_execution_duration_seconds{job_id="oracle_client_install",job_name="Oracle Client Install",project_name="oracle_client_install"} 20000.0
# HELP rundeck_project_execution_status Rundeck Project oracle_client_install Execution Status
# TYPE rundeck_project_execution_status gauge
rundeck_project_execution_status{job_id="oracle_client_install",job_name="Oracle Client Install",project_name="oracle_client_install",status="succeeded"} 1.0
Expand Down Expand Up @@ -239,3 +245,8 @@ docker run --rm -d -p 9620:9620 -e RUNDECK_TOKEN=$RUNDECK_TOKEN rundeck_exporter
* Remove param --rundeck.projects.executions.limit
* Remove rundeck_node label from all metrics
* Change rundeck_project_executions_info metrics to rundeck_project_status{job_id=...,job_name=...,project_name=...,status=....}

`v2.1.0`:
* Fix issue Long Running Jobs #2 - Add metric rundeck_project_execution_duration_seconds
* Fix issue Project executions metrics not show all jobs info #4
* Add pull request fix order labels and values the same way in execution metrics #3
40 changes: 34 additions & 6 deletions rundeck_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ def cached_request_data_from(self, endpoint: str) -> dict:
Method to get Rundeck projects executions info
"""
def get_project_executions(self, project: dict):
counter_name = 'rundeck_project_execution_status'
project_name = project['name']
project_executions = None
project_executions_status = list()
jobs_list = list()
metrics = None
endpoint = f'/project/{project_name}/executions?max=1'
endpoint = f'/project/{project_name}/executions?recentFilter=1d'

try:
if self.args.rundeck_projects_executions_cache:
Expand All @@ -146,26 +146,54 @@ def get_project_executions(self, project: dict):
project_executions = self.request_data_from(endpoint)

for project_execution in project_executions['executions']:
if not project_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:
continue

jobs_list.append(job_id)

# 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)
job_execution_duration = (job_end_time - job_start_time)

duration_metrics = GaugeMetricFamily(
'rundeck_project_execution_duration_seconds',
f'Rundeck Project {project_name} Execution Duration',
labels=['project_name', 'job_id', 'job_name']
)

duration_metrics.add_metric(
[
project_name,
job_id,
job_name
],
job_execution_duration
)

project_executions_status.append(duration_metrics)

for status in ['succeeded', 'running', 'failed', 'aborted', 'unknown']:
value = 0

if project_execution.get('status', 'unknown') == status:
value = 1

metrics = GaugeMetricFamily(
counter_name,
'rundeck_project_execution_status',
f'Rundeck Project {project_name} Execution Status',
labels=['project_name', 'job_id', 'job_name', 'status']
)

metrics.add_metric(
[
project_name,
project_execution.get('job', {}).get('id', 'None'),
project_execution.get('job', {}).get('name', 'None'),
job_id,
job_name,
status
],
value
Expand Down

0 comments on commit a665add

Please sign in to comment.