PromQL Query Language Guide | Generated by AI

Home 2025.11

PromQL (Prometheus Query Language) is a functional query language used to select and aggregate time series data in real time from Prometheus. It supports instant queries (evaluated at a single point in time) and range queries (evaluated at multiple steps over a time range). PromQL expressions can return one of four data types: instant vector, range vector, scalar, or string.


Introduction

PromQL enables users to:

Expressions are evaluated in the Prometheus UI:


Time Series Selectors

Time series selectors define which metrics and labels to retrieve.

Instant Vector Selectors

Selects the most recent sample for each matching time series.

Syntax:

<metric_name>{<label_matchers>}

Examples:

Label Matchers:

Note: {job=~".+"} is valid; {} alone is invalid.


Range Vector Selectors

Selects a range of samples over time.

Syntax:

<instant_selector>[<duration>]

Example:

The range is left-open, right-closed: excludes start time, includes end.


Offset Modifier

Shifts evaluation time forward or backward.

Syntax:

<selector> offset <duration>

Examples:

Must follow selector immediately.


@ Modifier

Evaluates at a specific timestamp.

Syntax:

<selector> @ <timestamp>

Examples:

Can be combined with offset.


Rate and Aggregations

PromQL supports rate and aggregation operators to compute metrics over time or across series.

Rate Function

Calculates per-second average rate of increase.

Example:

rate(http_requests_total[5m])

Used on range vectors.


Aggregation Operators

Apply to instant vectors to combine time series.

Examples:

Aggregation requires matching series; use by or without clauses.


Operators

PromQL supports several operator types.

Arithmetic Operators

Operator Description Example
+ Addition rate(a[5m]) + rate(b[5m])
- Subtraction rate(a[5m]) - rate(b[5m])
* Multiplication http_requests_total * 60
/ Division rate(a[5m]) / rate(b[5m])
% Modulo http_requests_total % 100

Operands must be compatible (same type and shape).


Comparison Operators

Compare two instant vectors.

Operator Description Example
== Equal rate(a[5m]) == rate(b[5m])
!= Not equal rate(a[5m]) != 0
> Greater than http_requests_total > 100
< Less than http_requests_total < 10
>= Greater or equal rate(a[5m]) >= 2
<= Less or equal http_requests_total <= 5

Returns boolean instant vector.


Logical Operators

Combine boolean expressions.

Operator Description Example
and Logical AND rate(a[5m]) > 1 and rate(b[5m]) > 1
or Logical OR rate(a[5m]) > 1 or rate(b[5m]) > 1
unless Except rate(a[5m]) unless rate(b[5m]) > 0

Operands must be boolean vectors of same cardinality.


Functions

PromQL includes built-in functions for transformation and analysis.

Common Functions:

Example:

quantile by (job)(0.95, http_request_duration_seconds_bucket[5m])

See Prometheus Functions Documentation for full list.


HTTP API for Querying

PromQL queries can be sent via HTTP API.

Instant Queries

Endpoint: /api/v1/query

Method: GET

Parameters:

Example:

GET /api/v1/query?query=http_requests_total{job="prometheus"}&time=1609746000

Response: JSON with status, data.result (instant vector or scalar).


Range Queries

Endpoint: /api/v1/query_range

Parameters:

Example:

GET /api/v1/query_range?query=rate(http_requests_total[5m])&start=1609746000&end=1609746600&step=10s

Response: JSON with time series data at each step.


Additional Notes


This guide covers the core of PromQL for beginners to intermediate users. For advanced usage, refer to the Prometheus Querying Basics and linked pages.


Back

x-ai/grok-4-fast

Donate