/ use-cases / cron-job-monitoring

How to monitor a cron job with a heartbeat

A cron job that stops running fails no request and throws no error. Here is how a heartbeat monitor catches the silence and alerts you before users notice.

Updated · Published

Fettle heartbeat list with a nightly backup and an hourly export job, each showing its period, grace window and last ping

Cron job monitoring tells you when a scheduled job did not run or did not finish, not only when it failed loudly. Fettle is uptime monitoring for developers, and it watches cron jobs with heartbeats: the job calls a ping URL each time it succeeds, and Fettle opens an incident when the ping does not arrive on time. The whole setup is one crontab line:

0 3 * * * /opt/backup/run-nightly-backup.sh && curl -fsS --retry 3 https://api.fettle.sh/v1/heartbeat/YOUR_TOKEN > /dev/null

The rest of this guide covers why the usual signals miss a stalled job, what is worth watching, and how to size the window before a late job counts as missing.

Why the obvious signals miss a stalled cron job

Everything in the rest of this site is about checking whether something answers: an HTTP request to a URL, a TLS handshake, a DNS lookup. A scheduled job usually has none of that to check. Think of a nightly backup, an hourly export, a billing run or a cache warm. Most of them are a process that starts, does work and exits, with no listener on the other end. There is no request to send and no response to fail.

That is exactly what makes a stalled cron job dangerous: it fails silently by default. If the cron daemon never fires, the missing run is invisible, because nothing errors. The same silence follows if the job runs in a container that gets rescheduled or redeployed and the crontab does not come back with it. If the job exits early on an unhandled exception, nothing watches its exit code unless you built something to watch it. A job can also hang long past its finish time, stuck on a lock, a slow query or a hung connection. No one is alerted unless the job's own code has a timeout. And a script that returns 0 can still have done nothing useful if its input was empty. A clean exit is not the same claim as a correct one.

None of these failure modes trip a health check, because there is no check to trip. The job does not fail a request. It simply does not run, or does not finish, and the calendar keeps going without it. The only way to catch that class of failure is to expect a signal from the job and notice when it stops arriving. That is a heartbeat, sometimes called a dead man's switch. Instead of going out to check that something answers, the monitor waits for the job to check in. The alert fires on silence rather than on a bad response.

What is worth monitoring

Not every job needs the same watch. What is worth wiring a heartbeat to:

  • Anything that runs unattended on a schedule, whose failure nobody would notice until they needed what it was supposed to produce: a backup, an export, a report, a billing sweep.
  • Anything with a real deadline, not just a rough cadence. A job that has to finish before a downstream process reads its output deserves a tighter grace window than one that is simply "roughly nightly."
  • Long-running jobs where "still running" and "hung" look identical from the outside for a while. Those benefit from a mid-run signal, not just a start and an end.
  • Jobs that already catch and log their own errors internally. A job with real error handling can report a failure the moment it happens instead of waiting for a deadline to pass.

What a heartbeat cannot tell you is whether the job did the right thing. It confirms the job ran, not that its output was correct. Pairing it with the job's own logging or a downstream data check still matters. The heartbeat's job is narrower than that, and worth being honest about.

How to set it up in Fettle

  1. Create a heartbeat from the dashboard or with a write-scoped API key, and name it after the job it watches. Set period_seconds to the job's expected cadence, anywhere from 60 seconds to 30 days. Set grace_seconds to how much lateness you can tolerate, from zero to 30 days, independent of the period. Grace is added on top of the period: a heartbeat goes late only once period plus grace has passed since the last ping, so a grace longer than the period is allowed and simply delays the alert.
  2. Fettle generates a ping URL for the heartbeat, in the form https://api.fettle.sh/v1/heartbeat/<token>. The token in that URL is the only credential a ping needs. No API key is needed to call it, so it is safe to paste straight into a crontab line or a CI job.
  3. Append the ping as the last thing the job does, so it only fires on success:
./run-nightly-backup.sh && curl -fsS https://api.fettle.sh/v1/heartbeat/YOUR_TOKEN

The endpoint accepts a bare GET as well as POST, so a plain curl with no method flag works from any shell, wget, or CI step that can make an HTTP request. In a crontab, the whole entry for a backup that runs at 03:00 every night looks like this:

0 3 * * * /opt/backup/run-nightly-backup.sh && curl -fsS --retry 3 https://api.fettle.sh/v1/heartbeat/YOUR_TOKEN > /dev/null

--retry 3 rides out a brief network blip on the ping itself (see curl's manual), and > /dev/null keeps cron from mailing you the response body after every successful run: cron mails any output a job prints to the crontab's owner or its MAILTO address, as crontab(5) describes.

For a schedule: trigger in GitHub Actions, where the pings become workflow steps and the URL lives in a repository secret, see monitoring a scheduled GitHub Actions workflow.

  1. For a job long enough that a stall partway through matters, ping the /start path when the job begins, before the ping in step 3. It does not change the heartbeat's state, but it pushes the deadline out by another period + grace from that moment. A job that is still legitimately running then does not trip the switch mid-execution. If the job's own code already catches its failures, call /fail directly instead of waiting for the deadline. It opens an incident immediately rather than after the grace window elapses.

A ping that lands anywhere within period + grace of the last one is on time, and nothing alerts. Only when that window elapses with no ping does the heartbeat flip to overdue and open an incident. Grace is still a judgment call, not a formula. The uptime/SLA calculator won't derive one for you, but it is a useful gut-check. Feed it a target like 99.5% and it shows the total downtime that allows over a day, week, month or year. That helps you judge how strict "basically always on time" should be before you pick a grace value.

Prefer an MCP-aware client to raw curl? Point it at the same account with this one-liner:

{
  "mcpServers": {
    "fettle": {
      "url": "https://api.fettle.sh/mcp",
      "headers": { "Authorization": "Bearer fettle_your_key_here" }
    }
  }
}

Which alerts to wire

A missed heartbeat has no other alarm attached to it, so the channel it reaches matters more here than for a monitor backing up a platform's own dashboard. Fettle sends heartbeat alerts by email and Telegram on every plan, and to Slack, Discord or a webhook from Plus. Wire the same channel your team already gets paged on for production incidents. A stalled job caught days later, once someone notices stale data, is a worse outcome than a noisy alert.

Two habits keep it from becoming noise of its own. First, if you know in advance that a job will not run, pause the heartbeat itself rather than letting it go overdue and page someone. A deliberate migration or a maintenance freeze on the system the job depends on are both good reasons. Pausing stops the clock and silently closes anything already open, and resuming picks it back up. Second, an open incident sends one down alert; repeats come only from the plan's reminders, and acknowledging the incident stops them.

How many heartbeats and alert channels each plan includes is on the pricing page. The full walkthrough for generating a key and reading heartbeat state back through the API is in the quickstart guide.

Questions

What is a heartbeat monitor?
It is the inverse of an uptime check. An uptime check fails when a request to your app fails; a heartbeat fails when an expected ping from your job does not arrive on schedule.
What happens if my job runs a few minutes later than usual?
Nothing, as long as it pings within period plus grace. Grace is slack you add on top of the expected cadence, so ordinary jitter does not trigger an alert.
Can Fettle monitor a job that has no public URL at all?
Yes. A heartbeat needs nothing inbound. The job makes one outbound request to a ping URL Fettle gives it; there is no endpoint on your side for anything to reach.

Start monitoring in a minute

The free plan checks up to 20 monitors as often as every 3 minutes from 1 region, and emails you when one breaks. See pricing for the paid intervals, or follow the quickstart to do it from the API.