Most monitoring watches things that are supposed to answer. A cron job is the opposite: it does its work and stays quiet. So when it stops running there's nothing to see. No error in the log, because the job never started; no failed request, because nothing made one. The nightly backup just doesn't happen, and you find out three weeks later, the night you need to restore from it.
Every scheduled task fails this way: backups, billing reconciliation, the export your warehouse depends on, the 6 a.m. digest email. A job that throws an exception at least leaves a stack trace. A job that silently stops being scheduled, because a server was rebuilt without its crontab or a container lost its cron daemon, leaves nothing, and a monitor pointed at your website has no way to notice it.
How heartbeat monitoring works
Turn the check around. Instead of a monitor reaching out to your service, the job reaches in to say it ran. It calls a unique URL at the end of every successful run, and the monitor's whole job is to notice when that call doesn't come. The pattern has an old name, a dead man's switch: silence is the alarm.
You tell the monitor how often the job runs. A ping inside that window means all is well. A window that passes without one means the monitor goes down and starts alerting, because the only reason a healthy job goes quiet is that it stopped.
Set up cron job monitoring in 3 minutes
- Create a free account and add a monitor of type Heartbeat.
- Set the expected interval to match the schedule, for example 1 day for a nightly job, and a grace period for normal lateness.
- Copy the heartbeat URL from the monitor page and add it to the end of the cron line.
# runs at 02:00; pings only if backup.sh exits 0
0 2 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 -X POST https://api.failover.io/heartbeat/<your-monitor-id>
The ping must be a POST. -fsS keeps curl quiet unless something goes wrong, and -m 10 stops a slow network from holding the job open.
Ping only when the job succeeds
Placement is the whole trick. Put the curl after your real command with &&, so it runs only if the command exits with 0. One monitor then catches both failures:
- The job doesn't run at all: no ping arrives and the window expires.
- The job runs and fails: the command errors,
&&skips the curl, and again no ping arrives.
Ping unconditionally (with ; instead of &&) and you only catch the first. For a script with several steps, put the ping on the last line and start the script with set -e so any failing step stops it before the ping.
#!/usr/bin/env bash
set -euo pipefail
pg_dump mydb | gzip > /backups/mydb-$(date +%F).sql.gz
aws s3 cp /backups/mydb-$(date +%F).sql.gz s3://my-backups/
curl -fsS -m 10 -X POST https://api.failover.io/heartbeat/<your-monitor-id>
Grace period and the first run
Two details separate a heartbeat that earns its keep from one that cries wolf.
The first is the grace period. A backup that usually finishes at 02:00 sometimes finishes at 02:09 because the disk was busy, and a page for nine minutes of ordinary variance teaches you to ignore the alerts. The grace period is slack on top of the interval: a daily job with 30 minutes of grace alerts only once it's a full half hour late. In numbers, the monitor goes down when no ping has arrived for interval + grace, so 24 h 30 min after the last good run.
The second is the moment you create the monitor. A fresh heartbeat hasn't been pinged yet, and a naive monitor would call that down and page you for a job whose first run hasn't come round. failover.io keeps a new heartbeat pending until its first ping and only then starts the clock, so you can set it up before you deploy the job.
What happens when a job misses its window
A missed heartbeat is an ordinary outage to the rest of the system. It opens an incident and walks the monitor's alert chain, for example Slack, then SMS, then a phone call, until someone acknowledges. When the job runs again and pings, the incident closes and the channels that got the alert receive a recovery message, so you know it's back without opening the dashboard. Plans and settings are on the cron job monitoring page.
Heartbeats beyond cron
Anything that runs on a rhythm and should report in works the same way:
- a Kubernetes CronJob: add the curl as the last command of the container, or as a final step after your main one (full YAML in Kubernetes CronJob);
- a queue worker that should finish a batch every few minutes: ping after each batch;
- a systemd timer: put the curl in the service's
ExecStartPost=, which only runs if the main command succeeded (full example in systemd timer vs cron); - a GitHub Actions schedule: add a last step that runs curl, so a failed workflow sends nothing.
You can attach up to 4 KB of JSON to a ping, for example how many rows were exported, by sending {"metadata": {...}} as the request body.
If the heartbeat alerts but the job ran
Check, in this order: that the curl is a POST to the exact URL from the monitor page; that the server running the job can reach api.failover.io over HTTPS (corporate proxies and egress firewalls are the usual cause); and that the expected interval matches the real schedule. A cron expression tester shows exactly when your expression fires, in your time zone, which catches the classic 0 2 * * 1-5 that never runs at weekends while the heartbeat expects a ping every day.
Ready-made expressions for common intervals, like every 5 minutes or every hour, are on the cron schedule examples page. For PHP scripts, see running a PHP script with cron.
Frequently asked questions
What is heartbeat monitoring?
Your job calls a unique URL each time it finishes. The monitor knows how often that should happen and alerts you when a call is late. It catches jobs that stopped running, which a normal uptime check cannot see.
How do I know if a cron job failed?
Ping a heartbeat URL only after the command succeeds, with &&. A failed run and a run that never started then look the same: no ping, and an alert once the expected interval plus grace period has passed.
Do I need to change my cron job?
Only the end of the line, where you add && curl -fsS -m 10 -X POST <heartbeat URL> after your command. The job itself stays the same.
What grace period should I use?
Long enough to cover the job running late on a busy day, short enough that you still hear about it the same night. For a nightly job, 30 to 60 minutes is common; for a job every 5 minutes, 2 or 3 minutes.
Does a new heartbeat alert before the first run?
No. A new heartbeat stays pending until its first ping arrives, so creating the monitor before the job first runs never pages anyone.