Fixing slow PromQL queries and dashboard timeouts

Grafana panels that time out on Prometheus usually trace back to a few expensive expressions, broad selectors or query limits. This page explains how to find them, fix them and decide when to hire help.

On this page

Why slow PromQL queries and dashboard timeouts happen on Prometheus

Grafana panels time out on Prometheus when a PromQL expression asks the server to read more series or more samples than it can return within its query limits, even though the server itself is healthy and scraping normally. The usual cause is not a sick server but one or two expressions that select a wide set of series over a long time range, often with regular expression matchers or aggregations applied after the fact. Prometheus runs as a single-node time series database, so every query is served by the same process that ingests samples, and its cost grows with the number of series touched and the length of the range being evaluated. A dashboard that refreshes many panels at once multiplies that cost.

Prometheus is designed to value reliability over precision, so it answers queries from local blocks and does not promise that an expensive question will finish. That design explains why the fix is rarely the server. In most estates a small number of panels account for nearly all of the slow work, and the first job is to find them: check which panel sends the request, what time range it uses, and which selectors it contains. The expensive part is usually the number of series matched before any aggregation happens, so reducing the matched set helps more than adding CPU or memory. Confirm the query timeout and sample limits configured on your server and in Grafana before changing anything, because a panel that hits a limit fails differently from one that is still running.

The fixes that follow from this are usually a few expressions: narrow the label selectors, move wide range math into recording rules, and align dashboard time ranges and refresh intervals with what the server can answer. Ask whoever owns the dashboards which panels matter for on-call decisions, since those panels deserve precomputed results and the rest can be simplified or removed. Treat the server settings as the last step, and test each change against the same panel and time range so you can show that the timeout is actually gone.

What makes a PromQL query expensive

A dashboard panel is one query, but a dashboard with twenty panels sends twenty queries every refresh, and each one pays the same costs. The four causes below decide how many samples and series Prometheus must read before it can answer, so check them in order when a panel times out.

Wide range selectors over long windows

A range selector such as [30d] asks Prometheus to read every sample in that window for every matching series, and the cost grows with both the window length and the number of series. Functions like rate() and avg_over_time() on a long window multiply that read across the whole panel. Check the window in each panel against the time range the panel displays, and ask whether a short rate window with a longer dashboard range would answer the question. Each panel repeats this work on every refresh, so a wide window on one panel can dominate the total load.

Storage docs

Regex matchers that scan many label values

An equality matcher such as job="api" narrows the search quickly, while a regex matcher such as instance=~".*prod.*" forces Prometheus to test each candidate label value against the pattern. Negative regex matchers and unanchored patterns are the usual culprits because they cannot use the index as efficiently. Replace broad patterns with explicit value lists where possible, and anchor patterns so they do not match substrings by accident. Look at the label values in the query first, since a regex that matches thousands of values is expensive even when the result is small.

High-cardinality series that queries must load

Every unique combination of labels is a separate series, and a query must load each matching series even if the final result shows only a few lines. A metric with a label such as user ID, request path or pod name can produce a very large number of series, and a panel that selects that metric without narrowing it scans all of them. Use the TSDB status view or a query such as count by (__name__)({__name__=~".+"}) in a test environment to find the largest metrics. Fixing cardinality at the source is usually cheaper than tuning every panel that touches the metric.

Aggregations applied after the fact

Writing sum by (service)(rate(http_requests_total[5m])) in a panel means Prometheus first computes the rate for every underlying series and then combines them, so the work scales with the raw series count on every refresh. The same aggregation in a recording rule runs once per evaluation interval and stores a small result that panels can read cheaply. When several panels share the same expensive aggregation, each one repeats the work, which is the main reason a dashboard with many panels times out while a single query runs fine in the expression browser. Confirm which aggregations appear across multiple panels before deciding what to precompute.

Query limits and server settings to tune

This table compares the server and panel settings that bound how long and how heavily a query can run. Read each row as a trade-off: the setting protects the server or the panel, the user sees a specific symptom when it is hit, and raising it is a poor fix unless the expression has already been checked. Confirm exact flag names and defaults in the Prometheus documentation for your version before changing anything.

SettingWhat it protectsWhat the user sees when hitWhen raising it is a poor fix
Query timeout (--query.timeout)Stops one query from holding resources until it finishes, protecting the server from runaway evaluation.The panel shows a timeout or gateway error, and the server cancels the query.Raising it lets a bad expression run longer and hold memory and concurrency slots. Fix the expression first.
Max samples (--query.max-samples)Caps how many samples one query may load into memory, guarding against spikes from wide range selectors.The query fails with an error about too many samples, so the panel shows no data.On a memory-limited server, a higher cap can cause out-of-memory restarts. Narrow the selector, shorten the range or add a recording rule.
Max concurrency (--query.max-concurrency)Limits how many queries evaluate at once, protecting CPU and memory when many dashboards refresh together.Queries wait in a queue, so panels load slowly or time out even when each query is fast.A higher value adds load to a saturated server and can slow rule evaluation. Reduce refresh rates or fix the heaviest panels first.
Lookback delta (--query.lookback-delta)Sets how far back an instant query searches for the last sample of a series, which determines when a series counts as present.Series that stopped reporting drop out early, or stale series linger, so graphs mislead without any error.Widening it to hide gaps from failed scrapes masks outages. Investigate scrape health first and change it only for a documented reason.
Grafana minimum step and max data pointsControls how many points a panel requests across its time range, limiting fine-grained evaluation over long ranges.Graphs look coarse, or very small steps make the panel slow because it requests many more steps.A tiny fixed step over a long range multiplies the work. Keep the panel's automatic interval and align the step with the scrape interval.
Rule evaluation intervalSets how often a rule group runs its expressions, protecting the server from repeated heavy work on every cycle.Recording rule values update late, so dashboards built on them lag and alerts fire later than expected.Shortening it to speed one dashboard moves the cost onto every evaluation. Check evaluation duration in the rule metrics before changing it.

How to find the query that times out

Start in Grafana because it shows which panel, data source and query the timeout comes from. Open the panel menu, choose Inspect, then Query, and read the request that Grafana sent to Prometheus. Note whether the panel holds several queries, transformations or template variables, because a variable that expands into many values multiplies the work the server does.

  • Panel and data source. Record the dashboard, the panel title and the Prometheus data source, since one dashboard can point at more than one server.
  • Expanded query text. Copy the expression with template variables substituted, since that is the text the server actually runs.
  • Range and step. Record the time range and the resolution step Grafana computed, because a small step over a long range produces many more evaluation points.
  • Hidden or duplicate queries. Check for disabled queries and for other panels that run the same expression.
  • Refresh interval. Note the auto-refresh setting, since a panel that refreshes every few seconds keeps re-running an expensive query.

Check that the copied expression, time range and step reproduce the timeout before you move to the server.

Fix a slow query step by step

This sequence turns a timing-out Grafana panel into a measured, repeatable fix, changing the expression first and the server limits last so each change can be verified on its own.

  1. Capture the slow expressions and baseline timings

    Pull the exact PromQL from the timing-out panels, including the variables that Grafana substitutes, and run each one directly in the Prometheus expression browser over one fixed time range. Record the duration the query reports, the number of series returned and the number of samples touched. Save these numbers next to the query text. The step is done when every slow panel has a baseline row that someone else can rerun and reproduce.

  2. Narrow selectors and remove unneeded regex

    Tighten each series selector with exact label matchers wherever the label values are known, and replace broad regex matchers such as =~".*" or wide alternations with equality matchers or a smaller set of values. Filter on the labels that the dashboard actually needs before the aggregation runs, not after. Rerun the same query over the same time range and compare the duration and series count with the baseline. The check passes when the result is identical and the work done has dropped.

  3. Replace subqueries with simpler range functions where correct

    Look for subqueries in the form of a range expression with a resolution suffix, and check whether a plain range function such as rate, increase or avg_over_time over the raw range gives the same answer. Many subqueries exist only to smooth a value that a single range function already smooths. Keep the subquery where it produces a different result. Compare outputs on several points of the time range before accepting a change, then time the query again against the baseline.

  4. Align Grafana step and interval values

    In the Grafana panel and the Prometheus data source settings, check the minimum interval, the max data points and the step that Grafana sends with each query. A step much finer than the scrape interval fetches more samples without adding information, and a range vector shorter than a few scrape intervals can return gaps. Set the step and range so they match the scrape interval and the panel width. Confirm in the query inspector that the step changed, then compare the panel load time before and after.

  5. Adjust server query limits only after the expression is fixed

    Once the expressions are as lean as they can be, review the server settings that bound query work, such as the query timeout, the maximum samples per query and the concurrent query limit, and change them only if a legitimate query still fails. Raising these limits before the expression is fixed hides the cost and lets more expensive queries run against the same server. Confirm the current values in the server configuration and the flags your version supports, make one change at a time, and record why each change was needed.

  6. Move the proven heavy expression into a recording rule

    When a corrected expression is still expensive and a dashboard or alert reuses it on every refresh, move it into a recording rule with the level:metric:operations naming convention. Evaluate it at an interval that matches how often the panel refreshes, then point the panel at the new series. Verify that the recorded series returns the same values as the original expression for the same time range, and that the dashboard load time drops. Keep the original expression in the rule file's comments so the next engineer can trace the result.

  7. Confirm the fix holds under normal dashboard use

    Load each repaired dashboard several times with its default time range and with the wider ranges that users pick most often, and check that no panel times out and that the query duration stays close to the recorded baseline. Watch the Prometheus server metrics for query duration and for queries that were rejected. The step is complete when the dashboards load without timeouts over the ranges users actually request and the change record shows each fix with its before and after numbers.

When recording rules fix dashboards and when they do not

A recording rule fixes a slow dashboard when the panel repeats the same expensive expression on every refresh across many users. The rule evaluates the expression on a schedule and writes the result as a new series, so the panel reads one precomputed series instead of rescanning raw samples. Name recorded series with the level:metric:operations convention, for example job:http_requests:rate5m, where the level is the aggregation labels kept, the metric is the base name and the operations describe what was applied. The name tells the next engineer what the series contains and stops two teams from writing conflicting recordings under the same name.

Correctness depends on what you aggregate. For a ratio of errors to requests, record the sums of the numerator and denominator, then divide at query time. Averaging per-instance averages gives the wrong answer when instances have different traffic, because each instance counts equally regardless of volume. Keep rate() inside the rule so counter resets are handled before aggregation. Choose the rule interval no coarser than the dashboard step, or the panel will show stair-step values. Confirm the exact evaluation behavior and any step alignment in the Prometheus documentation for your release before you rely on it for alerting.

Recording rules are not free. Each recorded series is stored like any other series, adds disk and memory use, and every rule group costs evaluation time on each interval. Heavy rules that run longer than their interval fall behind, so check rule evaluation duration after you add them. Recording rules also do not fix an unbounded label set. If a metric carries a label such as user ID or request path, the recording still produces one series per value, so the fix belongs in instrumentation or relabeling. Confirm the series count before and after each rule to measure whether the change helped.

How a Grafana panel request reaches Prometheus

A panel refresh starts in Grafana, which sends the PromQL expression through the Prometheus data source to the query engine. The engine reads samples from the head and from on-disk blocks, and every step is bounded by the query timeout, the sample limit and the concurrency limit. A recording rule sits beside this path as a precomputed series, so the panel can read a small, ready-made result instead of rerunning the heavy expression. Check the query timeout, the sample count the panel touches, and whether the expression has a recording rule before tuning anything else.

A panel query path through Prometheus, with a recording rule as a shortcut.

Security and operational considerations when tuning queries

Tuning query limits and moving expensive expressions into recording rules changes who can load the server and what data they can read. The four cards below cover capacity sharing, access to the query API, access to derived series, and how limit changes are reviewed and reversed.

Raised limits can starve other work

A higher query timeout or sample limit lets one slow dashboard hold CPU and memory that alert evaluation and scrapes also need. Before raising a limit, check which panels and users cause the load, and whether alert rule evaluation on the same server still finishes on time. Ask whether heavy dashboards can be moved to recording rules or a separate Prometheus instance so the limit increase does not have to apply to everyone.

Query API needs authentication and TLS

The query API and web UI are endpoints like any other, and they expose every series the server holds. The Prometheus security model describes TLS with client certificates, with TLS 1.2 as the minimum, and HTTP basic authentication with bcrypt-hashed passwords, which should only be used over TLS. Because Prometheus has no built-in single sign-on, plan an authenticating reverse proxy in front of the UI and API if your users sign in through a central identity provider.

Security model docs

Recording rule output is still metric data

Series written by recording rules are queryable like any other metric, so they can carry sensitive label values from the source metrics, such as tenant, customer or host identifiers. Review the labels a rule keeps, drop those that reveal more than a dashboard needs, and confirm that anyone who can read the derived series is already allowed to read the source data. Treat the rule files as configuration that needs the same review as code.

Limit changes go through change control

A timeout or sample limit change can alter how alerts and dashboards behave during an incident, so record each change with its owner, reason and the query it was meant to fix. Store the configuration in version control, test the change on a non-production server with representative queries, and keep the previous values ready for rollback. Confirm with your change board which changes need approval and how quickly a rollback can be executed outside working hours.

Questions buyers ask about fixing slow Prometheus queries

How much effort does a typical Prometheus query tuning engagement take?

Effort depends mainly on how many dashboards and panels read from Prometheus, how many distinct PromQL expressions sit behind them, and how the data is shaped. A small set of panels that query a few well-labeled metrics is a short exercise. A large Grafana estate with many expressions, high-cardinality label sets and regex matchers across dozens of metrics takes much longer, because each expression needs to be measured, rewritten or precomputed and then checked against the panels that use it. Ask any partner to base the quote on a written inventory of dashboards and expressions, not on a general estimate of the platform. No duration is fixed here; the scope document is where it should appear.

What does our team need to provide before tuning starts?

Tuning goes faster when the people doing it can see what is slow and why. Typically the team should provide:

  • Exports of the Grafana dashboards in scope, including panel queries, variables and refresh intervals
  • Query logs or the query statistics the server can expose, so slow expressions can be ranked by real cost
  • Read access to the Prometheus server and its configuration, including the query timeout and sample limit flags in use
  • Access to Grafana to confirm which panels time out and at what time range
  • Named owners who can approve changes to recording rules and to dashboards

Confirm with your own Prometheus version which query logging and statistics options are available in your environment.

Can an internal platform or SRE team fix slow Prometheus queries on its own?

Yes, many teams can, provided someone understands PromQL well enough to rewrite expressions and has permission to change server configuration and recording rules. The work is mostly methodical: find the expensive panels, identify the selectors and aggregations that scan the most series, rewrite them, and move repeated heavy calculations into recording rules. The harder part is usually coordination, because a recording rule change affects every dashboard and alert that depends on it. A team that already runs Prometheus in production and has a change process for rules and dashboards is in a strong position. A team that has never worked with the query engine may spend much of its time learning the cost model.

When is it worth paying for outside help with Prometheus query performance?

Outside help makes most sense when the slowdown affects many dashboards or alerts, when the internal team lacks PromQL depth, or when the same problem keeps returning after fixes. Other common triggers are a planned dashboard migration, a server that also suffers memory pressure or cardinality growth, and alert rules that evaluate too slowly to be trusted. A fixed-scope engagement gives you agreed deliverables and a written list of what changed before work starts. Retainers suit teams that expect dashboards and rules to keep changing after the first round of tuning.

Is raising the query timeout ever the right fix for a slow dashboard?

Sometimes, but rarely as the first step. A higher query timeout lets an expensive expression finish, yet it also lets that expression hold resources longer and can make other queries wait. It is a reasonable temporary measure while a recording rule or rewrite is prepared, or when a one-off report legitimately needs a long-running query. In most cases the better fix is to narrow the time range, reduce the label matchers, avoid regex matchers where equality works, or precompute the expression. Check the server's concurrency and sample limit settings at the same time, since raising one limit without the others can move the bottleneck rather than remove it.

Which Prometheus setting changes should we avoid during query tuning?

Avoid changing several limits at once, because the effect of each becomes hard to read. Be careful with the query timeout and the maximum concurrent queries setting, as raising them can increase memory use and load on the server. Keep administrative endpoints disabled in production unless you need them for a specific task, because the security model keeps admin HTTP APIs off by default and those endpoints can run destructive operations. Test each change on a non-production copy with representative data where you can, and record the before and after panel timings.

Will tuning queries change what our alerts and dashboards show?

It can, if a rewrite changes the math. Rewriting a rate, ratio or quantile incorrectly is a common source of wrong numbers, so each changed expression should be compared against the original over the same time window before the new version replaces it. Prometheus values reliability over precision, but that does not excuse a rewritten expression that quietly produces different results. Record the old and new outputs side by side during a validation period, and agree with the owners of affected alerts which differences are acceptable.

How DeployOpen scopes and delivers Prometheus query tuning

DeployOpen approaches slow PromQL and dashboard timeouts as a scoped piece of work on a Prometheus server you control. We start from the panels and alert rules that time out, measure what they actually execute, and agree the changes in writing before any tuning begins.

How we scope

  • We list the dashboards, panels and alert rules that time out, with the Grafana data source and query each one runs.
  • The written scope names the Prometheus version, server sizing, query limits and which expressions are in or out of tuning.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts. Ongoing support is available as a retainer.

How we build

  • We review query timeout, sample limit and concurrency settings against the workload before changing any of them.
  • Heavy expressions with wide range selectors or broad regex matchers are rewritten and checked for identical results.
  • Candidate recording rules are built and validated against the original queries on the same data before dashboards point to them.

How we hand over

  • You receive the changed queries, recording rule files and configuration with a record of each change and its reason.
  • Documentation covers the naming convention, evaluation intervals and which dashboards now depend on each recording rule.
  • We agree a verification checklist so your team can confirm panels load and the server stays within its limits after handover.

How we support

  • Post-handover retesting covers dashboards and rules after Prometheus upgrades or new services add query load.
  • Retainers can include periodic review of slow query logs, query limits and new panels added by teams.
  • Your team keeps ownership of the Prometheus server, and we confirm each support request against the written scope.

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.