PromQL, short for Prometheus Query Language, is the functional query language used to select, filter, aggregate and transform time series data stored by Prometheus and compatible systems. In observability for cloud-native platforms, PromQL is the common language behind Grafana dashboards, alerting rules and service level indicator calculations.
Unlike SQL, PromQL does not query rows in tables. It evaluates expressions over streams of timestamped samples identified by labels, and every query returns either an instant snapshot or a range of values over time. Mastering it means understanding label matching, rates and aggregation rather than joins and schemas.
How PromQL evaluates time series
PromQL works on a dimensional data model. Each time series is identified by a metric name and a set of key-value labels, such as http_requests_total{service="checkout", status="500"}, and holds a sequence of float samples with millisecond timestamps.
Every PromQL expression evaluates to one of four types. Knowing which type a function expects is the single most common source of query errors, because many functions accept only range vectors while graphs require instant vectors.
| Type | What it contains | Example |
|---|---|---|
| Instant vector | One sample per series at a single time | up{job="api"} |
| Range vector | Samples per series over a time window | http_requests_total[5m] |
| Scalar | A single floating-point number | 0.95 |
| String | A string literal, rarely used | "text" |
When a dashboard renders a graph, the server runs a range query: it evaluates the same instant expression at each step across the requested interval. A step of 15 seconds over 6 hours means 1,440 evaluations, which explains why heavy queries slow down long dashboard ranges.
Core functions and operators
A small set of functions covers most production PromQL usage. The table below summarizes the functions that appear in nearly every dashboard and alerting rule, together with the metric types they suit.
| Function | Input | Purpose |
|---|---|---|
| rate | Counter range vector | Per-second average increase over the window |
| irate | Counter range vector | Per-second rate from the last two samples |
| increase | Counter range vector | Total increase over the window |
| histogram_quantile | Histogram bucket rates | Estimated percentile, such as p99 latency |
| sum, avg, max by | Instant vector | Aggregate across chosen labels |
| avg_over_time | Gauge range vector | Smooth a gauge over a window |
| absent | Instant vector | Detect missing series for alerting |
Aggregation operators use by and without clauses to control which labels survive. For example, sum by (service) (rate(http_requests_total[5m])) produces one request-rate series per service, discarding instance and pod labels that would otherwise multiply the output.
Binary operators such as division match series by identical label sets. When label sets differ, vector matching modifiers such as on, ignoring, group_left and group_right define the join, which is how teams calculate an error ratio by dividing failed requests by total requests.
PromQL compared with other query languages
PromQL is one of several languages used to query telemetry. Its strength is concise numeric analysis of metrics; it is not designed for logs, traces or arbitrary relational queries, which other tools in the observability stack handle better.
| Language | Primary data | Strength | Limitation |
|---|---|---|---|
| PromQL | Metrics time series | Compact rates and aggregation | No joins across arbitrary data |
| LogQL | Log streams | Label selection plus log filtering | Metric functions are derived |
| SQL | Relational tables | General joins and grouping | Verbose for time series math |
| MetricsQL | Prometheus-compatible metrics | PromQL superset with extensions | Extensions are not portable |
PromQL has become a de facto interoperability standard. Thanos, Cortex, Grafana Mimir, VictoriaMetrics and several managed cloud services accept PromQL, so dashboards and alerting rules written once can usually move between backends with little or no rewriting.
Using PromQL for alerting and service levels
Alerting rules are PromQL expressions that fire when they return any series for longer than a configured for duration. A well-designed rule alerts on user-visible symptoms such as error ratio or latency rather than on internal causes such as CPU usage.
Service level objectives depend heavily on PromQL. A service level indicator for availability is typically the ratio of successful requests to total requests, and multi-window burn-rate alerts compare that ratio over short and long windows to detect fast and slow consumption of the error budget.
Recording rules precompute expensive expressions at regular intervals and store the results as new series. They make dashboards faster and alerting rules simpler, and they are the standard remedy when a query aggregates thousands of series on every refresh.
Common PromQL mistakes
Many PromQL errors produce results that look plausible but are wrong. The following table lists the mistakes that experienced engineers check first when a graph or alert behaves unexpectedly.
| Mistake | Consequence | Correction |
|---|---|---|
| Graphing a raw counter | Ever-rising line with resets | Wrap it in rate or increase |
| Applying rate after sum | Counter resets corrupt the result | Rate first, then sum |
| Rate window shorter than two scrapes | Gaps or empty results | Use at least four times the scrape interval |
| Averaging percentiles across instances | Statistically invalid latency | Aggregate buckets, then apply histogram_quantile |
| Unbounded label selectors | Slow queries, memory pressure | Filter early and watch metric cardinality |
Performance problems usually trace back to high metric cardinality rather than to PromQL syntax. A label holding user IDs or request paths can create millions of series, and no query optimization compensates for a data model that should never have stored them.
In everyday language
Modern software constantly records numbers about itself: how many requests it handled, how many failed, how long each one took. PromQL is the language engineers use to ask questions of those numbers.
A typical question sounds like this: how many errors per second did the checkout service have over the last five minutes, compared with all its requests? PromQL turns that sentence into a short formula. The answer feeds charts, warnings and reports that tell a team whether its systems are healthy.
Seen in the real world
A platform team runs about 40 microservices on Kubernetes and has a service level objective of 99.9 percent successful requests over 30 days for its public API. Previously, alerts fired on high CPU usage, which caused frequent pages that rarely matched customer impact.
The team defined an error ratio with PromQL by dividing the rate of responses with status 5xx by the rate of all responses, aggregated by service, and stored it through recording rules at 5-minute and 1-hour windows. A burn-rate alert pages the on-call engineer only when both windows exceed 14.4 times the allowed error rate, which indicates that the monthly budget would be exhausted in roughly two days.
Within two months, pages dropped by about 70 percent while every real customer-facing outage still triggered an alert, and the same PromQL expressions powered the Grafana dashboard used in weekly reliability reviews.