How to monitor a cron job
To monitor a cron job you use a heartbeat: a unique URL your job calls every time it finishes successfully. If the call doesn’t arrive within the expected interval, the monitoring service alerts you. That way you find out about backups, invoices or syncs that stopped running.
Published · ganyant
Why do they fail silently?
Nobody is watching a cron job. If the server rebooted, a password changed, the disk filled up or the script threw an error, it just doesn’t run, and nobody notices until that backup or invoice is needed.
How does a heartbeat work?
It’s the reverse of a normal check: we don’t visit anything, your job reports in. You say how often it should run and get a URL. Every time the job finishes, it calls it. If the interval passes with no call, an incident opens.
How do I add it to my job?
Add the call at the end, only when everything went well. In cron: 0 3 * * * /opt/backup.sh && curl -fsS https://your-heartbeat-url. In PowerShell: Invoke-WebRequest https://your-heartbeat-url. In Python: requests.get('https://your-heartbeat-url', timeout=10) at the end of the script.
The && matters: if the script fails, the URL isn’t called and you find out.
What interval should I set?
The same as your job, with some margin. If it runs hourly and sometimes takes 10 minutes, don’t set exactly 60 minutes, so a normal delay doesn’t trigger an alert.
How does ganyant do it?
In ganyant you create a Heartbeat monitor, pick the interval and copy the URL. It’s on every plan, including the free one, and the alert reaches you by email, Slack, Telegram, Discord or whichever channel you use.