Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create script to expose cronjob status #214

Closed
wants to merge 4 commits into from

Conversation

kraker
Copy link

@kraker kraker commented May 11, 2024

This script exposes the exit status of cronjobs. This script was born out of a desire to monitor and alert on cronjobs using Prometheus and Alertmanager.

This script was inspired by https://janikvonrotz.ch/2020/09/07/monitor-cron-jobs-with-prometheus-grafana-and-node-exporter/

As far as I'm aware there isn't another facility for exposing metrics related to this in Node Exporter.

This script receives two arguments, the description of the cronjob as a string and the exit status of the previous command. It prints the metric to stdout.

Usage:

<command> ; cronjob "<description>" $?

Example crontab entry:

* * * * * echo "Hello world!"; cronjob "greeting" $? | sponge /var/lib/prometheus/node-exporter/cronjob_greeting.prom

Example textfile:

[vagrant@rocky8 ~]$ cat /var/lib/prometheus/node-exporter/cronjob_greeting.prom 
# HELP node_cronjob_status Last exit code of cronjob.
# TYPE node_cronjob_status gauge
node_cronjob_status{user="vagrant", description="greeting"} 0

funkyfuture and others added 4 commits May 11, 2024 10:44
…nity#211)

Signed-off-by: Frank Sachsenheim <funkyfuture@users.noreply.github.com>
…ity#208)

As suggested by prometheus-community#194 and this fixes it

Signed-off-by: kennethso168 <kennethso168@gmail.com>
This feel a little less "magic", is better readable and maintainable. Might have a slight impact on performance, too.
Signed-off-by: wangqing <wangqing@uniontech.com>
@kraker
Copy link
Author

kraker commented May 11, 2024

Fixing DCO signoff commit rewrite history...

@kraker kraker deleted the cronjob branch May 11, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants