Use it to query metrics for dashboards and alerts.
PromQL Basics
PromQL is Prometheus's query language: selectors with labels, range vectors, functions such as rate(), aggregation such as sum by (), and binary operators.
1. Selector: http_requests_total{job="api",code=~"5.."}.
2. Rate: rate(...[5m]).
3. Aggregate: sum by (service)(...).
4. Ratio with matching labels.
5. Test in the expression browser.
selector → range vector → function → aggregation → result
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Compare a query result with a known value (for example request count in access logs). Check queries do not return many series unexpectedly.
Step 2 Common failures Narrow the fault
Too short a rate() range returns gaps. Dividing two metrics with different labels returns nothing without on(). sum without by() removes labels you need for alert routing.
rate() needs a range at least 4× the scrape interval. Aggregate after rate (sum(rate(...))). by keeps labels, without drops them. Watch for label mismatches in binary operations.
http_requests_total{job="api",code=~"5.."}— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
The engine evaluates the expression at each step of the graph. Binary operators match series by labels; on() and ignoring() control matching. Recording rules precompute expensive expressions.
ReferenceImportant terms & boundaries3 sections · depth on demand
Common queries
up == 0 # targets down
rate(node_network_receive_bytes_total[5m]) * 8 # bits/s
sum by (job) (rate(http_requests_total[5m]))
100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
predict_linear(node_filesystem_avail_bytes[6h], 24*3600) < 0
Use rate() on counters (never on gauges), choose a range at least 4× the scrape interval, and aggregate with sum by (...) after rate.
In depth
Instant vector vs range vector
http_requests_total is an instant vector (one value per series at the evaluation time). http_requests_total[5m] is a range vector (all samples in the last 5 minutes per series); only functions such as rate() accept it.
Choosing the rate() window
Use at least four times the scrape interval: with a 15 s scrape, [1m] is the minimum and [5m] is common. A window shorter than two scrapes returns nothing. In Grafana, $__rate_interval picks a safe value automatically.
Aggregation keeps or drops labels
sum by (service) (rate(http_requests_total[5m])) # keep only service
sum without (instance, pod) (rate(http_requests_total[5m])) # drop these, keep the rest
Always rate() first, then sum(); summing raw counters across instances breaks reset handling.
Vector matching
Binary operations match series with identical label sets. When the two sides differ, say how to match:
# error ratio per service: both sides reduced to the same labels
sum by (service) (rate(http_requests_total{code=~"5.."}[5m]))
/ sum by (service) (rate(http_requests_total[5m]))
# add a label from an info metric (many-to-one)
rate(http_requests_total[5m]) * on (instance) group_left (version) app_build_info
Useful patterns
up == 0 # targets that failed the last scrape
absent(up{job="checkout"}) # job disappeared entirely
predict_linear(node_filesystem_avail_bytes[6h], 24*3600) < 0 # disk full within 24 h
topk(5, sum by (route) (rate(http_requests_total[5m])))
Check a query's cost with the Prometheus UI's series count before putting it on a dashboard that refreshes every 10 seconds for 50 people.
Common mistakes
rate()over windows shorter than two scrapes.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.