PromQL Cheatsheet & Static Checker
Pure frontend: paste a PromQL expression and get instant hints about common traps and the right function family. Everything runs in your browser, with no network access and no connection to your Prometheus.
How to use it
Paste a PromQL expression below and click Check. The tool scans it with static rules: whether a function matches the metric family, whether a metric name suffix agrees with the function, whether histogram_quantile keeps le, whether a range window is obviously too short, and whether brackets are balanced. These are format and semantics hints, not query execution; verify the real result in your own Prometheus UI.
Three function families: know the type first
Before writing a query, work out whether the metric is a counter, a gauge or a histogram. Pick the wrong family and the syntax still parses while the result means nothing.
| Metric type | Typical suffix | Right functions | Common mistake |
|---|---|---|---|
| Counter | _total, _sum, _count, _bucket |
rate(), irate(), increase() |
Reading the running total, or summing totals to draw a trend |
| Gauge | no fixed suffix; often bytes, usage, temperature |
read directly, or delta(), deriv() |
Wrapping it in rate() and getting noise |
| Histogram | _bucket with an le label |
histogram_quantile() |
Treating _sum / _count as a percentile; that is the mean |
| Summary | has a quantile label |
read one quantile at a time | Averaging quantiles across instances, which is not statistically valid |
The classic mistake is treating a gauge like a counter. Drop rate(node_memory_MemAvailable_bytes[5m]) into any query UI and it parses perfectly, returning a professional-looking "memory change per second" curve. Memory rises and falls by nature, so every fall is compensated as a reset and the number means nothing. The reliable way to identify a type is the exporter's # TYPE line, not the metric name.
Four traps worth memorizing
Trap one: a window that is too short. rate() needs at least two samples in the window. Scrape every 15 seconds but write [30s], and edge moments often contain a single point, so the result is empty. Give the window at least four times the scrape interval; [5m] is a safe default. A graph that appears and disappears is usually this, not a sick service.
Trap two: dropping le from histogram_quantile. Classic histogram quantiles are interpolated from le bucket boundaries. sum(rate(x_bucket[5m])) collapses every bucket into one number, destroying the distribution, so there is nothing left to interpolate. Take rate() of the buckets, sum by (le), then call histogram_quantile(0.99, ...). Add service to the by clause when you need per-service results.
Trap three: aggregating before rate(). rate(sum(...)[5m]) is wrong. When one instance restarts and its counter drops to zero, the sum drops with it, and rate() reads that as a fleet-wide reset, drawing a huge false spike. Take rate() per series first, then sum across instances: sum by (job) (rate(x_total[5m])).
Trap four: irate() in alerts. irate() uses only the last two samples. It is sensitive but jumpy, good for inspecting a short spike and poor for deciding whether to page someone. Use rate() in alert rules and recording rules.
Copyable templates
These are the skeletons I reach for most often. Swap in your own metric names. The error ratio divides two rates; the quantile keeps le; the availability check uses absent() to catch the case where no series exists at all.
# request error ratio
sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))
# p99 latency, keeping le
histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
# target vanished or is down
absent(up{job="api"}) or (up{job="api"} == 0)
# CPU usage
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
Filter early, aggregate later
Most PromQL timeouts I have investigated came from filtering in the wrong place. Put label matchers in the innermost vector selector so the engine loads fewer series from the start. {handler=~"/api/users.*", status=~"5.."} is far cheaper than selecting everything and discarding later. Filter, then aggregate. That order is close to a rule.
Binary operators are the other source of surprises. If the two sides carry different label sets, a / b fails with "many-to-many matching not allowed". Spell out the alignment with on(instance, job) or exclude noise with ignoring(...). When a ratio's numerator comes from a different metric than its denominator, you almost always need this.
Keep absent() in mind as well. Many people write up == 0 to find dead targets, but a target that restarted and has not been scraped yet has no series at all, so that query returns nothing. absent(up{job="api"}) or (up{job="api"} == 0) covers both "gone entirely" and "explicitly down". In monitoring, the dangerous state is often not zero but no data.
What this checker cannot do
It matches text. It recognizes function names, metric suffixes and bracket syntax, and it balances parentheses. It will catch the mistakes listed above. It does not know your scrape interval, and it cannot tell what type a metric is in your environment. Treat every hint as a prompt to go and check, never as a verdict.
A sound way to validate a query is three steps: plot the raw metric first and see whether its shape matches your expectation; add the function and check the order of magnitude; only then put it in an alert rule with a for clause to dampen noise. If you cannot explain the unit of a query's output in one sentence, it is probably wrong. Unit sense is the best self-check PromQL offers. A rate should be events per second, a ratio should sit between zero and one, a latency quantile should be in seconds. When the number looks off, suspect the expression before the data source.
For the full troubleshooting path, see PromQL cheatsheet: golden signals and traps. For blank dashboards and missing data, continue with Prometheus no-data troubleshooting. Function semantics and arguments follow the official Prometheus querying functions documentation.