How to Monitor Cron Jobs with Heartbeat Checks

Step-by-step guide to heartbeat monitoring for cron jobs, background workers, and scheduled tasks. Get alerted when a job silently fails. Free code examples in bash, Node.js, and Python.

Frequently Asked Questions

What is heartbeat monitoring for cron jobs?

Heartbeat monitoring inverts the usual uptime check: your cron job calls a unique ping URL after each successful run. If sed.sh does not receive a ping within the grace period after the expected time, it sends you an alert email. This catches silent failures, hangs, and jobs that disappear from the crontab without anyone noticing.

How do I monitor a cron job with the sed.sh API?

Create a heartbeat monitor with POST /uptime/monitors, setting type to "heartbeat". The response includes a heartbeatUrl. Add curl --silent "$HEARTBEAT_URL" > /dev/null at the end of your cron script, after all other commands. If the script exits early due to an error, the ping is never sent, and sed.sh will alert you after the grace period.

What should I set for the grace period?

Use 1.5× your job interval as a starting point. For an hourly job (interval: 3600), set gracePeriod: 5400. This gives the job 1.5 hours to complete before an alert fires. Increase it for jobs that occasionally run long due to varying data volume, and decrease it for latency-sensitive jobs where you need to know quickly.

How is this different from a regular uptime monitor?

A regular HTTP uptime monitor checks whether your web server responds. It cannot tell you whether a background job ran. A heartbeat monitor works the other way: your job signals that it ran. Silence is the failure condition — not an HTTP error code.

Can I monitor jobs that run less often than hourly?

Yes. The maximum interval value is 3600 seconds, but you can create a monitor with interval: 3600 and set a large gracePeriod. For a nightly job, set gracePeriod: 86400 (or higher) and ping once per nightly run. The monitor will alert if more than gracePeriod seconds pass without a ping.

What happens if the heartbeat ping URL call itself fails?

The curl or requests call can fail due to a transient network error. Use retry flags (curl --retry 3) to handle this. If the ping genuinely cannot reach sed.sh, the grace period will eventually expire and you will get an alert — which is the safe-failure behavior. Tune the grace period generously enough that a single failed ping in an interval does not cause false alarms.