prometheus-community / node-exporter-textfile-collector-scripts

Scripts for node-exporter's textfile collector
Apache License 2.0
512 stars 191 forks source link

Create script to expose cronjob status #214

Closed kraker closed 6 months ago

kraker commented 6 months ago

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
kraker commented 6 months ago

Fixing DCO signoff commit rewrite history...