Alertmanager
Routing, grouping, inhibition, silences, and receivers
Prometheus decides that something is wrong. Alertmanager decides what to do about it: which team hears about it, through which channel, batched with what, how often to repeat, and when to stay quiet.
Open http://localhost:9093 to see the alerts it currently holds. The
Watchdog alert is always there.
The routing tree
The route block is a tree. Every alert enters at the root and descends
into the first child whose matchers match, recursively. If no
child matches, the current node handles it.
route:
receiver: default
group_by: [alertname, job]
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
routes:
- receiver: heartbeat
matchers: [alertname = "Watchdog"]
repeat_interval: 1m
- receiver: pager
matchers: [severity = "critical"]
group_wait: 10s
repeat_interval: 1h
- receiver: tickets
matchers: [severity = "warning"]Children inherit settings they don't override. The pager route
inherits group_by: [alertname, job] and group_interval: 5m from the
root. Add continue: true to a route to keep matching later siblings
after it matches, for example to send critical alerts both to the pager
and to a team chat channel.
In a real organisation, the first level usually routes by team (a label added by service discovery or in the rule), and the second level by severity:
routes:
- matchers: [team = "checkout"]
receiver: checkout-slack
routes:
- matchers: [severity = "critical"]
receiver: checkout-pagerduty
- matchers: [team = "data"]
receiver: data-slackTest which receiver an alert would reach without waiting for a real one:
docker exec alertmanager amtool config routes test \
--config.file=/etc/alertmanager/alertmanager.yml severity=critical alertname=Foo
# -> pager
docker exec alertmanager amtool config routes show --config.file=/etc/alertmanager/alertmanager.ymlGrouping and timing
Grouping turns an alert storm into one message. When a database dies,
30 services' error alerts fire at once. Grouped by alertname and
cluster, that's one notification listing 30 services instead of 30
pages.
| Setting | Meaning | Here |
|---|---|---|
group_by | Alerts with equal values for these labels share a notification | [alertname, job] |
group_wait | After the first alert of a new group, wait to collect siblings | 30s (10s for pages) |
group_interval | After a group's notification, wait before sending updates (new alerts joined) | 5m |
repeat_interval | Re-send a group that's still firing, unchanged | 4h (1h for pages) |
group_by: ['...'] (literally three dots) disables grouping: every
unique label set is its own group.
Inhibition
Inhibition suppresses alerts when another, more important alert is already firing:
inhibit_rules:
# if a critical alert is firing for a job, don't also send its warnings
- source_matchers: [severity = "critical"]
target_matchers: [severity = "warning"]
equal: [job]
# if Postgres itself is down, its port probe failing is noise
- source_matchers: [alertname = "PostgresDown"]
target_matchers: [alertname = "EndpointProbeFailed", instance =~ ".*:5432"]equal limits it to alerts that share those label values. Without
equal: [job], one critical alert anywhere would silence every warning
everywhere. The second rule can't use equal, because the exporter's
alert and the probe's alert share no label value, so it pins the
target to the Postgres port instead. Leave that matcher out, and
Postgres being down would also mute the ClickHouse probe alert, an easy
mistake that only shows up when two things break at once.
Silences
A silence mutes matching alerts for a fixed time window. Use one
during planned maintenance, or once someone is working on an incident so
the repeats stop. Create silences in the UI (New Silence) or with
amtool:
# silence the demo app's alerts for 2 hours
docker exec alertmanager amtool silence add \
--alertmanager.url=http://localhost:9093 \
--duration=2h --comment="load testing" --author="me" job=demo-app
docker exec alertmanager amtool silence query --alertmanager.url=http://localhost:9093
docker exec alertmanager amtool silence expire --alertmanager.url=http://localhost:9093 <id>A silence matches on labels, and matching is easy to get too broad.
severity=critical for "2 hours of maintenance" silences every
critical alert in the company. Always include something specific like
job or instance, give it the shortest duration that works, and
write a comment saying why.
Receivers
A receiver is a named list of integrations. Alertmanager supports email, Slack, PagerDuty, Opsgenie, Microsoft Teams, Telegram, Discord, SNS, webhooks, and more:
receivers:
- name: checkout-slack
slack_configs:
- api_url_file: /etc/alertmanager/secrets/slack-url
channel: "#checkout-alerts"
send_resolved: true
title: '{{ .CommonLabels.alertname }} ({{ .Alerts.Firing | len }} firing)'
text: '{{ range .Alerts }}• {{ .Annotations.summary }}\n{{ end }}'
- name: checkout-pagerduty
pagerduty_configs:
- routing_key_file: /etc/alertmanager/secrets/pd-keyThis stack uses webhooks into the demo app, which prints each alert, so you can see exactly what would have been sent without connecting real services:
docker logs -f demo-app | grep ALERT
# ALERT receiver=heartbeat status=firing alertname=Watchdog severity=none summary='Alerting pipeline heartbeat...'Use *_file variants (api_url_file, routing_key_file) to read
secrets from mounted files instead of putting them in the config.
High availability
Run two or three Alertmanagers with --cluster.peer pointing at each
other, and configure every Prometheus to send to all of them.
The peers gossip silences and notification state, so each notification
is sent once even though every instance receives every alert. Don't put
a load balancer in front: Prometheus must reach each instance directly.
Lab
- With errors still injected from the previous lesson, watch the
pagerreceiver indocker logs demo-app. - Create a silence for
alertname=ErrorBudgetBurnFastfor 10 minutes. Confirm the alert shows as silenced in the UI and the notifications stop. - Use
amtool config routes testto check where an alert withseverity=warning, alertname=DiskWillFillIn4Hoursgoes. - Add a
team = "checkout"route that sends to a newcheckoutwebhook receiver (http://demo-app:8080/webhook/checkout), withcontinue: true. Validate withamtool check-config, reload withcurl -X POST localhost:9093/-/reload. Thendocker stop demo-appand confirmTargetDownarrives at thecheckoutreceiver. (Theteamlabel comes fromtargets/demo-app.json.) - Now notice that
ErrorBudgetBurnFastdoes not reachcheckout. Its expression reads recording rules that aggregatesum by (job), which dropsteam. Fix it by changing those rules to keepteam. This is thewithoutvsbyadvice from Recording Rules in practice.