Monitor a cron job with crontab.
One curl at the end of the job. Four minutes, start to finish.
Before you start
You need a heartbeat in Upglory with its period and grace set to match the job. Its page shows the ping address; it looks like https://ping.upglory.io/abc123.
Settings that match this schedule
- Period24 hoursThe schedule the line runs on, not how long the job takes.
- Grace30 minutesThe longest the job has ever taken, plus a little.
- Channelsemail, TelegramInherited from the workspace default. Change it on this heartbeat if it matters less than the others.
The line
Add a curl to the end of the job, joined with && so it only pings when the job succeeded.
# every night at 2
0 2 * * * /usr/local/bin/backup-nightly && curl -fsS -m 10 https://ping.upglory.io/abc123 > /dev/null -fsS keeps curl quiet unless something fails, and -m 10 stops it waiting longer than ten seconds.
Measure the run time
Ping /start when the job begins. The plain ping at the end then records how long it ran, and a long run is not mistaken for a missed one.
0 2 * * * curl -fsS -m 10 https://ping.upglory.io/abc123/start > /dev/null; /usr/local/bin/backup-nightly && curl -fsS -m 10 https://ping.upglory.io/abc123 > /dev/null
Report a failure
If the job knows it failed, say so at once instead of waiting for the grace window to run out.
/usr/local/bin/backup-nightly && curl -fsS -m 10 https://ping.upglory.io/abc123 || curl -fsS -m 10 https://ping.upglory.io/abc123/fail
Test it
Use Send a test ping on the heartbeat's page, or run the curl by hand. Nothing alerts until the first ping arrives, so a job you have not deployed yet never raises an alarm.
What you will see if it stops
Thirty minutes after 02:00, the heartbeat turns down and the alert email arrives with the last ping time in it, so you know whether the job stopped or slowed. When the next night's run pings, it recovers on its own and you get one short line saying so.
last ping yesterday 02:04, ran 3 min 12 s
Email and Telegram told at 02:30