Use it for heavy or frequently used queries such as SLI ratios.
Recording Rules
Recording rules precompute expensive PromQL expressions into new series at each evaluation, speeding up dashboards and alerts.
1. Validate: promtool check rules rules.yml.
2. Rule loaded: curl -s localhost:9090/api/v1/rules.
3. Evaluation errors/duration.
4. Dashboard uses recorded series.
5. Naming convention.
expression → rule group evaluation → new series → queries
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Compare recorded and raw results for a few timestamps. Watch prometheus_rule_group_last_duration_seconds.
Step 2 Common failures Narrow the fault
Changing a recording rule breaks dashboards that use the old name. Recorded series have no history before the rule was added. Very many rules increase load and series count.
Name as level:metric:operations (e.g. job:http_requests:rate5m). Validate with promtool. Rules evaluate per group interval.
promtool check rules rules.yml— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
The rule manager evaluates each group on its interval and writes results back into the TSDB. Evaluations that take longer than the interval are skipped.
ReferenceImportant terms & boundaries3 sections · depth on demand
Example
groups:
- name: http
rules:
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
- record: job:http_errors:ratio_rate5m
expr: sum by (job) (rate(http_requests_total{code=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m]))
Documented example, not captured output. Naming convention level:metric:operations. Use recording rules for dashboards and SLO alerts that query large ranges; validate with promtool check rules.
In depth
When to record
| Use a recording rule | Keep the raw query |
|---|---|
| A dashboard panel used by many people is slow | Ad-hoc investigation |
| SLO and burn-rate alerts that need long windows (30 d) | Queries that need every label |
| Federation or remote write should send aggregates, not raw series | Rarely viewed panels |
Naming convention level:metric:operations
groups:
- name: http-aggregates
interval: 30s
rules:
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
- record: job:http_request_errors:ratio_rate5m
expr: |
sum by (job) (rate(http_requests_total{code=~"5.."}[5m]))
/ sum by (job) (rate(http_requests_total[5m]))
level lists the labels kept (job), metric the source, operations what was applied, newest last. Anyone reading job:http_request_errors:ratio_rate5m knows what it contains without opening the rule file.
Rules in a group run in order
A rule can use the result of a rule above it in the same group in the same evaluation. If a group takes longer than its interval, evaluations are skipped:
prometheus_rule_group_last_duration_seconds > prometheus_rule_group_interval_seconds
rate(prometheus_rule_group_iterations_missed_total[10m]) > 0
Validate before deploying
promtool check rules rules/*.yaml
promtool test rules tests/http-aggregates_test.yaml # unit tests with input series and expected output
A recorded series starts at the time the rule is added; it has no history. Keep the raw expression on the dashboard for older ranges or backfill with promtool tsdb create-blocks-from rules.
Common mistakes
- Recording rules with high cardinality.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.