Heartbeat monitoring: catch cron jobs that silently stop
Short answer: A scheduled job that fails loudly is easy to fix; one that quietly stops running is the dangerous kind. Heartbeat monitoring flips the usual check around: each run of the job sends a small "I ran" ping to a monitoring service, and you get an alert when the ping does not arrive on time. Add a start ping and a failure ping as well, set a sensible grace period, and you will hear about missing backups, stalled imports and broken reports before a customer does.
Why cron failures go unnoticed
Most small businesses rely on more scheduled work than they realise: a nightly database backup, an hourly stock sync with a supplier, a morning sales summary, a job that renews certificates or clears out old uploads. These run on server cron, a hosting panel's scheduler or a cloud function timer.
The trouble is that the usual way of noticing problems, someone seeing an error page, does not apply. A backup script that crashes at 2am produces no visible symptom. Neither does a cron entry that was lost when the server was rebuilt, or a job that hangs forever waiting on a network call. The classic crontab mechanism is to email any output to the address in the MAILTO variable, as the crontab manual describes, but that only helps if the job runs, produces output and the mail is actually delivered and read. A job that never starts sends nothing at all.
That gap is the reason to watch for the absence of a signal rather than the presence of an error.
How heartbeat (dead man's switch) monitoring works
The idea is simple. You create a check in a monitoring tool and tell it how often the job is supposed to run. The tool gives you a unique URL. At the end of each successful run, your job makes an HTTP request to that URL. As long as pings keep arriving on schedule, the monitor stays quiet. When one is overdue, it alerts you.
Healthchecks.io, an open-source service that can also be self-hosted, documents exactly this model: it listens for pings from cron jobs and scheduled tasks, stays silent while they arrive on time and raises an alert when one does not. Its documentation lists typical uses such as file system and database backups, task queues, report generation and periodic data imports, and is clear that it is not meant for probing website uptime.
Grace periods: avoiding false alarms
Jobs do not finish at exactly the same second every day. A backup that usually takes four minutes may take twenty when the database has grown. Heartbeat tools handle this with a grace time. In the Healthchecks.io model, a check that is due but not yet late by more than its grace time shows as late; only when the grace time has passed does it go down and send alerts.
Set the grace period from real run times over the last few weeks, plus a margin for busy days. Too short and people learn to ignore the alerts; too long and a failure sits unnoticed for half a day.
Start, success and failure signals
A single ping at the end tells you the job finished. You can get more out of the same approach with three signals:
- Start: sent when the job begins. If a start arrives but no success follows, the job is hanging or crashed midway.
- Success: sent when the job completes properly.
- Failure: sent when the job knows it has failed, so you are alerted immediately instead of waiting for the grace period to expire.
Healthchecks.io's pinging API exposes separate endpoints for start, failure and log pings, and one that accepts a script's exit status directly, so a non-zero exit code counts as a failure. It also accepts an optional run ID so that overlapping runs can be matched to the right start ping.
Wiring it into a job
For a shell script on a Linux server, the pattern is to ping once the real work has succeeded. If you chain the ping after the main command with a logical AND, the ping only fires when the command exits successfully. Two practical details matter:
- Give the ping request a short timeout and a couple of retries, so a slow network call to the monitor never holds up or breaks the job itself.
- Make sure the ping cannot succeed when the job did not. A ping placed at the top of a script, or after a command whose failure is ignored, defeats the purpose.
In application code, call the success URL as the last step of the job and the failure URL from the error handler.
What to monitor first
You do not need to wire up every job on day one. Start with the ones where silent failure is expensive:
- Backups and database dumps, ideally with the ping placed after the file has been verified or copied off the server.
- Imports and syncs that feed prices, stock levels or orders into your site or app.
- Billing and invoicing runs, renewal reminders and anything a customer would notice missing.
- Certificate renewals and cleanup jobs that keep disks from filling up.
For each one, write down the expected schedule, the grace period and who gets the alert. A check that alerts a shared inbox nobody watches is not much better than no check.
A worked example
Picture a hypothetical Leeds furniture retailer whose online shop pulls stock levels from a supplier feed every hour. One week the supplier changed its authentication and the import started failing at the first request. Nothing visible broke: the site simply kept showing stale stock, and customers ordered sofas that were no longer available.
After that, the team added a heartbeat check with an hourly schedule and a 20-minute grace period. The import script now sends a start ping, a failure ping from its error handler and a success ping only after the new stock figures are written. Alerts go to the developer on call and to the shop manager's phone. The next time the feed broke, they knew within the hour and switched the affected products to "call to order" while it was fixed.
FAQ
Is this the same as uptime monitoring?
No. Uptime monitoring probes your website from outside to check it responds. Heartbeat monitoring waits for your own jobs to report in. Most businesses benefit from both, because they catch different failures.
What if the monitoring service itself goes down?
Choose a provider with a status history you trust, or self-host an open-source option on separate infrastructure. Either way, keep the ping call non-blocking so an outage on their side never stops your job.
Can I monitor jobs that run on someone else's platform?
Usually, yes. If the platform lets your job make an outbound HTTP request at the end, it can send a heartbeat.
How many checks should a small business have?
As many as you have scheduled jobs whose silent failure would cost money or trust. For many small sites that is somewhere between a handful and a couple of dozen.
If you would like a hand listing your scheduled jobs and putting heartbeat checks on the ones that matter, send us a note about what runs behind your site.