What is heartbeat monitoring?

Heartbeat monitoring, also called cron monitoring or a dead man's switch, watches scheduled jobs by expecting a ping. The job calls a unique URL when it finishes; if the ping does not arrive within the expected period plus a grace time, you get an alert. It catches jobs that crash, hang or never start.

Updated · by PuzariCloud · also called cron monitoring, dead man's switch, cron job monitoring

Why heartbeat monitoring matters

Scheduled jobs fail silently. A backup script that never runs produces no error to alert on; a stopped cron daemon, a server rebuilt without its crontab, or a job stuck on a lock all look like nothing at all.

Alerting on the absence of success covers every one of those causes with one rule. Adding start and fail pings also records run times and failure output, so jobs that slowly take longer are visible before they overlap.

How to measure heartbeat monitoring

alert time = expected run time + grace period   (no success ping received)
run time   = success ping time − start ping time

Worked example

A backup runs daily at 02:00 (cron 0 2 * * *) with a 30-minute grace period. Last night it sent a start ping at 02:00:04 and a success ping at 02:06:51.

  1. Run time = 02:06:51 − 02:00:04 = 6 min 47 s.
  2. Tonight the next run is expected at 02:00. If no success ping arrives within 30 minutes, the alert fires at 02:30.
  3. If the job pings /fail or a non-zero exit code instead, Vigil records a failure straight away rather than waiting for the grace period.

Result: One rule now covers a crashed script, a missing crontab, a dead server and a job that hangs.

Common mistakes

  • Pinging only at the start. A start ping says the job began, not that it worked. Ping on success, after the work.
  • Pinging even when the job failed. backup.sh; curl … pings whatever happened. Use && or send the exit code.
  • A grace period shorter than normal variation. If the job sometimes takes 40 minutes, a 30-minute grace period alerts on good nights.
  • Timezone mismatch. A schedule set in UTC for a job that runs on Asia/Kolkata time looks hours late or early. Set the schedule's timezone.

How Vigil handles heartbeat monitoring

  • A Vigil Heartbeat monitor gives each job a URL: curl -fsS https://puzaricloud.in/ping/<token>. Optional /start, /fail and /<exit-code> pings track run time and failures, and a POSTed body is kept as the job's log.
  • The schedule is either a fixed period with a grace time or a cron expression with a timezone, and a maximum run time catches jobs that hang.
  • The cron schedule library and the cron expression explainer help get the schedule right; the guides on cron jobs and backups go further.

Heartbeat monitoring (cron monitoring): frequently asked questions

Is heartbeat monitoring the same as cron monitoring?

For scheduled jobs, yes. Heartbeat monitoring is the general idea (expect a regular signal, alert on silence); cron monitoring is its most common use. The pattern is also called a dead man's switch.

How long should the grace period be?

Longer than the job's normal variation in run time, shorter than the delay you can tolerate. For a nightly backup that takes 5 to 15 minutes, 30 to 60 minutes is typical.

Can heartbeats watch things other than cron?

Yes: queue consumers, long-running workers, IoT devices and backup appliances can all ping on a schedule, and the alert fires when they go quiet.

Vigil by PuzariCloud

Measure it instead of estimating it

Uptime and API checks, heartbeats, status pages, on-call, traces, errors, logs and real user monitoring in one place, with every feature on every plan, including Free.