Skip to content
PromQL & Query Patterns
step 1/5

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, increase
  • histogram_quantile (for prometheus histogram type)
  • clamp_min, clamp_max, abs
  • predict_linear, holt_winters

Query execution:

  1. Parse PromQL → AST.
  2. Optimize: prune by label, push down filters.
  3. For each series matching, fetch chunks for the time range.
  4. Decompress chunks into points.
  5. Apply functions per series.
  6. Aggregate across series.
  7. 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…