Reading — step 1 of 5
Read
~1 min readQuerying
PromQL & Query Patterns
Prometheus's PromQL is the most-copied TSDB query language. Concepts:
Instant vector: value at a single timestamp.
http_requests_total # all matching series, current value
http_requests_total{method="GET",status="200"} # filtered
Range vector: window of values.
http_requests_total[5m] # last 5min for each series
Rate calculations (counters):
rate(http_requests_total[5m]) # per-second rate over last 5min
irate(http_requests_total[5m]) # rate from last 2 samples
Aggregations:
sum by (service) (rate(http_requests_total[5m])) # sum per service
avg(node_cpu_usage) # global avg
quantile(0.99, http_request_duration_seconds_bucket) # p99 latency
Operators:
http_requests_total{status=~"5.."} / on(service) http_requests_total
# error ratio per service
Functions (~100 built-in):
rate,irate,delta,increasehistogram_quantile(for prometheus histogram type)clamp_min,clamp_max,abspredict_linear,holt_winters
Query execution:
- Parse PromQL → AST.
- Optimize: prune by label, push down filters.
- For each series matching, fetch chunks for the time range.
- Decompress chunks into points.
- Apply functions per series.
- Aggregate across series.
- Return matrix (timestamps × series) or vector.
Prometheus is single-node; HA + scale via federation, Thanos, Cortex, VictoriaMetrics, Grafana Mimir. All speak PromQL.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…