Monitoring a scheduled task with a heartbeat
Yann1 min readLire en français
A backup that stopped running warns no one. How to get an alert when a scheduled task goes quiet.
Some outages are silent: a nightly backup that stopped running, a stuck invoicing script, a cron job deleted by mistake. Nothing crashes, nothing shows, and you find out the day you need it.
Turning the check around
With the Heartbeat (Push) type, NorminUp does not contact your service: your task calls a unique address on each run. Nothing to open on your server, and it works even behind a firewall.
Setting it up
- Create a Heartbeat (Push) service and enter your task’s interval.
- Copy its ping address.
- Call it at the end of your task, with GET or POST.
0 3 * * * /usr/local/bin/backup.sh && curl -fsS https://api.norminup.fr/api/heartbeat/t/YOUR_TOKEN
With &&, the call only goes out if the backup succeeded: a failed backup also turns into silence.
When the alert goes out
If no call arrives for two and a half times the expected interval, the service goes down and you are warned. For an hourly task, the alert goes out after 2 h 30 without news.
More details in the documentation.