Pcornel
Observability · Metrics

PromQL Basics

Cheat sheet · https://pcornel.dk/topic.php?topic=6205

Back to the Topic

Answer

PromQL is Prometheus's query language: selectors with labels, range vectors, functions such as rate(), aggregation such as sum by (), and binary operators.

Remember

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.

First checks

  • http_requests_total{job="api",code=~"5.."} — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid

Verify in this order

selector → range vector → function → aggregation → result

Where it usually breaks

Too short a rate() range returns gaps.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6205

Confirmation

Confirm action

Continue?