A reasonable Prometheus install is half the work — the other half is teaching Alertmanager to send the right alert to the right place, group related alerts into one notification, and suppress the warnings that are downstream of a critical event. Without that, your on-call gets paged for the same root cause three different ways at three different times. This article shows a complete alertmanager.yml that routes, groups, and inhibits, plus the amtool commands used to verify it.
How to verify
Static checks first, runtime second.
amtool check-config /etc/alertmanager/alertmanager.yml
curl -fsS http://127.0.0.1:9093/api/v2/status | jq '{config: .config.original, version: .versionInfo.version}'
amtool config routes show --config.file=/etc/alertmanager/alertmanager.yml
amtool config routes test --config.file=/etc/alertmanager/alertmanager.yml \
severity=critical team=web alertname=HighErrorRate
amtool alert query --alertmanager.url=http://127.0.0.1:9093
routes test returns the receiver(s) a hypothetical alert with those labels would land in. If it returns the catch-all when you expected a team-specific receiver, your route tree is wrong; fix it before the next real alert.
What’s happening
Alertmanager is the dispatch layer between Prometheus and your humans. It takes alerts pushed from Prometheus (or any other source that speaks the alert API), runs them through a route tree, groups them into a single notification per group, and fires that notification at one or more receivers (Slack, PagerDuty, OpsGenie, generic webhook). Four mechanisms shape what eventually leaves the system:
- Routing matches alerts to a receiver based on labels. The tree is depth-first; the first matching route wins, unless
continue: trueis set. - Grouping collapses alerts that share the labels in
group_byinto a single notification. Settinggroup_by: ['alertname']is too coarse;['alertname','service','env']lets a single host going down emit a single notification per service-env pair. - Inhibition suppresses alerts that match a target while a source alert is firing. Classic use: when the cluster is
Down, do not also pageHighLatency. - Silences are time-bounded suppressions, usually created via the UI or
amtoolduring maintenance windows.
The procedure
-
Lay out the routing tree. A two-level tree — team at the top, severity inside — keeps it readable.
# /etc/alertmanager/alertmanager.yml global: resolve_timeout: 5m slack_api_url_file: /etc/alertmanager/slack_webhook route: receiver: 'default-slack' group_by: ['alertname', 'service', 'env'] group_wait: 30s group_interval: 5m repeat_interval: 4h routes: - matchers: - team = web receiver: 'web-slack' routes: - matchers: - severity = critical receiver: 'web-pagerduty' group_wait: 10s repeat_interval: 1h - matchers: - team = platform receiver: 'platform-slack' routes: - matchers: - severity = critical receiver: 'platform-pagerduty' group_wait: 10s repeat_interval: 1h - matchers: - severity = info receiver: 'info-slack' repeat_interval: 12h receivers: - name: 'default-slack' slack_configs: - channel: '#alerts-default' send_resolved: true title: '{{ template "slack.title" . }}' text: '{{ template "slack.text" . }}' - name: 'web-slack' slack_configs: - channel: '#alerts-web' send_resolved: true - name: 'platform-slack' slack_configs: - channel: '#alerts-platform' send_resolved: true - name: 'info-slack' slack_configs: - channel: '#alerts-info' send_resolved: false - name: 'web-pagerduty' pagerduty_configs: - routing_key_file: /etc/alertmanager/pd_web_routing_key send_resolved: true - name: 'platform-pagerduty' pagerduty_configs: - routing_key_file: /etc/alertmanager/pd_platform_routing_key send_resolved: true templates: - /etc/alertmanager/templates/*.tmpl inhibit_rules: - source_matchers: [ severity = critical, alertname = InstanceDown ] target_matchers: [ severity =~ "warning|info" ] equal: [ instance ] - source_matchers: [ alertname = ClusterDown ] target_matchers: [ alertname =~ "HighLatency|HighErrorRate" ] equal: [ cluster ] -
Tune the timing.
group_waitis how long Alertmanager waits before sending the first notification for a group — keep it short for critical (10s) so the first page is fast, longer for warnings (30s–1m) so co-firing alerts join the same notification.group_intervalis the gap between notifications for new alerts joining an existing group;repeat_intervalis how long before Alertmanager re-pages for the same group still firing —1hfor critical,4h+for warnings. -
Write a Slack template that includes the runbook link and a few labels. Without this, on-call sees
[FIRING:1] HighErrorRateand nothing else.# /etc/alertmanager/templates/slack.tmpl {{ define "slack.title" -}} [{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.alertname }} {{ if .CommonLabels.service }}({{ .CommonLabels.service }}){{ end }} {{- end }} {{ define "slack.text" -}} {{ range .Alerts -}} *Summary:* {{ .Annotations.summary }} *Description:* {{ .Annotations.description }} *Severity:* {{ .Labels.severity }} *Team:* {{ .Labels.team }} *Env:* {{ .Labels.env }} *Runbook:* {{ .Annotations.runbook_url }} *Graph:* {{ .GeneratorURL }} --- {{ end -}} {{- end }} -
Set up inhibit rules. Two patterns we use everywhere: instance-level critical inhibits per-instance warnings, and a cluster-level “down” inhibits the latency/error symptoms that are downstream of it. The
equalclause is what keeps the inhibition scoped — withoutequal: [instance], a single host going down silences warnings on every other host. -
Wire silences into maintenance windows. Anyone running a planned change should silence the affected alerts first.
amtool silence add \ --alertmanager.url=http://127.0.0.1:9093 \ --duration=2h --author="$USER" \ --comment="DB upgrade — INC-1234" \ 'service=postgres' 'env=prod' amtool silence query --alertmanager.url=http://127.0.0.1:9093 -
Reload and test.
curl -XPOST http://127.0.0.1:9093/-/reloadafter every config change, then post a synthetic alert viaamtool alert addand check that it lands in the receiver you expected and only there.amtool alert add --alertmanager.url=http://127.0.0.1:9093 \ alertname=DedupTest severity=warning team=web service=test env=dev \ --annotation=summary='dedup test'
Common pitfalls
- A
group_by: ['alertname']that collapses one alert across a thousand hosts into one notification line — operationally useless. inhibit_ruleswithoutequal:, which silences alerts on unrelated instances when a source fires anywhere.- Forgetting
send_resolved: true, so the channel never sees “this is over” — on-call assumes the incident continues. - Routing on a label that the alert does not actually carry (typo, label removed in a refactor); the alert falls through to the catch-all receiver and looks like noise.
- A long
repeat_intervalfor critical alerts; if the first notification is missed, the next page is four hours late.
For Alertmanager HA — three nodes with gossip mesh — see alertmanager-ha-cluster-gossip-deploy. For the rules that feed these notifications, see prometheus-alerting-rules.
Stack Harbor keeps the Alertmanager config in version control for clients on our managed operations tier — route tree reviewed during change windows, silences documented in incident tickets, templates with runbook URLs the on-call can actually open.