Back to Blog
Guides
heartbeat monitoring
cron job monitoring

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.

WT

Wakestack Team

Engineering Team

5 min read

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:

  1. Create a heartbeat monitor with expected schedule
  2. Get a unique URL (e.g., ping.wakestack.co.uk/hb/abc123)
  3. Add ping to end of your job on success
  4. Monitor expects ping within schedule + grace period
  5. Missing ping = alert

Heartbeat vs Uptime Monitoring

AspectHeartbeatUptime
DirectionJob pings monitorMonitor pings service
Best forScheduled tasksAlways-on services
Checks"Did it run?""Is it responding?"
Active/PassivePassive (waits)Active (requests)
ExamplesCron jobs, workersWebsites, 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/backup

If 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/sync

Catch 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/reports

Know 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:

  1. Add Monitor → Select "Heartbeat"
  2. Set schedule (e.g., "Every 24 hours")
  3. Set grace period (e.g., "1 hour")
  4. 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/backup

Python:

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/backup

2. Use Appropriate Grace Periods

Account for job duration variability:

Job DurationGrace Period
Under 1 min5-10 min
1-10 min15-30 min
10-60 min1-2 hours
1+ hours2-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/backup

4. 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 fail

2. 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/backup

For Systemd Timers

# backup.service
[Service]
ExecStart=/scripts/backup.sh
ExecStopPost=/usr/bin/curl -fsS https://ping.wakestack.co.uk/hb/backup

For Kubernetes CronJobs

spec:
  containers:
  - name: backup
    command: ["/bin/sh", "-c"]
    args:
      - /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup

Key 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

About the Author

WT

Wakestack Team

Engineering Team

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

Ready to monitor your uptime?

Start monitoring your websites, APIs, and services in minutes. Free forever for small projects.