PromQL cheat sheet
The patterns below cover most dashboards and alerts. Replace the metric and label names with your own.
| Goal | Query |
| Requests per second | sum(rate(http_requests_total[5m])) |
| Requests per second, per service | sum by (service) (rate(http_requests_total[5m])) |
| Error percentage | 100 * sum(rate(http_requests_total{code=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) |
| p95 latency | histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m]))) |
| CPU usage, % | 100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100 |
| Memory used, % | 100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) |
| Disk full in 4 hours | predict_linear(node_filesystem_avail_bytes[1h], 4 * 3600) < 0 |
| Target is down | up == 0 |
| Top 5 by request rate | topk(5, sum by (handler) (rate(http_requests_total[5m]))) |
| Restarts in the last hour | increase(kube_pod_container_status_restarts_total[1h]) > 0 |
| Series count per metric | topk(10, count by (__name__) ({__name__=~".+"})) |
Frequently asked questions
What is the difference between rate() and irate()?
rate() averages over the whole range and is stable, which makes it right for alerts and most graphs. irate() uses only the last two samples, so it reacts instantly but is noisy; use it for zoomed-in graphs.
What is the difference between rate() and increase()?
They are the same calculation in different units. rate() gives the per-second average; increase() gives the total growth over the range, which is rate multiplied by the range in seconds.
How do I calculate a percentile in PromQL?
Use histogram_quantile() on the rate of the metric's _bucket series, keeping the le label in the aggregation: histogram_quantile(0.95, sum by (le) (rate(metric_bucket[5m]))).
Why does my query return no data?
Check the label matchers first — a mistyped label value matches nothing without an error. Then check that the range is at least twice the scrape interval and that the target is still being scraped (up == 1).