ObservabilityPrometheus
Prometheus alerting rules: alert on symptoms
An alerting rule is a PromQL expression with a waiting time, labels and annotations. The Prometheus documentation also says what to point it at: symptoms that users feel, with as few alerts as possible.

What a rule file holds
Rules live in YAML files that Prometheus loads through rule_files in its configuration. A file holds groups. Each group has a name and a list of rules, which run in sequence at a regular interval. This is the example from the Prometheus documentation:
groups:
- name: example
labels:
team: myteam
rules:
- alert: HighRequestLatency
expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
for: 10m
keep_firing_for: 5m
labels:
severity: page
annotations:
summary: High request latencyThe threshold and the two durations are the documentation's example values. Choose your own.
What each field does
alertis the name. The Prometheus best practices note that the community writes alert names in camel case.expris the PromQL expression. Every series it returns becomes one active alert with that series' labels.foris how long the expression must keep returning a series before the alert fires. Until then the alert is pending. The default is0s, and a rule with noforbecomes active on the first evaluation.keep_firing_forkeeps the alert firing for a set time after the condition was last met. The default is0s. The documentation names flapping alerts and false resolutions as what it prevents.labelsare added to the alert and overwrite conflicting labels. The example setsseverity: pageon the rule andteam: myteamon the whole group.annotationshold longer information, such as alert descriptions or runbook links. Label and annotation values accept templates such as{{ $labels.instance }}and{{ $value }}.
Symptoms before causes
The Prometheus alerting practices fit in one sentence: keep alerting simple, alert on symptoms, have good consoles for pinpointing causes, and avoid pages where there is nothing to do. The page asks for as few alerts as possible, tied to end-user pain.
For online serving systems its advice is to alert on high latency and on error rates at the highest point of the stack you can, and to page on latency at a single point in the stack. Errors further down the stack that cause a user-visible failure need no separate page.
The SRE workbook writes the error-rate symptom as two rules, for a service with a 99.9% SLO. A recording rule computes the ratio of errors to requests:
record: job:slo_errors_per_request:ratio_rate10m
expr:
sum(rate(slo_errors[10m])) by (job)
/
sum(rate(slo_requests[10m])) by (job)An alerting rule fires when that ratio reaches the 0.1% the SLO allows:
- alert: HighErrorRate
expr: job:slo_errors_per_request:ratio_rate10m{job="myjob"} >= 0.001The workbook presents this as its simplest version and names the weakness: low precision. A 0.1% error rate for 10 minutes fires the alert while consuming only 0.02% of the monthly error budget. Its later versions alert on burn rate.
Rule checks with promtool
promtool check rules /path/to/example.rules.yml
promtool test rules test.ymlThe first command checks syntax with no running server. It prints the parsed rules and exits with 0, or prints the error and exits with 1. The second runs unit tests: you supply input series and the alerts you expect at a given evaluation time. promtool is part of the Prometheus archive.
Run both in CI. Prometheus applies a reload only if all rule files are well formatted.
Routing, grouping and inhibition
The Prometheus documentation says that alerting rules work out what is broken right now, and that another layer adds summarization, notification rate limiting, silencing and alert dependencies. That layer is Alertmanager. This excerpt comes from the example configuration in the Alertmanager repository, with the comments, the other routes and the other sections left out:
route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 5m
repeat_interval: 3h
receiver: team-X-mails
routes:
- matchers:
- service=~"foo1|foo2|baz"
receiver: team-X-mails
routes:
- matchers:
- severity="critical"
receiver: team-X-pager
inhibit_rules:
- source_matchers: [severity="critical"]
target_matchers: [severity="warning"]
equal: [alertname, cluster, service]- Routing. Every alert enters at the top-level route, which must match all alerts. It then goes down the child routes and stops at the first match, unless that route sets
continue. Here alerts for three services go toteam-X-mails, and the critical ones among them go toteam-X-pager. - Grouping.
group_bylists the labels by which alerts are batched into one notification.group_waitis the wait before the first notification for a new group, 30s by default.group_intervalis the wait before further notifications for that group, 5m by default.repeat_intervalis the wait before a notification is repeated, 4h by default. - Inhibition. A rule mutes target alerts while a source alert exists, when both carry the same values for the labels in
equal. The example mutes warning-level notifications if the same alert is already critical.
The label values, receiver names and timings are the example file's. Set your own.
A runbook link in the annotations
The default rules of the kube-prometheus-stack chart carry their runbook link in an annotation called runbook_url. This is one of them, as helm template renders it:
alert: KubeSchedulerDown
annotations:
description: KubeScheduler has disappeared from Prometheus target discovery.
runbook_url: https://runbooks.prometheus-operator.dev/runbooks/kubernetes/kubeschedulerdown
summary: Target disappeared from Prometheus target discovery.
expr: absent(up{job="kube-scheduler"})
for: 15m
labels:
severity: criticalUse the same annotation name in your own rules. The Prometheus documentation lists runbook links among the things annotations are for.
What to check in review
- The expression describes a symptom. The Prometheus practices ask for alerts on end-user pain.
forleaves slack. The same page says to allow for it, to accommodate small blips.- The labels are the ones your Alertmanager routes match on.
- The annotations include a summary and a
runbook_url. promtool check rulesand the unit tests pass.- After deploy, the rule shows on the Alerts tab of the Prometheus UI. The
ALERTSseries records when it is pending or firing.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Alert fatigue: page a person only when a person is needed
Observability · 4 min read
What may page, what becomes a ticket, and how to group, mute and review the rest.

The four golden signals: what to measure first
Observability · 4 min read
Latency, traffic, errors and saturation, with a PromQL query for each and a first dashboard.

Structured logging: logs a machine can query
Observability · 4 min read
The fields a log line needs, what to leave out, and how Loki queries the result.