Alerting with Alertmanager
Write alert rules in Prometheus, route them to the right people with Alertmanager, group and silence the noise, and follow one real alert from a dead server to a page and back.
By the end of this lesson you'll be able to
0 of 5 completeDashboards only help when someone is looking. Alerting tells a person when something users care about is broken, and stays quiet otherwise. Prometheus decides whether something is wrong; Alertmanager decides who hears about it, how and how often. In this lesson you'll write rules, build a routing tree, and follow one real alert from a dead server to a page and back.
Alert rules
An alert rule is a PromQL expression that returns series when something is wrong. Each returned series becomes one alert. Rules live in a rules file next to your recording rules:
# rules.yml groups: - name: node rules: - alert: TargetDown expr: up == 0 # any target Prometheus can't scrape for: 1m # must stay true this long before it fires labels: severity: page # used by Alertmanager to route it annotations: summary: '{{ $labels.job }} on {{ $labels.instance }} is down' runbook_url: https://runbooks.example.com/target-down - alert: DiskWillFillIn4Hours expr: predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}[1h], 4 * 3600) < 0 for: 15m labels: severity: page annotations: summary: 'Disk {{ $labels.mountpoint }} on {{ $labels.instance }} will be full within 4 hours' - alert: HighMemoryUse expr: (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) > 0.9 for: 10m labels: severity: ticket annotations: summary: 'Memory on {{ $labels.instance }} is over 90% used'
Each part has one job:
expr: the condition. Any series it returns is "wrong right now".for: how long it must stay true. This is your main defence against noise: a 30-second spike never pages anyone.labels: added to the alert.severityis the convention routing uses.annotations: text for the human: a summary using the alert's own labels, and arunbook_urlthat says what to do (you'll write runbooks in the SLOs lesson).
Point Prometheus at Alertmanager in prometheus.yml, and check the rules:
# prometheus.yml (added) alerting: alertmanagers: - static_configs: - targets: ['alertmanager:9093']
$ docker exec prometheus promtool check rules /etc/prometheus/rules.yml Checking /etc/prometheus/rules.yml SUCCESS: 4 rules found
docker exec prometheus promtool check rules /etc/prometheus/rules.ymldockerbuild and run containersexecrun a command in a running containerprometheusthe containerpromtool check rules /etc/prometheus/rules.ymlthe command to run inside it
(The fourth rule is the recording rule from lesson 2.)
Inactive, pending, firing
An alert rule is always in one of three states:
- Inactive: the expression returns nothing. All good.
- Pending: it returns something, but not for the full
forduration yet. Nothing is sent. - Firing: it has been true for the whole
for. Prometheus sends it to Alertmanager, and keeps re-sending it while it fires.
If the condition clears while pending, the alert goes back to inactive and nobody is told. That's
exactly what for is for.
Follow one real alert
Here is a real run on the lab machine (times in UTC). Rule: TargetDown, for: 1m. Alertmanager
settings: group_wait: 30s, group_interval: 5m.
| Time | What happened |
|---|---|
| 07:00:42 | docker stop node-exporter |
| 07:00:49 | Next scrape fails: up becomes 0, alert goes pending |
| 07:01:49 | Still down after 1 minute: alert fires |
| 07:02:19 | After group_wait (30 s), Alertmanager sends the page |
| 07:03:24 | docker start node-exporter |
| 07:03:34 | Next scrape succeeds: alert resolved |
| 07:07:20 | Alertmanager sends "resolved", at the group's next group_interval |
Two things worth noticing. First, the page arrived 97 seconds after the server died: 7 s to the
next scrape, 60 s of for, 30 s of group_wait. Every alert has this built-in delay, and you
choose it. Second, "resolved" took almost 4 minutes to arrive after recovery, because
Alertmanager only sends updates for a group every group_interval. That's normal, not a bug.
The receiver was a small webhook that printed what it got. This is the real payload, shortened:
POST /page { "receiver": "on-call", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "TargetDown", "env": "lab", "instance": "node-exporter:9100", "job": "node", "severity": "page" }, "annotations": { "runbook_url": "https://runbooks.example.com/target-down", "summary": "node on node-exporter:9100 is down" }, "startsAt": "2026-11-03T07:01:49.374Z", ... } ], "notification_reason": "first notification", "groupLabels": { "alertname": "TargetDown", "job": "node" }, ... }
The summary template turned into plain English (node on node-exporter:9100 is down), the
severity: page label chose the on-call receiver, and groupLabels shows how it was grouped.
Slack, PagerDuty and email receivers get the same data, formatted for them.
Alertmanager
Alertmanager is a separate program (port 9093) that receives alerts from one or more Prometheus servers and turns them into notifications. Its config has three parts: a route tree, receivers, and inhibit_rules.
# alertmanager.yml route: receiver: default # anything no child route matches group_by: ['alertname', 'job'] group_wait: 30s # wait this long to batch the first alerts of a new group group_interval: 5m # then send updates for that group at most this often repeat_interval: 4h # re-send a still-firing alert this often routes: - matchers: ['severity="page"'] receiver: on-call - matchers: ['severity="ticket"'] receiver: team-tickets receivers: - name: default - name: on-call webhook_configs: - url: http://webhook-sink:8080/page - name: team-tickets webhook_configs: - url: http://webhook-sink:8080/ticket inhibit_rules: - source_matchers: ['alertname="TargetDown"'] target_matchers: ['severity="ticket"'] equal: ['instance']
In real life on-call would use pagerduty_configs or opsgenie_configs, and team-tickets
slack_configs or email_configs. The structure stays the same.
amtool ships in the Alertmanager image. Use it to check the file before you reload:
$ docker exec alertmanager amtool check-config /etc/alertmanager/alertmanager.yml Checking '/etc/alertmanager/alertmanager.yml' SUCCESS Found: - global config - route - 1 inhibit rules - 3 receivers - 0 templates
docker exec alertmanager amtool check-config /etc/alertmanager/alertmanager.ymldockerbuild and run containersexecrun a command in a running containeralertmanagerthe containeramtool check-config /etc/alertmanager/alertmanager.ymlthe command to run inside it
Routing, grouping and silences
The routing tree
Alerts enter at the top route and walk down. The first child whose matchers fit the alert's
labels handles it; if none match, the parent's receiver does. Print the tree, then test where a
given set of labels would go:
$ amtool config routes --config.file=/etc/alertmanager/alertmanager.yml Routing tree: . └── default-route receiver: default ├── {severity="page"} receiver: on-call └── {severity="ticket"} receiver: team-tickets $ amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml severity=page alertname=TargetDown on-call $ amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml severity=ticket alertname=HighMemoryUse team-tickets $ amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml alertname=Watchdog default
Run routes test in CI on every change to alertmanager.yml. A typo in a matcher silently sends
pages to the default receiver, and you find out during the next outage. Add continue: true to a
route when an alert should also carry on to later siblings (for example, page on-call and post
to the team channel).
Grouping
group_by: ['alertname', 'job'] means: alerts with the same alert name and job travel together.
If 40 node_exporters go down because a network switch died, on-call gets one message listing
40 instances, not 40 pages. group_wait gives the group 30 seconds to collect its members before
the first message.
Inhibition
An inhibition rule mutes some alerts while another is firing. The rule above says: while
TargetDown fires for an instance, mute every severity="ticket" alert with the same instance.
If a server is unreachable, nobody needs a separate ticket about its memory.
Silences
A silence mutes matching alerts for a fixed time, typically for planned work. You create it in the Alertmanager UI or with amtool, and it needs an author and a comment, so the next person knows why:
$ amtool silence add --alertmanager.url=http://localhost:9093 \ alertname=TargetDown instance=node-exporter:9100 \ --duration=2h --author=rajeev --comment="Planned reboot of node-exporter host" cf666dc6-711b-47c1-a657-f6409aa0ff78 $ amtool silence query --alertmanager.url=http://localhost:9093 ID Matchers Ends At Created By Comment cf666dc6-711b-47c1-a657-f6409aa0ff78 alertname="TargetDown" instance="node-exporter:9100" 2026-11-03 09:03:01 UTC rajeev Planned reboot of node-exporter host $ amtool alert query --alertmanager.url=http://localhost:9093 Alertname Starts At Summary State $ amtool alert query -s --alertmanager.url=http://localhost:9093 Alertname Starts At Summary State TargetDown 2026-11-03 07:01:49 UTC node on node-exporter:9100 is down suppressed
The plain query hides silenced alerts; -s shows them as suppressed. The alert still exists in
Prometheus, and if the silence expires while it's still firing, notifications start again. Always
set an end time: a forgotten "silence forever" is how real outages go unnoticed.
Writing alerts people trust
Every page should mean: users are affected, and a human needs to act now. Anything else is a ticket or a dashboard. A few rules that keep it that way:
- Alert on symptoms, not causes. Users feel errors and slowness, not CPU. "Checkout error rate above 2% for 10 minutes" is a page. "CPU above 80%" is a dashboard: a busy server that serves fast is fine.
- Alert on predictions for things that fill up.
predict_linear(...) < 0gives you hours of warning, at any disk size. "Disk above 90%" fires too late on a small disk and far too early on a 10 TB one. - Use
forgenerously. 5 to 15 minutes for most symptoms. If you'd fix it the same way 5 minutes later, it doesn't need to fire on the first sample. - Two severities are enough to start.
page(wake someone) andticket(handle in working hours). Each should map to one receiver. - Every alert has a runbook link and an owner. If nobody can say what to do when it fires, delete it or make it a ticket.
- Review alerts monthly. Anything that fired and nobody acted on is noise. Fix it or remove it.
One more rule many teams add: a Watchdog alert with expr: vector(1) that always fires. It goes
to a "dead man's switch" service that pages you if the Watchdog stops arriving. That's how you
find out the alerting pipeline itself is broken.
If a target disappears completely, up == 0 won't help: there's no series left to compare. For
critical jobs, add absent(up{job="checkout"}) as well, which fires when the series is missing
altogether.
Run Alertmanager as a cluster of 2 or 3 (they share silences and deduplicate), point every
Prometheus at all of them, and send pages to a real paging tool (PagerDuty, Opsgenie, Grafana
OnCall) that handles escalation and acknowledgement. Keep rules and alertmanager.yml in Git and run
promtool check rules and amtool check-config in CI.
Break a server and time the alert
With Prometheus, Alertmanager and the rules from this lesson running, stop node_exporter and write down when the alert went pending, when it fired and when the notification arrived. Then silence it, restart node_exporter and record when the resolved notification came. Explain each delay from the settings.
~/alert-timeline.txtReveal one safe solution
$ date -u +%T; docker stop node-exporter $ curl -s localhost:9090/api/v1/alerts | grep -o '"state":"[a-z]*"' # repeat until "firing" $ amtool alert query --alertmanager.url=http://localhost:9093 $ date -u +%T; docker start node-exporter
date -u +%T; docker stop node-exporterdateprint the date and time
curl -s localhost:9090/api/v1/alerts | grep -o '"state":"[a-z]*"'curlmake an HTTP request-ssilent: no progress bar|pipe: send output to the next commandgrepfind lines that match a pattern-oprint only the matching part
On the lab machine the page came 97 seconds after the stop (7 s to the next scrape, 60 s of for,
30 s of group_wait) and the resolved message about 4 minutes after recovery (the next
group_interval). Your times will differ by a few seconds. If nothing fires, check that
Prometheus found Alertmanager with curl -s localhost:9090/api/v1/alertmanagers, and look at the
Alerts page for rule errors.
Try it yourself
0 of 6 steps doneRun each task in your own account or terminal, then tick it off.
Quick check
An alert rule has for: 15m. The expression is true for 10 minutes, then false. What happens?
Official reading for this lesson
Or get every quiz answer right and it completes itself.
Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.