Heartbeat Monitoring: How to Monitor Cron Jobs and Background Tasks
Monitorion Team
Engineering Team
Your nightly database backup cron job stopped running three weeks ago. Nobody noticed because cron jobs do not have a URL you can ping. Your monitoring dashboard shows all green — every HTTP check passes, every ping succeeds, every SSL certificate is valid. But the backup that protects your entire business has not run in 21 days. This is the failure mode that traditional monitoring cannot catch. Heartbeat monitoring can.
What Is Heartbeat Monitoring?
Heartbeat monitoring flips the traditional monitoring model. Instead of your monitoring tool reaching out to check on a service, the service reaches out to your monitoring tool. Your cron job sends an HTTP request to a unique heartbeat URL after it completes successfully. If the monitoring tool does not receive that request within an expected time window, it triggers an alert.
Think of it as a dead man's switch. As long as the process keeps checking in on schedule, everything is fine. The moment it stops — because it crashed, because the cron daemon was misconfigured, or because the job is hanging — the silence itself is the alert.
Why Traditional Monitoring Cannot Watch Cron Jobs
- They are ephemeral — they run for seconds or minutes, then exit. There is no persistent process to check.
- They have no HTTP endpoint — a cron job that processes CSV files does not listen on any port.
- They fail silently — when a cron job fails, it might write to a log file nobody reads.
- The absence of activity is the failure — the problem is not an error; it is that something did not happen at all.
Common Use Cases
- Database backups — ping the heartbeat URL after a successful
pg_dumpormysqldump. - Data pipeline jobs — ETL processes that import, transform, and load data.
- Scheduled email sends — newsletter dispatches, billing reminders.
- Cache warming — pre-computing expensive queries on a schedule.
- Certificate renewal — your certbot renewal cron should ping a heartbeat on success.
- Queue consumers — background workers that process queued jobs.
How to Set Up Heartbeat Monitoring in Monitorion
Step 1: Click "Add Monitor" and select Heartbeat. Name it descriptively — "Nightly Database Backup."
Step 2: Set the expected interval with a grace period. If your cron job runs every hour, set the interval to 1 hour with a 15-minute grace period.
Step 3: Copy the heartbeat URL. It looks like: https://app.monitorion.com/api/v1/heartbeat/abc123
Step 4: Add the ping to your job. In a bash script:
#!/bin/bash
pg_dump mydb > /backups/mydb_$(date +%Y%m%d).sql
if [ $? -eq 0 ]; then
curl -s https://app.monitorion.com/api/v1/heartbeat/abc123
fi
In Python:
import requests
def run_backup():
perform_backup()
requests.get("https://app.monitorion.com/api/v1/heartbeat/abc123")
The key: only ping the heartbeat URL after the job completes successfully. If the job fails, the missing ping triggers the alert.
Step 5: Configure alert channels. Route critical jobs to PagerDuty or SMS, less critical ones to Slack or email.
Heartbeat vs Health Check
- Use HTTP/health checks for continuously running services: web servers, API servers.
- Use heartbeat monitors for periodic tasks: cron jobs, scheduled scripts, batch processing.
A comprehensive monitoring setup uses both. Your web server gets an HTTP monitor. Your backup cron gets a heartbeat monitor. Together, they cover both "is it running?" and "did it run?"
Silent failures are the most dangerous kind. Set up your first heartbeat monitor for free and make sure your critical background tasks never fail silently again.
Enjoyed this post?
Get monitoring tips and product updates delivered to your inbox.