Skip to main content
In this lesson we cover PromQL operators — how to transform metric values, compare them, combine series, and control evaluation order. PromQL supports several operator categories:
  • Arithmetic operators — basic math (addition, subtraction, multiplication, division, modulo, power)
  • Comparison operators — ==, !=, >, <, >=, <=
  • The bool modifier — returns numeric boolean results (1/0)
  • Logical operators — or, and, and unless
  • Operator precedence and associativity — how PromQL orders evaluation
These building blocks let you filter, transform, and compose expressive queries for visualization and alerting.

Arithmetic operators

Arithmetic operators perform element-wise math on instant vectors (the values returned by a query).
A dark-themed presentation slide titled "Arithmetic Operators" that explains basic math operations. It includes a table listing symbols (+, −, *, /, %, ^) with descriptions like Addition, Subtraction, Multiplication, Division, Modulo, and Power.
Common uses:
  • Add/subtract constants to values.
  • Convert units (e.g., bytes to KB/MB).
  • Combine metrics with arithmetic expressions.
Examples Fetch a single metric value:
Example instant-vector output:
Add a constant:
Convert bytes to kilobytes:
Example output after dividing by 1024:
When you perform arithmetic on a metric, the resulting expression does not retain the original metric name. The expression returns a vector of values (with labels) — not a new series with the original metric name. Keep this in mind when composing further expressions or alert rules.

Comparison operators and the bool modifier

Comparison operators filter or compare time series by value: Example dataset:
Filter to values greater than 100:
Result:
The bool modifier changes comparison semantics: instead of dropping series that don’t match, it returns numeric 1 (true) or 0 (false) for each input element. This is especially useful for alerting rules where you want a numeric indicator of a condition.
Use bool when you need a per-series numeric true/false (1/0) result — for example, to feed into alerting conditions or further numeric expressions.
Example dataset for filesystem availability:
Find filesystems with less than 1000 bytes available and return 1/0:
Result:
Values of 1 indicate true (condition met); 0 indicates false.

Operator precedence and associativity

When an expression contains multiple operators, PromQL evaluates them according to operator precedence. Operators with higher precedence are evaluated first. Operators at the same precedence are left-associative (evaluated left to right), except exponentiation (^), which is right-associative.
A slide titled "Binary operator precedence" showing a ranked list of PromQL binary operators (1: ^; 2: *, /, %, atan2; 3: +, -; 4: ==, !=, <=, <, >=, >; 5: and, unless; 6: or). A highlighted note below states operators on the same level are left-associative and that ^ is right-associative.
Examples:
  • 2 * 3 % 2 is evaluated as (2 * 3) % 2 because * and % share precedence and are left-associative.
  • 2 ^ 3 ^ 2 is evaluated as 2 ^ (3 ^ 2) because ^ is right-associative.

Logical operators: or, and, unless

PromQL provides three logical operators that operate on instant vectors and combine or filter series by label matching and value presence:
  • and — returns elements present on both sides (intersection).
  • or — returns elements present on either side (union).
  • unless — returns elements from the left-hand side that do not have a matching element on the right-hand side (left-side subtraction).
A dark-themed slide titled "Logical Operators" showing the statement "PromQL has 3 logical operators" with three checked items: OR, AND, and UNLESS, each marked by a colored checkmark.
Examples Return time series greater than 1000 and less than 3000 (both conditions must be true for the same series):
Given:
and result:
or — return series less than 500 or greater than 70000:
Result:
unless — return series greater than 1000 unless they are greater than 30000 (exclude series that also match the right-hand side):
Given:
unless result:
(Series /home and /opt are excluded because they match the right-hand side condition > 30000.)

Combined practical examples

Filter filesystems between 6,000,000 and 1,000,000,000 bytes:
Example result:
Find filesystems either under 6,000,000 bytes or over 1,000,000,000 bytes:

Tips and references

  • Always remember arithmetic expressions produce a value vector without the original metric name — use explicit labels or relabeling if you need a specific metric name in follow-up processing.
  • Use bool for numeric indicators in alert thresholds.
  • Review operator precedence when combining many operators; the precedence image above is a handy reference.
Links and further reading

Watch Video