Guides
Monitoring cron jobs with heartbeats
Scheduled jobs fail silently: no errors, nothing happens at all. Heartbeats flip the perspective and alert you when a job stops showing signs of life.
UptimeAnchor team · · 8 min read
Nightly backups, invoice runs, syncing with your ERP, cleaning up temporary files: every infrastructure has dozens of scheduled jobs. They all have one thing in common: when they stop working, nobody notices until the result is needed. And by then it's often too late.
Why classic monitoring isn't enough
An HTTP monitor checks something that responds. A cron job, on the other hand, doesn't respond to anyone: it runs, does its work and exits. If the server reboots and the cron daemon doesn't come back, if the script fails because of a missing permission or someone accidentally comments out the line in the crontab, there's no error to catch. There's just silence.
How a heartbeat works
A heartbeat monitor flips the logic: the job contacts UptimeAnchor by calling a unique URL every time it finishes successfully. You set how often the signal should arrive and a grace period; if the signal doesn't arrive in time, the monitor goes DOWN and you get an alert.
# Backup every night at 3:00, ping only if the backup succeeds 0 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://uptimeanchor.com/api/heartbeat/YOUR_TOKEN > /dev/null
The && operator is essential: the ping is only sent if the script exits with code 0. If the backup fails, the signal doesn't arrive and you get alerted.
Choosing interval and grace period
- The interval should match the job schedule: 24 hours for a daily job, 1 hour for an hourly one.
- The grace period covers variable run times: if the backup takes 10 to 40 minutes, a one-hour grace period avoids false alarms.
- For very long jobs, consider sending a ping at the start and using a second monitor for the end.
Examples in other languages
# Python
import urllib.request
urllib.request.urlopen("https://uptimeanchor.com/api/heartbeat/YOUR_TOKEN", timeout=10)
# PowerShell (Windows Task Scheduler)
Invoke-WebRequest -Uri "https://uptimeanchor.com/api/heartbeat/YOUR_TOKEN" -Method POST -TimeoutSec 10
// Node.js
await fetch("https://uptimeanchor.com/api/heartbeat/YOUR_TOKEN", { method: "POST" });What to monitor with heartbeats
- Database and file backups.
- Invoicing jobs and scheduled emails.
- Syncs with external systems (ERP, CRM, marketplaces).
- Queue workers: they send a ping on every cycle.
- Devices behind NAT or firewalls that can't be reached from outside.
Setting up a heartbeat takes two minutes. Discovering that the backup hasn't worked for three weeks on the very day you need it takes a lot longer.