Heartbeat Monitoring

Monitor the execution of your jobs, scripts, and scheduled tasks in real-time

Heartbeat monitoring, also known as dead man's switch or liveness ping, represents a fundamental approach to monitoring critical processes. Unlike traditional HTTP monitoring that actively checks if a server responds, heartbeat takes an inverse approach: it passively waits for a regular signal from your applications and only alerts when that signal is absent.

This technique is particularly powerful for detecting silent failures—situations where a process stops working without generating any visible error. A cron job that no longer starts, a backup script that crashes before writing its logs, a worker that silently dies: all these situations go unnoticed with classic monitoring but are immediately detected by heartbeat.

MoniTao provides a complete and easy-to-integrate heartbeat monitoring solution. By adding a single line of code to your existing scripts, you benefit from 24/7 surveillance with instant alerts via email, SMS, or webhook as soon as a job misses its expected check-in.

What is Heartbeat Monitoring?

Heartbeat monitoring is based on a simple but highly effective principle: your application periodically sends a liveness signal, and the absence of this signal triggers an alert. This approach has several distinctive characteristics.

  • Passive surveillance: Unlike active checks that query your servers, heartbeat passively waits for a signal from your code. It's your application that proves it's alive, not an external agent checking.
  • Absence detection: The system monitors not errors that occur, but events that should have occurred and didn't. This inversion of logic enables detection of silent failures.
  • Flexible intervals: You freely configure the expected interval between each ping: every minute for a critical job, once daily for a backup, once weekly for a maintenance task.
  • Grace period: A configurable tolerance period prevents false alerts from minor delays. The job is only considered failed after exceeding this safety margin.

Heartbeat Monitoring Use Cases

Heartbeat is the ideal solution for monitoring any process that runs on a recurring, automated basis, where absence of execution is as critical as an explicit error.

  • Cron jobs and scheduled tasks: Cron tasks are the classic heartbeat use case. A cron can fail silently for many reasons: deleted crontab, stopped crond service, PATH error. Without heartbeat, these failures go unnoticed.
  • Backup scripts: Backups are critical but often run at night without supervision. A heartbeat ensures your daily, weekly, or monthly backup actually executed, protecting your data.
  • Data imports and exports: ETL processes, database synchronizations, and file exchanges between systems must run regularly. Heartbeat verifies these vital data flows are working.
  • Workers and queues: Background workers processing jobs can die silently (OOM killer, crash, server restart). A periodic heartbeat confirms your workers are active.

How Heartbeat Monitoring Works

MoniTao heartbeat integration follows a simple four-step process, designed to minimize implementation effort while maximizing monitoring coverage.

  1. Create the heartbeat: In the MoniTao interface, create a new heartbeat job. Give it a descriptive name (e.g., "Daily DB Backup") and configure the expected interval and grace period.
  2. Integrate into your code: MoniTao provides a unique ping URL. Add an HTTP call to this URL at the end of your script. In bash: curl -s URL, in PHP: file_get_contents(URL), in Python: requests.get(URL).
  3. Automatic surveillance: On each successful execution, your script sends its ping. MoniTao records the timestamp and resets the counter. As long as pings arrive on time, status remains "Healthy".
  4. Alert on absence: If the ping doesn't arrive within the configured delay (interval + grace), MoniTao immediately triggers an alert via your preferred channels: email, SMS, webhook, Slack.

Heartbeat Integration Examples

Here are concrete examples of MoniTao heartbeat integration in different contexts. The goal is to add the ping only on success.

# Bash - At the end of a cron script
#!/bin/bash
set -e  # Stop on error

# Your business logic here
./backup.sh
rsync -av /data/ /backup/

# Ping MoniTao only on success
curl -fsS "https://monitao.com/ping/YOUR_TOKEN" > /dev/null

# PHP - In a processing script
try {
    // Your business logic
    $result = processData();

    // Ping MoniTao on success
    file_get_contents("https://monitao.com/ping/YOUR_TOKEN");
} catch (Exception $e) {
    // No ping = automatic alert
    log_error($e);
}

The crucial point is that the ping should only be sent on success. If your script fails before the ping, the absence of signal will automatically trigger the alert. This is the fundamental principle of the dead man's switch.

Benefits of Heartbeat Monitoring

Heartbeat offers unique advantages that classic monitoring cannot provide, especially for monitoring batch processes and scheduled tasks.

  • Silent failure detection: Heartbeat is the only way to detect processes that stop working without generating an error. A cron that no longer starts, a script that crashes at initialization, a service not restarted after reboot.
  • Minimal integration: A single line of code is enough. No agent needed, no complex SDK, no infrastructure changes. A simple HTTP call at the end of your existing scripts.
  • History and metrics: MoniTao records each ping with its timestamp and optionally the execution duration. You can analyze trends, detect slowing jobs, and prove proper operation.
  • Multi-channel alerts: Receive alerts via your preferred channel: email, SMS, webhook to Slack/Discord/Teams, or integration with your on-call system (PagerDuty, OpsGenie).

Heartbeat Getting Started Checklist

  • List all critical processes: crons, backups, imports, workers
  • Define the expected interval for each job (daily, hourly, etc.)
  • Create the corresponding heartbeats in MoniTao
  • Add ping calls at the end of each script
  • Configure alert channels (email, SMS, webhook)
  • Test with a manual execution and verify ping reception

Heartbeat Frequently Asked Questions

What's the difference between HTTP and heartbeat monitoring?

HTTP monitoring actively and periodically checks if your server responds to a request. Heartbeat works in reverse: your application sends a liveness signal, and the absence of this signal triggers the alert. HTTP is ideal for websites, heartbeat for batch processes.

How do I integrate heartbeat in an existing script?

Simply add an HTTP call to the MoniTao ping URL at the end of your script. In bash: curl -fsS "URL" > /dev/null. In PHP: file_get_contents("URL"). In Python: requests.get("URL"). The key is that this ping should be the last instruction executed after success.

What happens if my script crashes before the ping?

That's exactly the purpose of heartbeat. If your script fails before reaching the ping line, no signal is sent. MoniTao waits for the ping, notes its absence after the configured delay, and triggers the alert. That's the dead man's switch principle.

Can I measure my jobs' execution duration?

Yes, MoniTao offers start and complete endpoints. Call /start at the beginning of your job and /complete at the end. MoniTao automatically calculates the duration and can alert if a job exceeds a configured maximum duration.

How do I avoid false alerts from minor delays?

Configure an appropriate grace period. If your cron is supposed to run every hour, set an interval of 1h and a grace of 10-15 minutes. This way, a minor delay won't trigger an alert, but a real failure will be detected.

Does heartbeat work with Docker containers and Kubernetes?

Absolutely. Heartbeat is particularly useful in containerized environments where pods can be evicted, restarted, or dynamically scaled. Add the ping to your Kubernetes CronJobs or to scripts executed by containers.

Conclusion: Secure Your Critical Processes

Heartbeat monitoring is an essential complement to traditional monitoring. While HTTP monitoring and classic alert systems excel at detecting errors that occur, only heartbeat can detect actions that should have occurred but didn't. For any critical process that runs on a recurring basis—crons, backups, imports, synchronizations—heartbeat represents the last line of defense against silent failures.

MoniTao makes heartbeat implementation trivial: create a job in a few clicks, add one line of code to your scripts, and sleep easy knowing you'll be alerted if something doesn't run. Start protecting your critical processes with MoniTao heartbeat monitoring now.

Ready to Sleep Soundly?

Start free, no credit card required.