PromQL Query Language Fundamentals
You'll learn: How to query time-series metrics using PromQL's selector syntax, operators, and basic aggregation functions.
PromQL (Prometheus Query Language) is your interface to the time-series data stored in Prometheus. Think of it as SQL for metrics—it lets you slice, filter, and aggregate measurements across time and labels.
Selectors: Picking Your Metrics
Selectors identify which time series you want. The simplest form is just the metric name:
http_requests_total
You refine this using label matchers in curly braces:
http_requests_total{method="GET", status="200"}
Matchers support equality (=), inequality (!=), regex match (=~), and regex non-match (!~).
Operators: Transforming Values
PromQL supports arithmetic (+, -, *, /), comparison (>, <, ==), and logical operators. Since counters reset, you typically use range vectors with functions:
rate(http_requests_total[5m])
This calculates the per-second rate over the last 5 minutes—perfect for converting counter increments into meaningful rates.
Basic Aggregation Functions
Aggregation collapses multiple time series into one. Common functions include:
sum()- Total across seriesavg()- Average valuemax()/min()- Extremescount()- Number of series
Example: sum(rate(http_requests_total[5m])) by (status) gives you request rates grouped by HTTP status code.
You can combine these building blocks: avg(rate(http_requests_total{job="api"}[5m])) calculates the average request rate across all API instances.
Key Takeaway: PromQL uses selectors to filter metrics by labels, operators and functions like rate() to transform raw counter data into meaningful measurements, and aggregation functions to summarize across multiple time series—giving you the full picture of your system's behavior.