What Is Heartbeat Monitoring for Cron Jobs?
Heartbeat monitoring tracks scheduled tasks by waiting for check-ins. If your cron job doesn't ping within the expected timeframe, you get alerted. Simple explanation with examples.
Wakestack Team
Engineering Team
Heartbeat monitoring is a passive monitoring approach where your scheduled jobs "check in" by pinging a URL when they complete. If the heartbeat isn't received within the expected timeframe, you get alerted. It's specifically designed for cron jobs, background workers, and any task that runs periodically.
Think of it like a dead man's switch—if your job stops running, you'll know immediately instead of finding out days later.
How Heartbeat Monitoring Works
Unlike uptime monitoring (which actively checks services), heartbeat monitoring waits for your jobs to report:
Normal Operation:
─────────────────────────────────────────────────────
Job runs → Pings heartbeat URL → "All good"
Job runs → Pings heartbeat URL → "All good"
Job runs → Pings heartbeat URL → "All good"
Failure Detection:
─────────────────────────────────────────────────────
Job runs → Pings heartbeat URL → "All good"
Job fails → No ping → ⚠️ Alert!
(expected by 2:15, none received)
The workflow:
- Create a heartbeat monitor with expected schedule
- Get a unique URL (e.g.,
ping.wakestack.co.uk/hb/abc123) - Add ping to end of your job on success
- Monitor expects ping within schedule + grace period
- Missing ping = alert
Heartbeat vs Uptime Monitoring
| Aspect | Heartbeat | Uptime |
|---|---|---|
| Direction | Job pings monitor | Monitor pings service |
| Best for | Scheduled tasks | Always-on services |
| Checks | "Did it run?" | "Is it responding?" |
| Active/Passive | Passive (waits) | Active (requests) |
| Examples | Cron jobs, workers | Websites, APIs |
What Heartbeat Monitoring Catches
- Jobs that fail to start — Cron daemon issues, scheduling errors
- Jobs that crash — Script errors, exceptions
- Jobs that hang — Stuck processes, infinite loops
- Jobs that run late — Resource contention, slow execution
- Jobs that partially fail — Success ping never reached
Common Use Cases
1. Database Backups
# Backup runs nightly at 2 AM
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupIf the backup fails, you'll know immediately—not when you need to restore.
2. Data Synchronization
# Sync data every hour
0 * * * * /scripts/sync.sh && curl -fsS https://ping.wakestack.co.uk/hb/syncCatch sync failures before data gets stale.
3. Report Generation
# Weekly reports on Sunday
0 0 * * 0 /scripts/report.sh && curl -fsS https://ping.wakestack.co.uk/hb/reportsKnow if reports fail to generate before stakeholders ask.
4. Background Workers
# Worker process that should run continuously
while True:
process_queue()
requests.get("https://ping.wakestack.co.uk/hb/worker")
time.sleep(60)If the worker dies, no heartbeat arrives.
Setting Up Heartbeat Monitoring
Step 1: Create a Heartbeat Monitor
In Wakestack:
- Add Monitor → Select "Heartbeat"
- Set schedule (e.g., "Every 24 hours")
- Set grace period (e.g., "1 hour")
- Get your unique URL
Step 2: Add Ping to Your Job
Bash (cron):
# Only ping on success (&&)
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupPython:
import requests
def run_job():
result = do_work()
if result.success:
requests.get("https://ping.wakestack.co.uk/hb/myjob")Node.js:
async function runJob() {
await processData();
// Ping on success
await fetch('https://ping.wakestack.co.uk/hb/myjob');
}Step 3: Configure Alert Channels
Set up notifications:
- Slack for team awareness
- Email for backup
- PagerDuty for critical jobs
Best Practices
1. Only Ping on Success
# Good: Ping only if backup succeeds
/scripts/backup.sh && curl https://ping.wakestack.co.uk/hb/backup
# Bad: Ping regardless of outcome
/scripts/backup.sh; curl https://ping.wakestack.co.uk/hb/backup2. Use Appropriate Grace Periods
Account for job duration variability:
| Job Duration | Grace Period |
|---|---|
| Under 1 min | 5-10 min |
| 1-10 min | 15-30 min |
| 10-60 min | 1-2 hours |
| 1+ hours | 2-3 hours |
3. Add Retry Logic to Ping
# Retry 3 times with 5-second delays
curl -fsS --retry 3 --retry-delay 5 https://ping.wakestack.co.uk/hb/backup4. One Heartbeat Per Job
Don't share heartbeat URLs between different jobs. Each job needs its own monitor.
5. Include Duration (Optional)
Track how long jobs take:
START=$(date +%s)
/scripts/backup.sh
DURATION=$(($(date +%s) - START))
curl "https://ping.wakestack.co.uk/hb/backup?duration=$DURATION"Common Mistakes
1. Pinging Before the Job Runs
# Wrong: Ping happens even if job fails
curl https://ping.wakestack.co.uk/hb/backup
/scripts/backup.sh # This might fail2. Too Short Grace Period
Job takes 30 minutes but grace period is 5 minutes? You'll get false alerts.
3. Not Testing the Setup
Always run your job manually and verify:
- Job completes successfully
- Heartbeat is received
- Dashboard shows "healthy"
4. Forgetting to Update When Jobs Change
If you change job timing, update the heartbeat schedule to match.
When Wakestack Is a Good Fit
Wakestack's heartbeat monitoring integrates with uptime and server monitoring:
- Combined view — See scheduled jobs alongside services
- Same dashboard — No separate tool for heartbeats
- Consistent alerting — Same channels for all alerts
- Included in plans — Not an extra cost
Heartbeat Monitor Setup
Name: Nightly Backup
Type: Heartbeat
Expected: Every 24 hours
Grace Period: 2 hours
Alert after: 1 missed heartbeat
URL: https://ping.wakestack.co.uk/hb/abc123xyz
Set up heartbeat monitoring — Included in all plans.
Quick Implementation
For Cron Jobs
# /etc/crontab
0 2 * * * root /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupFor Systemd Timers
# backup.service
[Service]
ExecStart=/scripts/backup.sh
ExecStopPost=/usr/bin/curl -fsS https://ping.wakestack.co.uk/hb/backupFor Kubernetes CronJobs
spec:
containers:
- name: backup
command: ["/bin/sh", "-c"]
args:
- /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupKey Takeaways
- Heartbeat monitoring waits for scheduled jobs to check in
- If the heartbeat doesn't arrive on schedule, you get alerted
- It catches silent failures that cron can't detect
- Only ping on success, not before or regardless of outcome
- Set grace periods based on job duration variability
Related Resources
Frequently Asked Questions
What is heartbeat monitoring?
Heartbeat monitoring tracks jobs that run on a schedule. Your job pings a unique URL when it completes. If the ping doesn't arrive within the expected timeframe, you get alerted. It's the opposite of active monitoring—instead of checking if something responds, you wait for it to check in.
How is heartbeat monitoring different from uptime monitoring?
Uptime monitoring actively sends requests to check if services respond. Heartbeat monitoring passively waits for scheduled jobs to report in. Uptime is for always-on services; heartbeat is for periodic tasks like cron jobs.
Why do cron jobs fail silently?
Cron has no built-in notification system for failures. By default, it only sends email to a local mailbox nobody checks. Jobs can fail for weeks before anyone notices. Heartbeat monitoring catches these failures immediately.
Related Articles
Cron Job Monitoring: Never Miss a Failed Scheduled Task
Learn how to monitor cron jobs effectively. Get alerts when scheduled tasks fail, run late, or don't run at all. Comprehensive guide for Linux cron monitoring.
Read moreHeartbeat Monitoring: Track Background Jobs and Scheduled Tasks
Learn how heartbeat monitoring works for cron jobs, background workers, and scheduled tasks. Get alerts when jobs fail to run or take too long.
Read moreUptimeRobot Alternative: Why Teams Are Switching to Wakestack
Looking for an UptimeRobot alternative? Compare Wakestack vs UptimeRobot for uptime monitoring, status pages, and server monitoring. See why teams are making the switch.
Read moreReady to monitor your uptime?
Start monitoring your websites, APIs, and services in minutes. Free forever for small projects.