- Components
- Blog
How to monitor cron jobs with heartbeat checks
Most cron jobs fail quietly. The server is up, your uptime checks are green, and the nightly backup hasn’t run in a week. Nothing errors loudly, because a job that never starts can’t report that it failed.
Heartbeat monitoring flips the model. Instead of asking a job whether it’s healthy, you wait for the job to tell you it finished. If that signal doesn’t arrive on time, you get an alert.
Why cron jobs fail silently
Cron runs whatever is scheduled and moves on. It doesn’t know what success looks like for your job, and it won’t tell you when a job stops running. Common ways that happens:
- A deploy overwrote the crontab and the schedule never came back.
- The host was replaced, and the job only lived on the old one.
- The job hangs on a lock or a slow network call and never exits.
- The script errors out, but its output goes to a mailbox nobody reads.
How heartbeat checks work
Each check has an expected schedule and a grace period. When the job finishes, it sends an HTTP request to the check’s unique ping URL. If the ping doesn’t arrive within the schedule plus the grace period, Ionhour opens an incident and alerts your team wherever you’ve routed it.
Ping on success, not on start
A ping at the start of the job only proves the job began. Send it after the work is done, so a crash halfway through still counts as a miss.
Add a ping to your crontab
Chain the ping after your command with &&, so it only fires when the job exits successfully:
1# Run the backup at 03:00 every day, then report success20 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 \3 https://signal.ionhour.com/api/signals/ping/YOUR_TOKEN > /dev/null
The flags keep the ping itself from causing trouble: -f fails on HTTP errors, -m 10 caps the request at ten seconds, and --retry 3 rides out a brief network blip.
Pick a sensible grace period
Too short and you’ll get paged every time a job runs a little long. Too long and you’ll find out about a failure hours after it happened. Start from the job’s longest normal runtime and add a buffer.
A grace period is the gap between “late” and “broken.” Set it from how long the job really takes, not how long you hope it takes.
What to do when an alert fires
Check whether the job ran at all, then whether it finished. Your scheduler’s logs answer the first question; the job’s own logs answer the second. Once it’s fixed, the next successful ping resolves the incident automatically. The cron monitoring docs cover schedules, grace periods, and alert routing in more detail.