Back to Blog
Guides
heartbeat monitoring
cron monitoring

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.

WT

Wakestack Team

Engineering Team

6 min read

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:

  1. You create a heartbeat URL with an expected schedule
  2. Your job pings that URL when it completes
  3. 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) MonitoringPassive (Heartbeat) Monitoring
Monitor sends requestsJob sends check-in
For always-on servicesFor scheduled jobs
"Is it responding?""Did it run?"
HTTP, TCP, PingHTTP ping from job

When You Need Heartbeat Monitoring

Cron Jobs

Any scheduled task:

# Backup database every night
0 2 * * * /scripts/backup.sh

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

  1. Go to Monitors → Add Monitor
  2. Select "Heartbeat" type
  3. 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/abc123xyz

Python:

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 fail

Good:

/scripts/backup.sh                          # Job runs
if [ $? -eq 0 ]; then
  curl https://ping.wakestack.co.uk/hb/abc123  # Ping only on success
fi

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

5. 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 + Slack

Scenario 2: Hourly Data Sync

Job: Sync data from external API
Schedule: Every hour
Expected duration: 5 minutes
Grace period: 15 minutes
Alert: Slack

Scenario 3: Weekly Reports

Job: Generate weekly analytics
Schedule: Sunday at midnight
Expected duration: 2 hours
Grace period: 3 hours
Alert: Email

Scenario 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 CaseMonitoring Type
Web server upUptime (HTTP)
Database accessibleUptime (TCP)
Cron job ranHeartbeat
Background worker aliveHeartbeat
SSL certificate validSSL monitoring
Server healthyServer agent

Integration Examples

With Cron

# /etc/crontab
0 2 * * * root /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup

With Systemd Timers

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

With CI/CD

# GitHub Actions
- name: Deploy
  run: |
    ./deploy.sh
    curl -fsS https://ping.wakestack.co.uk/hb/deploy

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

With 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 result

Troubleshooting

Heartbeat Not Received

Check:

  1. Is the job actually running?
  2. Can the job reach the internet?
  3. Is the URL correct?
  4. 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.log

Wakestack 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

Set Up Heartbeat Monitoring →

About the Author

WT

Wakestack Team

Engineering Team

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

Ready to monitor your uptime?

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