Heartbeat 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.
Wakestack Team
Engineering Team
Who This Is For
This guide is for developers and DevOps engineers who run scheduled tasks, background jobs, or cron jobs that need to be monitored. If you've ever had a critical job fail silently, heartbeat monitoring is the solution.
What Is Heartbeat Monitoring?
Heartbeat monitoring is a passive monitoring approach:
- You create a heartbeat URL with an expected schedule
- Your job pings that URL when it completes
- If the ping doesn't arrive on schedule, you get alerted
How It Works
Your Cron Job Heartbeat Monitor
│ │
│ [Job runs successfully] │
│ │
├──────── HTTP GET ────────────────→│ "Heartbeat received"
│ ping.wakestack.co.uk/hb/abc123 │
│ │
│
✗ [Job fails/doesn't run] │
│
│ No ping received │ ⚠️ Alert: "Job missed heartbeat"
vs Active Monitoring
| Active (Uptime) Monitoring | Passive (Heartbeat) Monitoring |
|---|---|
| Monitor sends requests | Job sends check-in |
| For always-on services | For scheduled jobs |
| "Is it responding?" | "Did it run?" |
| HTTP, TCP, Ping | HTTP ping from job |
When You Need Heartbeat Monitoring
Cron Jobs
Any scheduled task:
# Backup database every night
0 2 * * * /scripts/backup.shIf this fails silently, you won't know until you need the backup.
Background Workers
Jobs processed asynchronously:
Queue processor
Email sender
Report generator
Data importer
Scheduled Scripts
Periodic maintenance:
Log rotation
Cache clearing
Data synchronization
Health checks
Serverless Functions
Scheduled Lambda/Cloud Functions:
Daily reports
Cleanup tasks
Data aggregation
Setting Up Heartbeat Monitoring
Step 1: Create a Heartbeat Monitor
In Wakestack:
- Go to Monitors → Add Monitor
- Select "Heartbeat" type
- Configure schedule:
- Name: "Nightly Backup"
- Expected every: 24 hours
- Grace period: 30 minutes
You'll receive a unique URL:
https://ping.wakestack.co.uk/hb/abc123xyz
Step 2: Add Ping to Your Job
At the end of your job, ping the heartbeat URL:
Bash:
#!/bin/bash
# Your job logic here
/scripts/backup.sh
# Ping heartbeat on success
curl -fsS --retry 3 https://ping.wakestack.co.uk/hb/abc123xyzPython:
import requests
def run_job():
# Your job logic here
process_data()
# Ping heartbeat on success
requests.get("https://ping.wakestack.co.uk/hb/abc123xyz")Node.js:
const https = require('https');
async function runJob() {
// Your job logic here
await processData();
// Ping heartbeat on success
https.get('https://ping.wakestack.co.uk/hb/abc123xyz');
}Step 3: Configure Alerts
Set up notifications for missed heartbeats:
- Email for all misses
- Slack for team visibility
- PagerDuty for critical jobs
Heartbeat Monitoring Best Practices
1. Ping After Success, Not Before
Bad:
curl https://ping.wakestack.co.uk/hb/abc123 # Ping first
/scripts/backup.sh # Job might failGood:
/scripts/backup.sh # Job runs
if [ $? -eq 0 ]; then
curl https://ping.wakestack.co.uk/hb/abc123 # Ping only on success
fi2. Use Appropriate Grace Periods
Job takes 5 minutes? Don't alert if it's 1 minute late.
Job duration: ~5 minutes
Expected: every 1 hour
Grace period: 15 minutes
3. Include Job Duration
Some heartbeat systems accept timing data:
START=$(date +%s)
/scripts/backup.sh
END=$(date +%s)
DURATION=$((END-START))
curl "https://ping.wakestack.co.uk/hb/abc123?duration=${DURATION}"4. Handle Retries
Use retry logic for the ping itself:
curl -fsS --retry 3 --retry-delay 5 https://ping.wakestack.co.uk/hb/abc1235. Monitor Job Duration Too
Alert if jobs take too long:
Expected duration: < 10 minutes
Alert if: > 30 minutes
Common Heartbeat Monitoring Scenarios
Scenario 1: Nightly Backups
Job: Database backup
Schedule: Daily at 2 AM
Expected duration: 30 minutes
Grace period: 1 hour
Alert: Email + SlackScenario 2: Hourly Data Sync
Job: Sync data from external API
Schedule: Every hour
Expected duration: 5 minutes
Grace period: 15 minutes
Alert: SlackScenario 3: Weekly Reports
Job: Generate weekly analytics
Schedule: Sunday at midnight
Expected duration: 2 hours
Grace period: 3 hours
Alert: EmailScenario 4: Background Queue
Job: Process payment queue
Schedule: Continuous (ping every 5 min)
Expected: Every 5 minutes
Grace period: 10 minutes
Alert: PagerDuty (critical)Heartbeat vs Other Monitoring
| Use Case | Monitoring Type |
|---|---|
| Web server up | Uptime (HTTP) |
| Database accessible | Uptime (TCP) |
| Cron job ran | Heartbeat |
| Background worker alive | Heartbeat |
| SSL certificate valid | SSL monitoring |
| Server healthy | Server agent |
Integration Examples
With Cron
# /etc/crontab
0 2 * * * root /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupWith Systemd Timers
# backup.service
[Service]
ExecStart=/scripts/backup.sh
ExecStopPost=/usr/bin/curl -fsS https://ping.wakestack.co.uk/hb/backupWith CI/CD
# GitHub Actions
- name: Deploy
run: |
./deploy.sh
curl -fsS https://ping.wakestack.co.uk/hb/deployWith Kubernetes CronJobs
apiVersion: batch/v1
kind: CronJob
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
containers:
- name: backup
command: ["/bin/sh", "-c"]
args:
- /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupWith AWS Lambda
import urllib.request
def handler(event, context):
# Your logic
result = process_data()
# Ping heartbeat
urllib.request.urlopen("https://ping.wakestack.co.uk/hb/lambda")
return resultTroubleshooting
Heartbeat Not Received
Check:
- Is the job actually running?
- Can the job reach the internet?
- Is the URL correct?
- Is the job completing successfully?
False Alerts
Causes:
- Grace period too short
- Network issues from job environment
- Job taking longer than expected
Solutions:
- Increase grace period
- Add retry logic to ping
- Monitor job duration
Job Runs But Heartbeat Fails
# Log heartbeat attempts
/scripts/backup.sh
PING_RESULT=$(curl -fsS -w "%{http_code}" https://ping.wakestack.co.uk/hb/backup)
echo "Heartbeat result: $PING_RESULT" >> /var/log/heartbeat.logWakestack Heartbeat Monitoring
Monitor your scheduled jobs alongside uptime and servers.
Features:
- Unique heartbeat URLs per job
- Configurable schedules
- Grace periods
- Duration tracking
- Integrated with status pages
Included in:
- Free tier: 5 monitors (any type)
- Pro tier: 50 monitors
- Enterprise: Unlimited
Related Resources
Frequently Asked Questions
What is heartbeat monitoring?
Heartbeat monitoring tracks jobs that should run on a schedule. Your job pings a unique URL when it completes. If the heartbeat isn't received within the expected timeframe, you get alerted.
How is heartbeat monitoring different from uptime monitoring?
Uptime monitoring actively checks if something is up. Heartbeat monitoring passively waits for check-ins. Heartbeat is for jobs that run periodically, uptime is for always-on services.
What happens if my cron job fails to run?
With heartbeat monitoring, if your job doesn't ping the heartbeat URL within its schedule, you get alerted. This catches both crashed jobs and jobs that never started.
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 moreUptime Monitoring: The Complete Guide for 2026
Learn everything about uptime monitoring - what it is, why it matters, how to set it up, and which tools to use. A comprehensive guide for DevOps teams and developers.
Read moreBest Uptime Monitoring Tools in 2026: Complete Comparison
Compare the best uptime monitoring tools available in 2026. We analyze pricing, features, and use cases for Wakestack, Pingdom, UptimeRobot, Better Stack, and more.
Read moreReady to monitor your uptime?
Start monitoring your websites, APIs, and services in minutes. Free forever for small projects.