Guides / n8n

Heartbeats in n8n: know when a scheduled workflow quietly stopped running

Intermediate, 8 min read,

Your error workflow tells you when a run fails. It says nothing when a run never starts. Someone unpublished the workflow, a trigger stopped firing, the server rebooted into a broken state. No run, no error, no alert. You find out weeks later, when someone asks where the report went.

A heartbeat fixes that. Every important workflow notes the time it last succeeded. A watchdog checks those times and tells you when one goes quiet. And something outside n8n watches the watchdog.

The three layers

  1. Each job writes a heartbeat at the very end of a successful run.
  2. A watchdog workflow checks every heartbeat on a schedule and alerts once when a job is late, and once when it's back.
  3. An outside check expects a ping from the watchdog. If n8n or the whole server is down, nothing inside it can alert you, so something outside has to.

1. Create the heartbeats table

Create a Data Table called heartbeats with three columns: job (string), late_after_minutes (number) and last_success (string). One row per job. Each job writes its own row, so nothing here is maintained by hand.

late_after_minutes is how long silence is fine. A job that runs every hour might use 90. A daily job might use 1560, 26 hours, so a slow morning doesn't count as late.

2. Add a heartbeat to each job

Add two nodes at the very end of every workflow you want to watch:

Your jobLast step
FilterProduction only
Data TableHeartbeat

Execute Once matters: if the last step outputs fifty items, the heartbeat would otherwise be written fifty times. And because it sits at the end, a run that crashed halfway never beats.

3. Build the watchdog

The watchdog uses the snapshot pattern from the change-only alerts guide: it works out each job's state, compares it with the last state it saved, and speaks only when a state changes. Create the snapshots table from that guide if you don't have it yet.

ScheduleEvery 15 min
Data TableGet heartbeats
Data TableGet last state
CodeCheck
HTTP RequestPost alert
CodeRows to save
Data TableSave state

Data Table: Get heartbeats

Operation Get, table heartbeats, Return All on. Add one condition that every row meets, late_after_minutes Greater Than 0. In Settings, turn on Always Output Data, so the watchdog still runs before the first job has beaten.

Data Table: Get last state

Operation Get, table snapshots, condition watch Equals heartbeats, Return All on. In Settings, turn on Always Output Data and Execute Once. Without Execute Once it runs once per heartbeat row.

Code: Check

Run Once for All Items mode:

const now = Date.now();
const ago = m => (m < 120 ? `${m} min` : `${Math.round(m / 60)} h`);

// Empty items from Always Output Data have no job / item_id.
const beats = $('Get heartbeats').all().map(i => i.json).filter(b => b.job);
const prev = new Map(
  $('Get last state').all().map(i => i.json)
    .filter(r => r.item_id)
    .map(r => [r.item_id, r.status])
);

const lines = [];
const rows = [];
for (const b of beats) {
  const last = Date.parse(b.last_success); // compare times, never date text
  const age = Math.round((now - last) / 60000);
  const status = Number.isNaN(last) || age > Number(b.late_after_minutes) ? 'late' : 'ok';
  const was = prev.get(b.job) || 'ok'; // a job that is late on day one still alerts

  if (status === 'late' && was !== 'late') {
    lines.push(`LATE: ${b.job}, last success ${Number.isNaN(last) ? 'unknown' : ago(age) + ' ago'}`);
  }
  if (status === 'ok' && was === 'late') lines.push(`Back: ${b.job} ran again`);
  rows.push({ watch: 'heartbeats', item_id: b.job, name: b.job, status });
}

return [{ json: {
  notify: lines.length > 0,
  text: `Heartbeat check:\n${lines.join('\n')}`,
  rows,
} }];

IF, Post alert, Production only, Rows to save, Save state

These are the same five nodes as in the change-only alerts guide:

So a late job alerts once, not every 15 minutes, and you get a second message when it recovers.

4. Watch the watchdog from outside

If n8n is down, the watchdog is down with it. So the last layer has to live somewhere else. Healthchecks.io does exactly this: it expects a ping on a schedule and alerts you when one doesn't arrive. The free plan covers 20 checks, and it's open source if you'd rather host it yourself, on a different machine from the one it watches.

  1. Create a check with Period 15 minutes and Grace Time 15 minutes, and set up its email or chat notification.
  2. In the watchdog, add an HTTP Request node, Ping: GET the check's ping URL, https://hc-ping.com/your-uuid.
  3. Connect Check's output to Ping as well as to the IF node. The ping then goes out on every run, whether or not there's anything to say, but only after both tables were read.

Now a stopped server, a crashed n8n or a broken watchdog each turn into an email within half an hour.

Test it

The traps

Why it's built this way