Automatically detect when a critical process stops working, even without visible errors
The dead man's switch is a fundamental safety concept borrowed from the industrial and railway world. In its original application, it's a device that must be actively maintained by a human operator: if the operator releases pressure (for example, in case of illness), the system automatically goes into safety mode. In computing, this principle becomes a powerful monitoring tool for detecting silent failures.
Unlike traditional monitoring that watches for errors and exceptions, the dead man's switch takes the opposite approach: it waits for a regular life signal and triggers an alert in the absence of that signal. This logic inversion allows detecting failures that leave no trace, such as a cron that no longer starts, a server that reboots without relaunching services, or a script that crashes before it can even log an error.
This technique is particularly valuable for monitoring critical processes running in the background: automatic backups, data synchronizations, billing jobs, nightly batch processes. Without a dead man's switch, these processes can fail for days or weeks before anyone notices the problem, often at the worst possible time.
The term "dead man's switch" comes directly from the railway sector where it designates a vital safety device. Understanding its origin helps better grasp its application in IT monitoring.
The dead man's switch fills a major gap in traditional monitoring. While classic systems excel at detecting errors that occur, only the dead man's switch can detect actions that should have occurred but didn't.
In modern production environments, many critical processes run automatically and silently. These processes share a common characteristic: when they fail, no one notices immediately.
In summary, the dead man's switch is not a luxury but a necessity for any critical process. It constitutes the last line of defense against invisible failures that can go unnoticed for days, weeks, or even months.
Implementing a dead man's switch relies on four key components that must work in harmony to ensure reliable detection of silent failures.
Here are concrete examples of integrating the dead man's switch in different languages and contexts. The goal is to add a simple HTTP call at the end of your existing scripts.
#!/bin/bash
# Backup script with dead man's switch
# Your backup logic
/usr/bin/mysqldump -u root mydb > /backup/db_$(date +%Y%m%d).sql
# Check success
if [ $? -eq 0 ]; then
# Ping MoniTao only if backup succeeded
curl -fsS --retry 3 --max-time 10 \
"https://ping.monitao.com/p/YOUR_TOKEN" > /dev/null
fi
This script sends the ping only if mysqldump returns a success code (0). The curl options include --retry for reliability, --max-time to avoid blocking, and -fsS for silent behavior on success.
processOrders();
$this->generateInvoices();
$this->sendNotifications();
// Ping MoniTao if everything went well
file_get_contents('https://ping.monitao.com/p/YOUR_TOKEN');
} catch (Exception $e) {
// Log the error, don't ping
Log::error($e->getMessage());
throw $e;
}
In PHP, the ping is placed at the very end of the try block, after all critical operations. If an exception is thrown, the ping is never sent and MoniTao will alert you of the failure.
The dead man's switch applies to a wide variety of situations. Here are the most common use cases with their specifics.
Backups are the quintessential use case for dead man's switch. A backup that fails silently is a time bomb: you won't discover the problem until the day you need to restore, at the worst time. Configure a heartbeat with an interval equal to your backup frequency (24h for a daily backup) plus a margin of 2-4 hours. Ping MoniTao after verifying backup integrity, not just after creation.
Billing processes often have direct financial consequences if they don't execute. A monthly billing job that fails can mean unsent invoices, uncollected payments, and cash flow problems. Use the dead man's switch to be alerted if the invoice generation job doesn't run on the scheduled date. Add metadata to the ping (number of invoices generated, total amount) for richer monitoring.
Synchronization jobs between systems (CRM to ERP, database to data warehouse, multi-region replication) are critical for data consistency. An undetected sync stop can cause data divergences that become increasingly expensive to fix over time. The dead man's switch ensures rapid detection of any sync stoppage.
Beyond batch jobs, you can use the dead man's switch to continuously monitor your applications' health. A queue worker can ping every minute to prove it's alive and processing messages. A critical service can send a heartbeat every 5 minutes. If the application crashes or freezes, the absence of ping will alert you well before users complain.
Implementing a dead man's switch may seem simple, but several common mistakes can reduce its effectiveness or generate false alerts.
MoniTao simplifies setting up dead man's switches for all your critical processes with an intuitive interface and advanced features.
A timeout monitors that a specific operation completes within a given time. The dead man's switch is more global: it monitors the total absence of a life signal, whatever the cause. A timeout detects an operation that's too long, the dead man's switch detects an operation that never started or crashed without a trace.
The general rule is: normal frequency + 50% to 100% margin. For an hourly cron, configure an alert after 1h30 to 2h without signal. For a daily backup, a margin of 4 to 6 hours is reasonable. The goal is to avoid false alerts while quickly detecting real failures.
Three strategies: 1) Add a sufficient grace period to absorb normal duration variations. 2) Ensure your script pings even on "empty success" (no data to process). 3) Use retries on the ping HTTP call to handle temporary network issues.
Yes, by installing a lightweight agent that sends a regular ping (every 1-5 minutes). If the server goes down, reboots, or loses connectivity, the pings stop and you're alerted. It's complementary to classic HTTP monitoring which only detects web service issues.
Yes, MoniTao allows sending additional data with each ping: execution duration, number of items processed, detailed status. These metrics are stored and viewable in history, allowing detection of gradual degradations before they become critical.
A single missed ping doesn't trigger an immediate alert thanks to the grace period. However, for more robustness, configure automatic retries in your call (curl --retry 3) and a reasonable timeout. If network issues persist beyond the grace period, you'll be alerted, which is generally desirable.
The dead man's switch is an indispensable tool for any modern production environment. By inverting the logic of traditional monitoring, it detects what other systems cannot see: silent failures, processes that never start, jobs that die without leaving a trace. This unique capability makes it the last line of defense against invisible incidents.
With MoniTao, setting up a dead man's switch takes only a few minutes. Create a heartbeat, copy the ping URL, add it to the end of your script, and you're protected. No longer discover your backup problems when you need to restore. No longer let your sync jobs stop for weeks. Start today monitoring your critical processes with MoniTao.
Start free, no credit card required.