Speeding up dashboards with Prometheus recording rules

Recording rules move expensive PromQL into scheduled evaluations so dashboards read precomputed series. This page explains how to design them, keep rate and ratio results correct, and choose evaluation intervals.

On this page

Why Prometheus recording rules speed up dashboards

A Grafana panel that times out on a shared Prometheus usually runs the same heavy PromQL expression on every refresh, for every viewer. Recording rules precompute those expressions at a set interval and store the result as a new time series, so dashboards read a small, ready-made series instead of re-scanning raw samples each time. The cost moves from every dashboard load to one scheduled evaluation per rule, which is why teams reach for recording rules when a few expensive queries are repeated across many panels, alerts or users.

The trade-off is freshness and exactness. Recording rules only update on their evaluation interval, so a panel built on one shows the state as of the last evaluation, not the latest raw sample. The Prometheus overview describes the system as valuing reliability over precision, and that philosophy applies here: a precomputed result is a dependable summary of the expression, not a guarantee of the instantaneous value. Before you convert a panel, decide with the owners whether a delay of one evaluation interval is acceptable for that view, and keep alerting rules that need up-to-the-second detail on raw expressions.

Before writing rules, confirm three things in your own environment: which dashboard queries are slow (the query timings shown in Grafana and the Prometheus query log are the places to start), how often the underlying data changes, and whether the same expression already appears in other panels or alert rules. Those answers determine which rules are worth creating and how often they should evaluate. The naming and aggregation patterns that keep those precomputed results correct are covered in the sections below.

Naming recording rules with level:metric:operations

A recording rule name tells an engineer what the series contains before they open it. The convention from Prometheus best practices splits the name into three parts, and each part answers a question a dashboard author or on-call engineer will ask.

The level component

The level part names the aggregation level and labels that remain after the rule runs, for example job or job_instance. It tells readers which labels they can still filter or group by. Illustrative: a rule that sums requests per job keeps only the job label, so the level reads job. Check that the level matches the by clause in the expression, because a mismatch makes the name misleading.

Recording rules guidance

The metric component

The metric part is the underlying metric name, such as http_requests, with the _total suffix removed when a rate or counter is aggregated. Keeping the original name makes it obvious which raw metric the series derives from. Illustrative: http_requests_total becomes http_requests in the recorded name. Review the metric name whenever the source metric is renamed by instrumentation changes.

The operations component

The operations part lists the functions applied to the metric, in the order they run, such as rate5m or sum. A reader can see that a series is already a rate or a ratio before they read the expression. Illustrative: a five-minute rate summed across instances ends in rate5m. Avoid listing operations that are not in the expression, since engineers will trust the name and misuse the series.

Avoiding collisions with raw metrics

Recorded series share a namespace with scraped metrics. Using the level:metric:operations pattern, with colons in the name, separates recorded series from raw metrics that exporters publish. Prometheus reserves colons for recording rules by convention, so a metric with a colon in its name is a signal that it was computed. Check that no exporter emits a series with the same name before you add the rule.

Keeping names consistent across rules

Consistent names let teams search, review and reuse recorded series without reading each expression. Agree a naming review in the rule repository so that every new rule follows the same three parts. Ask the team whether the naming standard is written down and enforced in code review, since names that drift are hard to trust during an incident.

Keeping rates and ratios correct when you aggregate

Counters only increase, and they reset when a process restarts. The rate() function handles those resets and turns a counter into a per-second rate for each series. Summing is safe only after that step. If you aggregate the raw counter first, a restart on one instance can make the combined value drop or jump, and the rate you compute afterward reflects that artifact rather than the traffic. The usual pattern is to apply rate() to each series, then aggregate with sum by the labels you want to keep. Illustrative expression: sum by (job) (rate(http_requests_total[5m])). Keep the range window in the recording rule fixed, and make sure it is wide enough to cover several scrape intervals so the rate has enough samples.

  • Rate first: apply rate() or increase() to each counter series before any sum.
  • Keep labels deliberately: list the labels you need in the by clause so the result stays small.
  • Watch for restarts: a window that spans a restart is handled by rate(), but a sum of raw counters is not.
  • Match the window: the range in the recording rule should match what the dashboard expects.
  • Validate: compare the recording rule output with the raw query on a test server over a period that includes a deployment or restart.

Check that each summed rate in your rules has rate() or increase() applied to the counter before the aggregation, not after.

Recording rule options and when each fits

This table compares the four main design choices in a recording rule setup: evaluation interval, labels on recorded series, evaluation order within a group, and how rule groups are split across teams or services. Read each row against your dashboard freshness needs and your rule count, then confirm the default values for your Prometheus version in the configuration reference before you set anything explicitly.

OptionWhat it controlsWhen it fitsWatch for
Shorter evaluation intervalHow often the rule group recomputes the expression and writes a fresh sampleDashboards that must reflect recent changes, such as incident views on fast-moving error ratesMore rule evaluations and more load on the server for every expression in the group
Longer evaluation intervalFewer recomputations of the same expression over timeCapacity and trend dashboards where minutes-old data is acceptable and expressions are expensivePanels and alerts built on the recorded series can lag behind raw data
Labels added to recorded seriesWhich label sets the output keeps, typically through an aggregation with by()Keeping job, service or cluster labels so dashboards can filter precomputed seriesDropping a label that a dashboard or alert later needs forces a rule rewrite and a history gap
Evaluation order within a groupRules in one group run sequentially, so later rules can read results from earlier onesBuilding a chain where a base rate feeds a ratio or a per-service summaryReordering rules or splitting them across groups can change results that depend on earlier output
One group per teamOwnership boundaries and review scope for rule filesOrganizations where teams own their services and change their rules independentlyMany small groups multiply scheduling and make cross-team naming conventions harder to enforce
One group per serviceRules evaluated together for the component they describeServices with many related expressions that should change and deploy togetherLarge services can produce long groups, so one slow expression delays the rest of its group

Setting up recording rules in a Prometheus rule file

This sequence moves an expensive dashboard expression into a recording rule, checks that the precomputed series matches the raw query, and points dashboards at the cheaper series. Each step ends with a check so the team knows the change is correct before panels depend on it.

  1. Identify slow panels and their PromQL

    Start with the dashboards that time out or load slowly, and open each panel's query in Grafana. Record the exact PromQL for the panels that are slowest, especially those that aggregate many series, use long range selectors or repeat the same subexpression across several panels. Note which panels share a query, because one recording rule can serve several of them. The step is done when you have a short list of expressions, each tied to the dashboards that use it.

  2. Validate the expression in the query UI

    Paste each candidate expression into the Prometheus expression browser and run it over the time range the dashboard uses. Confirm that it returns the expected series and that the result has the labels you need for grouping and filtering. Check the query duration shown by the UI and keep a note of it as the baseline. The step is done when the expression returns the right shape of data and you have a baseline timing to compare against later.

  3. Write the rule file with a group, name and expr

    Create a rule file, for example recording-rules.yml, containing a group with a name, an evaluation interval and one or more rules. Give each recorded series a name in the level:metric:operations form described in the Prometheus recording rules guidance, so a reader can see the aggregation labels, the metric and the operations applied. Keep rates and ratios in the form the guidance recommends, aggregating sums before dividing, so the recorded value matches what the panel computes. The step is done when the file is saved with one group and each rule has a name and an expr.

  4. Load the rule file into the Prometheus configuration

    Add the rule file path under rule_files in prometheus.yml, then reference it from your configuration management if you manage the file as code. Confirm that the Prometheus process can read the file and that the path matches the one in the configuration. Reload Prometheus using the method your deployment allows, such as a signal or the lifecycle endpoint if it is enabled, which is disabled by default. The step is done when the rules page in the web UI lists your group and shows its last evaluation without errors.

  5. Check that the rule file validates

    Run promtool check rules against the file before or after loading, so syntax, metric names and the structure of the group are verified. Fix any reported errors and re-run the check until it passes. Treat a passing check as a gate for changes to rule files in version control. The step is done when promtool reports the file as valid and the Prometheus rules page shows no evaluation errors for the group.

  6. Compare the recorded series with the raw query

    Once the first evaluation has run, query the new series by name in the expression browser. Run the raw expression and the recorded series over the same time range and compare the values at several points, including a period with known load. They should match within the rounding you expect from floating-point arithmetic. If they differ, check the aggregation labels, the range window in rate functions and whether the rule evaluates on an interval that aligns with your range. The step is done when both queries return the same results over the test range, and the recorded series appears with the expected labels.

  7. Point dashboards at the recorded series

    Replace the raw expression in the affected panels with the recorded series name, and keep the panel's grouping and filters so the labels still match. Load each dashboard and note the query duration of the panel, then compare it with the baseline from the query UI. Watch for panels that still use the raw expression in template variables or alerts, because those will keep the cost. The step is done when the changed panels render the same data as before and their query times fall compared with the baseline.

Security and operational considerations for rule files

Recording rules are code that runs inside your Prometheus server, so the people who can edit them, the way changes reach the server, and the series those rules create all carry security and reliability consequences. The cards below cover access to rule files and reloads, the exposure of recorded series, change control, and the checks to run after each change.

Control who can edit and reload rules

Rule files are read from disk and take effect only after Prometheus reloads its configuration. Decide which team owns the rule directory, who has write access to the host or the configuration repository, and who can trigger a reload. The --web.enable-lifecycle flag enables the reload endpoint, and it is disabled by default, so confirm it is off unless your deployment process needs it. If it is enabled, any client that can reach the web port can trigger a reload, so restrict that port to the operators and automation that need it.

Prometheus security model

Review what recorded series expose

A recording rule creates a new time series that is queryable through the same HTTP API and web UI as any scraped metric. Users who can read metrics can therefore read recorded series, including ones built from sensitive labels such as customer identifiers, tenant names or internal hostnames. Before merging a rule, check its output labels and the label values it keeps through by clauses. Aggregating away sensitive labels is usually the simplest control, and the review should cover the new metric name as well as its labels.

Keep rules in version control

Store rule files in a Git repository with the same review process used for application code. Each change should show the rule diff, name the owner of the dashboard or alert that depends on it, and record who approved it. Version control also gives you a known-good state to revert to when a rule starts producing wrong values or heavy load. Treat the repository as the source of truth so that a reload always reflects reviewed content rather than a file edited on the server.

Validate rules before they load

Run promtool check rules on every rule file in continuous integration before it reaches a server. The check catches syntax errors and invalid rule definitions that would otherwise fail a reload. Validation does not judge whether an expression is correct or cheap, so pair it with a review of the expression and its evaluation interval. Test expected output for rules that feed alerts, because a recording rule that silently returns no series can keep an alert from firing.

Watch rule evaluation health after changes

After each reload, check that the rule groups evaluate successfully and within their interval. Prometheus exposes metrics for rule evaluation failures and evaluation duration, and the rule status view in the web UI shows the last error for each rule. Look for groups whose evaluation time approaches the interval, because the next evaluation then starts late and the recorded series develop gaps. Set an alert on evaluation failures so a broken rule does not go unnoticed until a dashboard looks wrong.

Questions teams ask before adding recording rules

Do recording rules reduce the cost of running Prometheus?

Recording rules mainly reduce query work, not the cost of collecting data. Prometheus still scrapes the same targets and stores the same raw series, so the disk and memory needed for ingestion stay roughly the same. What changes is how often an expensive expression runs over raw samples: a rule evaluates it on a schedule and stores a new, smaller series that dashboards and alerts read. Savings show up as lower query load on the server and fewer panel timeouts, and they grow with the number of dashboards that repeat the same heavy expression. The stored result adds series of its own, so a rule set that creates many series can add storage. Ask for a before and after measurement of query duration on your busiest dashboards rather than a generic saving.

How long does a recording rules project take and what drives the effort?

The effort depends mostly on how many expressions need precomputing, how many dashboards and alerts depend on them, and how well the current metric names and labels are understood. Each candidate expression needs its aggregation level chosen, its labels checked, and its output tested against the raw query for matching results. Rules that feed alerts need more review than rules that feed a dashboard, because a wrong ratio can hide a real problem. Work also grows when the team has to change dashboards to read the new series. Ask any partner for a fixed-scope plan that lists the expressions in scope, the dashboards and alerts that will switch over, and the validation method for each. Duration should come from that written scope, not from a general estimate.

What does our team need to provide before the work starts?

The main inputs are a query inventory, read access to the Prometheus servers and their configuration, and a way to test changes safely. The query inventory should list every dashboard panel and alert expression that times out or runs slowly, with the time range and refresh interval used. Engineers also need the current rule files, the scrape configuration, and the Prometheus version in use, because evaluation behavior and available features depend on it. A staging server with comparable data, or a copy of recent data, is needed to compare recording rule output with the original queries. Confirm who can approve changes to dashboards and alert rules, since those owners must accept the new series names.

Can our in-house platform team build recording rules without a partner?

Yes, a capable in-house team can write recording rules, and the core technique is documented in the Prometheus rules guidance. The harder part is the judgment: choosing aggregation levels, keeping rates and ratios correct when series are summed, and matching alert behavior after the change. Teams with a small number of hot queries and someone who understands PromQL can often handle this internally. Teams with many dashboards owned by several groups, or with alerts that must not change behavior, usually need more review time. A partner is useful when the work has to be fixed in scope, validated and handed over with documentation. Compare the internal time needed against the written scope from a partner before deciding.

When should we use recording rules instead of tuning queries or setting limits?

Choose recording rules when the same expensive expression is reused across many panels or alerts and cannot be simplified further. Tune the query first when a single panel uses a wide range selector, an unnecessary regex matcher or a step that is smaller than the data needs. Use query limits and concurrency settings to protect the server from runaway queries, but they stop slow work rather than make it faster, so panels may still fail. If the root cause is too many series, the fix is in instrumentation or relabeling, and precomputing will only hide the growth. In practice, teams often tune the worst queries, then precompute the few that remain. Ask for a short triage that ranks expensive expressions by how often they run and who depends on them.

What should we ask for in a quote for recording rules work?

Ask for a written scope that names each expression to be precomputed, the rule file and evaluation interval proposed for it, and the dashboards and alerts that will change. The quote should state which validation is included, such as comparing rule output with the original query over a sample period, and whether alert behavior is tested. Ask what is one-time work, such as the audit, rule design and documentation, and what recurs, such as reviewing new dashboards or upgrading Prometheus. Clarify who runs the staging test, who approves production changes and what handover material is delivered. Requesting these items makes two quotes comparable, even when their approaches differ.

Do recording rules change how accurate our dashboards and alerts are?

They can, if the aggregation is wrong, so accuracy must be checked rather than assumed. The naming convention level:metric:operations helps readers see which labels were kept and which operations were applied, such as a rate followed by a sum. Rates and ratios need care: averaging precomputed rates or dividing summed values without keeping the right labels can give a different answer from the original expression. Prometheus also values reliability over precision, so small timing differences from evaluation intervals are normal and should be understood before alerts depend on them. Ask that every rule be compared with its source query over the same time window before it replaces that query.

How DeployOpen scopes and delivers recording rule work

DeployOpen treats recording rules as part of the monitoring design, not a quick fix for a slow panel. We start from the dashboards and alerts that are slow or failing, decide which expressions belong in rules, and build them in a Prometheus server you control. Each step is written down so your team can review and run it after handover.

How we scope

  • We list the slow dashboard panels and alert expressions that will be moved into recording rules.
  • The written scope names each rule group, its evaluation interval, and the naming convention used for every recorded series.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before any rule is changed.
  • We confirm which Prometheus version and deployment method you run, since rule behavior must be checked against it.

How we build

  • We write rules in the level:metric:operations form and keep rate and ratio calculations correct by aggregating sums and counts before dividing.
  • Each rule is compared with the original query on the same data to confirm the results match before dashboards switch over.
  • We choose evaluation intervals against your scrape interval and query needs, and record the reasons in the rule files.
  • Rule files are kept in version control with the dashboards and alerts that depend on them, so changes can be reviewed.

How we hand over

  • You receive the rule files, a naming reference, and a list of which dashboards and alerts now read each recorded series.
  • Documentation covers how to add a rule, how to check that a rule is evaluating, and what to watch after a change.
  • Your team runs a walkthrough of the rules and the rollback steps for each dashboard switch.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • We can review new dashboards and alerts against your existing rules as your metrics and query load change.
  • Confirm with us which Prometheus release line you will run, since support windows differ between minor releases and long-term support lines.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.