InfraNestInfraNest

Monitors & checks

Monitor a cron job or script

Most checks reach out to something of yours. A heartbeat monitor works the other way around: your backup script, cron job or scheduled task calls in to…

A heartbeat monitor watches a cron job, backup script or scheduled task by waiting for it to call in — it's for anyone who needs to know when a background job silently stops running.

Overview

  • Most monitors reach out to check on something; a heartbeat monitor works in reverse — your job calls InfraNest each time it finishes.
  • If the call doesn't arrive on time, InfraNest alerts you.
  • This is the best way to catch a job that stops running without throwing an obvious error.

Set one up

  1. Go to Monitoring and select Add a monitor.
  2. Choose Heartbeat / Cron monitor as the type.
  3. Give it a Monitor name you'll recognise in an alert — "Nightly database backup" beats "job 1".
  4. Set the Check interval to how often the job is supposed to run.
  5. Set a Grace period (seconds) — extra time allowed before the job is considered late. A backup that usually takes four minutes but occasionally takes eight needs a grace period comfortably longer than that overrun.
  6. Select Create monitor.

You don't enter a URL for this type — InfraNest creates one for you when you save.

Make your job check in

  1. Open the monitor and find its Ping URL, along with a ready-to-paste one-liner.
  2. Add that line to the end of your script or cron job, so it only runs when the job actually succeeded:
0 3 * * *  /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 https://your-infranest-url/api/heartbeat/your-uuid

The && matters: it means the check-in happens only if the backup itself exited successfully. A failed job then stays silent, and silence is what raises the alert.

  1. Use Copy rather than retyping the URL — the identifier in it is unique to this monitor.

What happens next

  • Every check-in marks the monitor Up and records the time as its Last ping.
  • A brand-new monitor stays pending until its first window has passed, so you have time to wire the check-in up without being alerted about it.
  • If nothing arrives within the Check interval plus the Grace period (seconds), the monitor goes Down and opens an incident, so your usual alert destinations fire.
  • The next check-in resolves the incident and alerts you that it's back — you don't have to close it by hand.

NotePause monitor is safe to use on a heartbeat monitor: the ping URL keeps answering normally, so a job that's still calling it won't start reporting failures. InfraNest simply stops watching until you select Resume monitor.

TipTreat the ping URL as a secret. Anyone who has it can report your job as healthy — which would hide a real failure.

Troubleshooting

  • No heartbeat received yet on the monitor means InfraNest hasn't heard from the job at all. Run the curl line by hand from the same machine: if that turns the monitor green, the problem is in your script, not here.
  • If the machine can't reach the internet outbound, the check-in can't arrive — allow outbound HTTPS to InfraNest.
  • A monitor that alerts every night at the same time usually has a Grace period (seconds) shorter than the job's real worst-case runtime.

Related articles

Start in seconds

Bring your whole infrastructure into one modern dashboard.

Free plan · No credit card required · Set up in minutes