Learn Labs
Rules, Alerting & SLOs

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.

route (root)group_by alertname, jobheartbeatalertname=Watchdogpagerseverity=criticalticketsseverity=warningdefaultnothing else matchedrepeats every 1 mgroup_wait 10 s; inhibitswarnings for the same jobrepeats every 4 heach alert walks down to the first child whose matchers match

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-slack

Test 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.yml

Grouping 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.

SettingMeaningHere
group_byAlerts with equal values for these labels share a notification[alertname, job]
group_waitAfter the first alert of a new group, wait to collect siblings30s (10s for pages)
group_intervalAfter a group's notification, wait before sending updates (new alerts joined)5m
repeat_intervalRe-send a group that's still firing, unchanged4h (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>

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-key

This 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

  1. With errors still injected from the previous lesson, watch the pager receiver in docker logs demo-app.
  2. Create a silence for alertname=ErrorBudgetBurnFast for 10 minutes. Confirm the alert shows as silenced in the UI and the notifications stop.
  3. Use amtool config routes test to check where an alert with severity=warning, alertname=DiskWillFillIn4Hours goes.
  4. Add a team = "checkout" route that sends to a new checkout webhook receiver (http://demo-app:8080/webhook/checkout), with continue: true. Validate with amtool check-config, reload with curl -X POST localhost:9093/-/reload. Then docker stop demo-app and confirm TargetDown arrives at the checkout receiver. (The team label comes from targets/demo-app.json.)
  5. Now notice that ErrorBudgetBurnFast does not reach checkout. Its expression reads recording rules that aggregate sum by (job), which drops team. Fix it by changing those rules to keep team. This is the without vs by advice from Recording Rules in practice.

On this page