Monitoring glossary

Heartbeat

Also called: heartbeat monitoring, heartbeat check, heartbeat signal

Definition

A heartbeat is a small signal that a running process sends at a regular interval to say it is still alive and doing its work. Heartbeat monitoring watches for those signals and raises an alert when one is overdue. It suits processes that run all the time, like queue workers, polling loops and sync daemons, where there is no single run that starts and ends.

How heartbeat monitoring works

You pick an interval that matches how often the process does its work, for example every 5 minutes. Inside the work loop, after each healthy pass, the process sends a heartbeat, usually an HTTP request to a monitoring service. The monitor keeps track of when the next one is due. If an interval plus a grace period passes without a heartbeat, it raises an alert.

A heartbeat is a kind of dead man's switch: the alert is caused by silence, not by an error message. That is what lets it catch a worker that is still running but stuck, such as a consumer waiting forever on a lock, or a loop that swallows every exception and tries again.

Heartbeat or uptime check?

An uptime check works from the outside: a monitor requests your health endpoint and expects a good answer. A heartbeat works from the inside: the process reports in on its own. A worker can pass a health check, with the process up and the port answering, while doing no useful work. A heartbeat sent from inside the work loop only arrives when the work actually happens. Many teams use both.

Other meanings

In clusters and networks, a heartbeat is a message that machines send each other to find out when a peer has failed, for example between database replicas or between the two nodes of a high-availability pair. The idea is the same, a missing heartbeat means trouble, but sender and receiver are parts of one system rather than a job and an outside monitor.

Example

A worker loop that sends a heartbeat

import time
import requests

PING = "https://api.drumbeats.io/v1/ping/<monitor-id>"

def heartbeat():
    try:
        requests.get(f"{PING}/success", timeout=5)
    except requests.RequestException:
        pass  # a lost heartbeat must not stop the worker

while True:
    process_next_batch()
    heartbeat()
    time.sleep(300)  # about every 5 minutes

The heartbeat is sent after the batch, not before it, so it means 'a batch was processed', not just 'the process is up'. If process_next_batch() hangs or the process dies, the heartbeats stop and the monitor raises an alert once the interval and the grace period have passed. A heartbeat request that fails is caught, so a network problem never stops the worker itself.

Common mistakes

  • Beating from a separate thread or timer. A background timer keeps sending heartbeats while the main loop is stuck. Send the heartbeat from the code that does the work.
  • An interval with no headroom. A loop that sleeps 5 minutes and then works for 20 seconds really repeats every 5 minutes and 20 seconds. Set the interval to the real cadence, or leave room for the difference in the grace period.
  • One heartbeat per item. Sending a heartbeat for every message in a busy queue adds thousands of requests and no information. One per batch or per pass of the loop is enough.
  • Replicas that hide each other. Several replicas sending to one monitor is fine when any healthy replica means the service is healthy. If you need to know which replica stopped, give each one its own monitor.

How Drumbeats handles it

In Drumbeats this is a heartbeat monitor. You set how often the process repeats, down to 1 minute on the free plan and 30 seconds on paid plans, and a grace period. Your loop sends a success ping on each pass. If no ping arrives within the interval plus the grace period, Drumbeats opens a Missed check-in incident and alerts your channels. The next success ping resolves it and sends a recovery message.

By default the first missed heartbeat alerts. For a process that may skip a beat now and then, raise the Missed check-ins setting so it takes several in a row.

All glossary terms

Monitoring for scheduled work

Hear about the run that did not happen.

Your job pings Drumbeats when it finishes. If the ping does not arrive on time, you get an alert. No agent to install, free for up to 50 monitors.

Free for up to 50 monitors · Setup in 60 seconds · No credit card required