RousselTMLEARNING

Article · Prometheus: From Discovery to Expertise

Understanding recording rules

1. Why recording rules? #

Compute in advance rather than on every read.

The problem #

A PromQL query is computed when it runs. On a twenty-panel dashboard, refreshed every thirty seconds and opened by ten people, Prometheus keeps repeating the same computations on the same samples. The dashboard gets slow, and every extra user makes it worse.

A recording rule solves this: Prometheus evaluates the expression at a regular interval and writes the result to a new series. Reads become simple accesses to that series.

Cost of a query with and without a recording rule

Real measurement: on a test Prometheus 3.15, with stats=all, sum by (job) (rate(prometheus_http_requests_total[5m])) reads 448 samples, and the equivalent recorded series just one. The gap is far larger on a production server.

When to use them, and when not to #

Good ideaBad idea
Expensive, frequent query (heavily used dashboard)Query run rarely, by hand
Alert with a heavy expressionQuery already fast on few series
Shared indicator (SLI, error rate) defined only onceKeeping all original labels: nothing is reduced
Aggregates to keep for a long time or to federateReplacing exploration: the window (5m) is fixed

A rule is not free: each recorded series uses storage and memory, like a scraped series. The gain comes from aggregation: replacing thousands of series with a few dozen.

2. How Prometheus evaluates them #

Groups, interval, order and no retroactive effect.

How it works #

  • Rules live in groups, declared in files referenced by rule_files.
  • Within a group they run in order, at the same timestamp. A rule can therefore use the result of the previous one.
  • The interval is the group's (interval), otherwise the global evaluation_interval.
  • The result keeps the labels of the expression; the metric name is replaced by record.
  • A rule only computes the present: a new rule has no history, unless recomputed manually (see below).

Anatomy of a rule name and chaining of rules within a group

Mind the interval: a series with no point for more than five minutes (the default lookback) no longer appears in instant queries. A group evaluated every ten minutes therefore produces gaps.

📄 Prometheus recording rules: speeding up your queries and dashboards →

My progress

  • ⏱ Estimated time : ≈ 3 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

Alerting

The process of notifying teams (via email, Slack, Teams) when a specific event, threshold breach, or anomaly is detected.

Architecture

The overall structural design of an IT system, defining its various components, their relationships, and the principles guiding its evolution.

OpenTelemetry

An open source framework providing standards, APIs, and SDKs to collect and export observability data (traces, metrics, logs) in an agnostic way.

Recommended Articles

Prometheus best practices: metrics, cardinality, rules and operations

Prometheus best practices: metric naming, labels and cardinality, scrape intervals, recording rul...

Thanos Ruler: rules and alerts on the global view

Evaluate recording and alerting rules across all clusters with Thanos Ruler: configuration, Alert...

Measuring SLIs with Prometheus

Implement availability and latency SLIs with Prometheus: required metrics, ratio queries, histogr...

Prometheus: alerting with Alertmanager (rules, routing, silences)

Set up Prometheus alerting: alert rules, Alertmanager, routing, grouping, inhibition, silences, S...

Alerting on logs with the Loki Ruler

Set up LogQL alerts and recording rules with the Loki Ruler: configuration, rule files, Alertmana...

Mimir: ruler, Alertmanager and mimirtool

Evaluate recording and alerting rules in Mimir, configure the multi-tenant Alertmanager and autom...

Writing good Prometheus alerting rules (and testing them)

Design useful alerts: alert on symptoms, choose for and thresholds, severity and team labels, ann...

Time-based vs event-based SLO: understanding, computing and choosing (with the Qonto example)

Differences between time-based SLOs (time slices, uptime) and event-based SLOs (good events over ...

Prometheus: visualizing your metrics (UI, Grafana and dashboards)

Visualize Prometheus data: the web interface, PromQL graphs, connecting to Grafana, RED and USE d...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!