Most monitoring watches for things that fail loudly. A cron job fails quietly. The backup script that stopped running three weeks ago doesn't throw an error anywhere you'll see it. It just doesn't run, and you find out the day you need the backup.

Uptime checks can't catch this, because there is nothing to check. The fix is to flip the direction: the job tells a monitor "I ran", and the monitor alerts you when that message stops arriving. That's a heartbeat, sometimes called a dead man's switch.

How a heartbeat works

  1. You create a heartbeat monitor and get a unique URL.
  2. You tell the monitor how often the job runs (say every 24 hours) and how much grace to allow (say 30 minutes).
  3. The job requests the URL at the end of every successful run.
  4. If no request arrives within the interval plus the grace period, the monitor opens an incident and alerts you.

The important detail is step 3: ping at the end, and only on success. A ping at the start tells you the job started, not that it finished.

Add it to a crontab

The && is doing the work here. curl only runs if the backup script exits 0.

0 3 * * * /opt/scripts/backup-db.sh && curl -fsS --retry 3 --max-time 10 https://api.foursight.cloud/hb/<YOUR_TOKEN> 

Why those flags:

  • -f makes curl fail on an HTTP error instead of printing an error page and exiting 0.
  • -sS keeps cron mail quiet unless something goes wrong.
  • --retry 3 rides out a brief network blip, so one dropped packet doesn't page anyone.
  • --max-time 10 stops a hung request from holding the job open.

In a GitHub Actions schedule

Store the token as a repository secret and ping as the last step. Steps stop at the first failure, so the ping only fires when everything before it passed.

on: schedule: - cron: "0 3 * * *" jobs: nightly: runs-on: ubuntu-latest steps: - run: ./scripts/nightly-export.sh - name: Heartbeat run: curl -fsS --retry 3 "https://api.foursight.cloud/hb/${{ secrets.FOURSIGHT_HEARTBEAT_TOKEN }}" 

From Node

async function main() { await runNightlyJob(); await fetch("https://api.foursight.cloud/hb/<YOUR_TOKEN>"); } 

If runNightlyJob() throws, the fetch never happens, and the missing ping is your alert.

From PowerShell (Windows Task Scheduler)

& C:\scripts\export.ps1 if ($LASTEXITCODE -eq 0) { Invoke-RestMethod -Uri "https://api.foursight.cloud/hb/<YOUR_TOKEN>" -Method Get } 

Picking the grace period

Set the grace to cover the job's normal variation in run time, not its worst case. A backup that usually takes 10 minutes and sometimes 25 needs about 30 minutes of grace. If you set the grace to hours, a stuck job can sit for hours before anyone hears about it.

Things that bite people

  • Pinging before the work. You'll get a green dashboard for a job that crashes every night.
  • Swallowing errors. script.sh; curl ... pings even when the script fails. Use &&.
  • One token for many jobs. If two jobs share a URL, one healthy job hides the other's failure. Give each job its own monitor.
  • Forgetting time zones. Cron runs in the server's time zone; make sure the expected schedule in your monitor matches.

Doing this with FourSight

I build FourSight, so this is the tool the examples use. Heartbeat monitors are on the Growth plan ($40/mo, 100 monitors), and alerts go to email, Slack, webhooks or SMS depending on plan. The pattern above works the same with any heartbeat service; the URL is the only part that changes.

Full guide with more examples: https://foursight.cloud/guides/heartbeat-monitoring-cron-jobs