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

Cronjob Monitoring Script #215

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cronjob_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Expose cronjob exit status
#
# Usage: <command> ; cronjob_status "<description>" $?
#
# Example crontab entry:
# * * * * * echo "Hello world!"; cronjob_status "greeting" $? | sponge /var/lib/prometheus/node-exporter/cronjob_greeting.prom
#
# Inspired by: https://janikvonrotz.ch/2020/09/07/monitor-cron-jobs-with-prometheus-grafana-and-node-exporter/
#
# Author: Alex Kraker (github.com/kraker)

# Unofficial strict mode
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

readonly DESCRIPTION="$1"
readonly STATUS="$2"

echo "# HELP node_cronjob_status Last exit code of cronjob."
echo "# TYPE node_cronjob_status gauge"
echo "node_cronjob_status{user=\"${USER}\", description=\"${DESCRIPTION}\"} ${STATUS}"
Loading