PromQL Query Patterns
Docs: https://prometheus.io/docs/prometheus/latest/querying/basics/
PromQL returns either an instant vector, a range vector, or a scalar.
Golden rule: rate() / increase() require a range vector ≥ 4× the scrape interval. 60s scrape → use [5m] minimum.
Prerequisites
- A Prometheus / Mimir / Grafana Cloud endpoint to query (
/api/v1/queryor via Grafana Explore) - The PromQL pattern library in
references/patterns.md[blocked]
Common Workflows
1. Write + validate a query
2. Common patterns to copy
Per-status request rate (aggregate AFTER rate):
p95 latency (must keep le in the inner aggregation):
Error rate with divide-by-zero guard:
Full library (recording rules, SLO burn-rate, offsets, cardinality hunt, native histograms): references/patterns.md [blocked].
3. Convert a slow dashboard query into a recording rule
Common bugs
histogram_quantilereturns NaN → forgotby (le)in the inner aggregation- "No data" → check the metric exists (
/api/v1/series) and the window ≥ 4× scrape interval - Wrong rate magnitude → counter was aggregated before
rate()(alwaysrate()first) - Query timeout → series count too high; use
topk(...)+ a recording rule + drop high-cardinality labels (seereferences/patterns.md[blocked])


