Skip to main content
We’ve covered all four metric types; now it’s time to learn PromQL. PromQL (Prometheus Query Language) converts time-series metrics into actionable results used for alerting and dashboards (for example in Grafana). Learning PromQL lets you turn raw metrics into meaningful observability signals: rates, percentiles, SLIs, and aggregated views across services. A quick note on scope:
This lesson/article provides practical patterns you’ll use every day. It is not intended to be comprehensive Prometheus certification preparation.

Basic queries

The simplest PromQL expression is just the metric name. This returns all time series with that metric over the selected time range:
When you enter a metric name in Prometheus, Grafana, or the Prometheus expression browser, the result is rendered as a set of time series.

Filtering with label selectors

To narrow results, use label selectors. Label selectors support exact matches, negative matches, and regular expressions:
Example sample metrics (for illustration):

Metric types (quick reference)

Working with counters: rate() and range vectors

Counters are cumulative and always increase. To show a meaningful value, compute the rate of change over a lookback window using rate():
  • The expression http_requests_total[5m] is a range vector.
  • rate() returns an instant vector representing the per-second increase computed over the last 5 minutes for each time series.
Always use rate() (or irate() when appropriate) for counters when you want a meaningful per-second rate. Plotting raw cumulative counters will produce unusable graphs.

Aggregation

To aggregate across time series, use aggregation operators like sum, avg, min, max, etc. Aggregations are commonly wrapped around rate():
  • Total request rate across all label dimensions:
  • Request rate aggregated by endpoint (keeps endpoint label, drops others):
If you forget by(...), the aggregation removes all label dimensions and returns a single scalar per instant.

Arithmetic and SLIs

PromQL supports arithmetic on instant vectors. For example, compute a 2xx success rate percentage over the last 5 minutes:
This computes (successful requests) / (total requests) * 100.

Histograms and percentiles

Histogram bucket series are cumulative counters representing counts of observations that fell into each bucket boundary. To compute per-bucket rates, apply rate() and then aggregate by the le (less-or-equal) label:
A slide showing a histogram titled "Histogram_quantile()" that buckets HTTP request counts by request duration. The bars are tallest at 50ms and progressively smaller at 100ms, 250ms, 500ms and +INF.
Example histogram metric exposition:
To estimate latency percentiles (P50, P95, P99) from bucketed histograms, use histogram_quantile() with the aggregated bucket rates:
Notes on histogram_quantile():
  • It uses linear interpolation across bucket counts to approximate percentiles.
  • Accuracy depends on your bucket boundaries and their density. You cannot recover exact values beyond the bucket granularity — only an approximation.
When designing buckets, choose boundaries that capture the SLO-relevant regions (e.g., many tight buckets around your target latency). This improves percentile accuracy where it matters.

Common PromQL functions and operators

Practical tips

  • Use rate() with a window appropriate for your traffic volume: high-volume services can use shorter windows (1m), low-volume may need longer windows (5m or 15m) to smooth spikes.
  • When aggregating across instances or jobs, explicitly control the label dimensions with by(...) or without(...) to avoid accidental double-counting.
  • For alerting, prefer more conservative window sizes and consider increase() for absolute counts over a time window.
Common Helm charts are often used to deploy Prometheus and Grafana together.

Watch Video