Alerting: Alertmanager, SLOs and Burn Rates
An alerting rule is a PromQL expression evaluated on a schedule by Prometheus; every series the expression returns becomes one alert (an instance of the rule, identified by its label set). Prometheus does not send emails or pages. It pushes active alerts over HTTP to an Alertmanager (AM), a separate service whose only job is to deduplicate, group, route, silence and deliver notifications. Splitting the two is deliberate: rule evaluation must stay cheap and local to the data, while notification needs cluster-wide coordination (one page, not five).
Alerting Rules in Prometheus
rules/api.yml
groups:
- name: api
interval: 30s # evaluation interval for this group (default: global evaluation_interval)
rules:
- alert: HighErrorRatio
expr: |
sum by (job) (rate(http_requests_total{code=~"5.."}[5m]))
/ sum by (job) (rate(http_requests_total[5m])) > 0.05
for: 10m # must be true on every evaluation for 10m before it fires
keep_firing_for: 5m # stay firing 5m after the condition clears (anti-flap)
labels:
severity: page # labels are what the ROUTING TREE matches on
team: payments
annotations: # annotations are for humans: never used for routing
summary: "{{ $labels.job }}: {{ $value | humanizePercentage }} of requests failing"
runbook_url: "https://runbooks.example.com/api/high-error-ratio"
dashboard: "https://grafana.example.com/d/api?var-job={{ $labels.job }}"expr | Any PromQL. One alert per returned series; the series' labels (minus __name__) become the alert's labels. No series returned = nothing active. |
|---|---|
for | How long the expression must be continuously non-empty. Without it the alert is firing on the first evaluation that matches. |
keep_firing_for | Hold-down after recovery (added in Prometheus 2.42). for delays the start; this delays the end. Together they damp flapping. |
labels / annotations | Both are Go-templated: $labels, $externalLabels, $value. Labels identify and route; annotations only describe. A label that contains $value would create a new alert on every change, so never put values in labels. |
Alert States
Each alert instance is in one of three states. Inactive: the expression returns no series for it. Pending: it has appeared but has not yet been true for the whole for duration. Firing: it has, so Prometheus sends it to Alertmanager. If the expression goes empty while pending, the alert silently returns to inactive and the for clock is lost. With keep_firing_for, a recovering alert stays firing until the hold-down elapses.
Prometheus records every active alert as a synthetic series ALERTS{alertname="HighErrorRatio", alertstate="pending|firing", ...} = 1, so you can graph and query alert history. It also writes ALERTS_FOR_STATE, which holds the time the alert became active, so that after a restart Prometheus can restore pending timers instead of restarting every for countdown.
Firing alerts are not sent once. Prometheus re-sends each firing alert to Alertmanager about every minute (--rules.alert.resend-delay, default 1m) with an endsAt a few evaluation intervals in the future. If Prometheus dies, alerts therefore expire in Alertmanager on their own instead of firing forever. Resolution is an explicit update with endsAt in the past.
The Alertmanager Pipeline
Alertmanager has two phases. On ingest, an alert is stored (keyed by its label set, which is the dedup identity: repeats just refresh the existing alert), matched against the routing tree, and inserted into an aggregation group. On flush, when a group's timer fires, the group's current alerts go through the notification pipeline: inhibit, silence, then dedup against the notification log, then the integration call with retries. This ordering matters: grouping is decided before suppression, and suppression is evaluated on every flush, not once.
Grouping and the Three Timers
group_by lists the labels whose values define a group; alerts with identical values for those labels share a group and therefore share one notification. group_by: ['alertname','cluster'] turns 200 pods failing the same alert in one cluster into one page listing 200 pods. The special group_by: ['...'] disables grouping (one group per alert), and an empty list puts everything in one group.
route:
receiver: slack-default
group_by: ['alertname', 'cluster']
group_wait: 30s # default 30s: wait before the FIRST notification of a new group
group_interval: 5m # default 5m: minimum gap before notifying about CHANGES to the group
repeat_interval: 4h # default 4h: re-send an UNCHANGED, still-firing group- t = 0:00. Alert A1 (
HighLatency, cluster=eu) arrives; no group exists, so one is created and itsgroup_waittimer starts. Nothing is sent yet. - t = 0:30.
group_waitexpires and the first flush sends [A1]. This wait exists so that sibling alerts firing within seconds of each other (the common case in an outage) land in one notification instead of three. - t = 2:00. A2 (same group) arrives. The group already notified, so A2 waits for the next
group_intervalflush. No page. - t = 5:30. Flush every
group_intervalafter the first. The group changed, so it sends [A1, A2]. - t = 10:30, 15:30, .... Flushes find nothing new and the notification log says this exact set was already sent, so dedup drops them. Only when
repeat_interval(4 h) has passed since the last send does the same set go out again, on the first flush after that point. - A1 resolves. The group changed, so the next flush notifies (with
send_resolved: trueon the receiver, the message carries the resolved alert). When all alerts resolve, the group is deleted.
The Routing Tree
Routes form a tree. The root route has no matchers and is the default receiver. An alert descends into children whose matchers (label comparisons such as severity="page", team=~"pay.*") match it; the first matching child wins and the search stops, unless that child sets continue: true, in which case Alertmanager keeps evaluating later siblings too. Children inherit group_by and the timers from their parent unless they override them.
route:
receiver: slack-default # fallthrough if nothing matches
group_by: ['alertname', 'cluster']
routes:
- matchers: ['alertname="Watchdog"'] # the always-firing "is alerting alive?" alert
receiver: heartbeat
repeat_interval: 1m
- matchers: ['severity="page"']
receiver: pagerduty
continue: true # ALSO copy pages to the team channel below
- matchers: ['team="payments"']
receiver: slack-payments
group_by: ['alertname', 'service']
- matchers: ['severity="ticket"']
receiver: jira-webhook
group_wait: 5m # tickets can wait, batch them
receivers:
- name: pagerduty
pagerduty_configs: [{routing_key_file: /etc/am/pd-key, send_resolved: true}]
- name: slack-payments
slack_configs: [{channel: '#payments-alerts', api_url_file: /etc/am/slack-url, send_resolved: true}]
- name: jira-webhook
webhook_configs: [{url: 'http://jira-bridge.internal/alerts'}]
- name: heartbeat
webhook_configs: [{url: 'https://hc.example.com/ping/abc'}]
- name: slack-default
slack_configs: [{channel: '#alerts-misc', api_url_file: /etc/am/slack-url}]Inhibition, Silences, and Muting
An inhibition rule suppresses target alerts while a source alert is firing, when the labels named in equal agree. It encodes causal knowledge once: "if the whole cluster is unreachable, don't also page for every service in it."
inhibit_rules:
- source_matchers: ['alertname="ClusterDown"']
target_matchers: ['severity=~"page|warning"']
equal: ['cluster'] # only inhibit alerts from the SAME clusterA silence is a temporary, human-created mute: a set of matchers plus start and end times plus a comment, created in the UI, with amtool silence add, or by the API. Silences mute notifications, not evaluation: the alert is still firing and visible in the AM UI. Time intervals (time_intervals with mute_time_intervals or active_time_intervals on a route) are the recurring variant, for example "no ticket noise on weekends."
Receivers
A receiver is a named list of integrations: pagerduty_configs, slack_configs, webhook_configs (an HTTP POST of a JSON payload with the alert group, the escape hatch for anything unsupported), email_configs, plus Opsgenie, VictorOps, Teams, Telegram and others. One receiver can contain several integrations, so one route can notify PagerDuty and Slack. The notification text is a Go template over the group's alerts; keep PagerDuty's dedup key stable so repeated notifications update one incident.
High-Availability Alertmanager
Run 2 to 3 Alertmanagers as a cluster, each started with --cluster.peer= addresses of the others. They use HashiCorp memberlist (a gossip protocol) to replicate two things: the silences and the notification log (which group was last sent to which receiver, and when). They do not replicate alerts.
That is why every Prometheus must send every alert to every Alertmanager replica, listed individually under alerting.alertmanagers, not behind a load balancer. Each replica independently builds the same groups and reaches the flush at about the same time. Replica 2 waits a short peer-position-based delay, checks the gossiped notification log, sees that replica 1 already sent, and skips. If replica 1 is dead, replica 2 sends. The design chooses "at least once" delivery: a network partition between replicas can produce duplicate pages, never a missing one.
Grafana-Managed Alerting
Grafana Alerting is the alternative where the rules live in Grafana. Grafana evaluates a rule's queries against any data source (Prometheus, Loki, SQL, ...), supports multi-dimensional alerts like Prometheus, and ships an embedded Alertmanager with the same concepts under different names: contact points (receivers) and a notification policy tree (routes, with the same matching and nesting and group_by timers) plus mute timings. Trade-off: it is easy to use and can alert on non-Prometheus data, but rules stored in Grafana's database are not naturally reviewed in git unless you provision them, and evaluation depends on Grafana being up. Many teams keep infrastructure and SLO alerts as Prometheus or Mimir ruler rules (for/GitOps) and use Grafana alerting where the data source has no ruler. Both can use the same external Alertmanager.
What to Alert On
- Page on symptoms, not causes. A symptom is what a user or caller experiences: errors, latency, data staleness. CPU at 95% is a cause that may or may not hurt anyone; page on the symptom and use causes as dashboard clues or tickets.
- Every page must be actionable and urgent. If the right response is "wait and see" or "nothing", it should not page. Alert fatigue is a reliability risk: people stop reading pages and eventually miss the real one.
- Every alert carries a runbook link and a dashboard link in annotations, and the summary says what is broken for whom, not which metric crossed.
- Prefer few, broad, symptom-based alerts; use severity (
pagevsticket) as a routing label, so the tree, not the rule, decides the channel. - Run a Watchdog alert (
expr: vector(1), always firing) routed to an external heartbeat service: when the heartbeat stops, the alerting pipeline itself is dead.
SLO-Based Alerting: Error Budget and Burn Rate
The error budget is 1 − SLO, the amount of unreliability you are allowed over the SLO window (defined fully in the RED, USE and SLOs part). For a 99.9% SLO over 30 days it is 0.1% of requests, or 43.2 minutes of total outage. The burn rate is how fast you are spending it, relative to spending it exactly evenly over the window:
burn rate = observed error ratio / (1 − SLO) · budget consumed = burn rate × alert window / SLO period
A burn rate of 1 uses exactly 100% of the budget by the end of the window. At 99.9%, a 0.1% error ratio is burn rate 1, 1% is burn rate 10, and a total outage (100% errors) is burn rate 1000. At burn rate 14.4 a 30-day budget lasts 30 / 14.4 ≈ 2.08 days; at 6, five days; at 1, thirty.
Why a simple threshold is bad
The Google SRE Workbook (chapter 5, "Alerting on SLOs") walks through the attempts. error_ratio_5m > 0.1%: fires on a blip that costs a negligible fraction of the budget (low precision, high noise). A long window like 30 days: precise but detection takes forever and the alert stays red long after the fix. Adding for: 1h to a high threshold: still misses a slow burn that would exhaust the budget, and a short outage resets the clock. The goal is high precision (page only for real budget loss), good recall (catch every budget-threatening event), fast detection, and fast reset.
Multiwindow, multi-burn-rate alerts
The workbook's recommendation for a 99.9% SLO over 30 days:
| Severity | Burn rate | Long window | Short window | Budget consumed when it fires |
|---|---|---|---|---|
| page | 14.4 | 1 h | 5 m | 2% |
| page | 6 | 6 h | 30 m | 5% |
| ticket | 1 | 3 d | 6 h | 10% |
The budget column is derived: 14.4 × 1 h / 720 h = 2%, 6 × 6 / 720 = 5%, 1 × 72 / 720 = 10%. Each alert requires both windows to exceed the threshold. The long window establishes that enough budget really burned; the short window, one-twelfth of the long one, makes sure it is still burning now, so the alert resets within minutes of a fix instead of an hour later. Fast burns page; the slow 1× burn, which would eat the entire budget unnoticed over a month, only opens a ticket.
Detection time follows from the same arithmetic. In a total outage, the 1 h window reaches a 14.4 × 0.1% = 1.44% error ratio after 0.0144 × 60 min ≈ 52 seconds, so a full outage pages in about a minute; a 1% error ratio (burn 10) takes longer and pages via the 6× alert.
slo-rules.yml: recording rules, then the alert
groups:
- name: slo-api-recording
rules:
- record: job:slo_errors_per_request:ratio_rate5m
expr: sum by (job) (rate(http_requests_total{code=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m]))
# ... identical rules for 30m, 1h, 6h, 3d (name the window in the record name)
- name: slo-api-alerts
rules:
- alert: ErrorBudgetFastBurn
expr: |
(
job:slo_errors_per_request:ratio_rate1h > (14.4 * 0.001)
and
job:slo_errors_per_request:ratio_rate5m > (14.4 * 0.001)
)
or
(
job:slo_errors_per_request:ratio_rate6h > (6 * 0.001)
and
job:slo_errors_per_request:ratio_rate30m > (6 * 0.001)
)
labels: {severity: page}
annotations: {runbook_url: "https://runbooks.example.com/slo-burn"}
- alert: ErrorBudgetSlowBurn
expr: |
job:slo_errors_per_request:ratio_rate3d > (1 * 0.001)
and
job:slo_errors_per_request:ratio_rate6h > (1 * 0.001)
labels: {severity: ticket}The recording rules matter: evaluating a 3-day rate() over raw data on every evaluation is expensive, so you compute the ratio once per window and let the alert read the pre-aggregated series. Notice that no for: is needed; the short window already provides the "still happening" guard.
Traps
The Invariants
- Guarantees: One notification per group per flush across an AM cluster in normal operation; at-least-once delivery (partitions duplicate rather than drop); a stalled Prometheus's alerts expire on their own via
endsAt; both-window burn-rate alerts reset within about one short window of recovery. - Does not guarantee: An alert for an expression that returns nothing (absent data is silent); exactly-once pages; that a route you wrote is reachable (first match wins); that a receiver's endpoint was up (retries are bounded); that a Prometheus down cannot hide a problem, hence the Watchdog.