Prometheus and PromQL 3 cheatsheet
Prometheus and PromQL 3: Rates and aggregation
11 common Prometheus and PromQL 3 tasks.
Per-second rate of a counter
Average per-second increase over five minutes. Always use rate (or increase) on counters, never the raw value.
rate(http_requests_total[5m])
Total increase over a window
How much a counter grew in the last hour.
increase(http_requests_total[1h])
Aggregate across series
Sum the rate across all instances, keeping one series per job and status.
sum by (job, status) (rate(http_requests_total[5m]))
Error ratio
The share of requests that fail, from two aggregated rates.
sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))
95th percentile latency
Estimate a percentile from a histogram's buckets. Always sum by le first.
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
Top N series
Return the five busiest series.
topk(5, sum by (instance) (rate(http_requests_total[5m])))
Predict a trend
Estimate free disk space four hours from now by extrapolating the last six hours.
predict_linear(node_filesystem_avail_bytes[6h], 4 * 3600)
Detect a missing metric
Returns 1 when no series match, which is useful for alerting on vanished targets.
absent(up{job="api"})
Memory used as a percentage
A common node_exporter query for host memory use.
100 * (1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)
CPU used as a percentage
A common node_exporter query for host CPU use.
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)