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

💬 Ask a question

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 : alerter avec Alertmanager (règles, routage, silences)

Mettre en place l'alerting Prometheus : règles d'alerte, Alertmanager, routage, regroupement, inh...

Grafana Alloy: Understanding and exploiting the User Interface (UI)

Discover how to enable, secure, and use Grafana Alloy's built-in web interface to visualize your ...

Les types de métriques dans Prometheus

Découvrez en détail les quatre types de métriques supportés par Prometheus (Counter, Gauge, Histo...

Prometheus sur Kubernetes et l'interface web de Prometheus

Déployer Prometheus sur Kubernetes avec kube-prometheus-stack (Prometheus Operator, ServiceMonito...

Mimir : le chemin de lecture (query-frontend, querier, store-gateway et caches)

Comment Mimir répond à une requête PromQL : découpage et cache du query-frontend, file d'attente,...

Prometheus dans le monde Kubernetes (Operator, ServiceMonitor, kube-prometheus-stack)

Superviser Kubernetes avec Prometheus : service discovery, kube-prometheus-stack, Prometheus Oper...

Grafana : maîtriser les requêtes (PromQL, LogQL, SQL et expressions)

Construire des requêtes efficaces dans Grafana : éditeur de requêtes, Query Inspector, PromQL, Lo...

Exploring data in OpenObserve: SQL, PromQL and VRL

Search with SQL, query metrics with PromQL, optimize a stream (indexes, partitions, retention) an...

Kibana avancé : data views, Lens, dashboards, alerting et reporting

Exploiter Kibana en profondeur : data views et champs runtime, Discover, Lens et formules, dashbo...

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!