Skip to main content
This lesson dives into PromQL operators — how to perform arithmetic, compare and filter series, combine expressions using logical set operators, and understand operator precedence. These concepts are essential for crafting precise Prometheus queries and reliable alerting rules.

Arithmetic operators

Arithmetic operators perform numeric operations on instant vectors or scalars: addition (+), subtraction (-), multiplication (*), division (/), modulo (%), and power (^).
The image lists arithmetic operators along with their descriptions, providing basic math functions such as addition, subtraction, multiplication, division, modulo, and power.
Operator quick reference: Example — convert bytes to kibibytes (KiB). node_memory_active_bytes reports memory in bytes; divide by 1024 to convert to KiB:
Arithmetic on a metric produces a computed vector — the result does not preserve the original metric name. The result contains the same labels but no original metric identifier. This is expected PromQL behavior.
Dividing by 1000 converts to decimal kilobytes (kB); dividing by 1024 converts to kibibytes (KiB). Choose based on the unit system you want.

Comparison operators

Comparison operators filter or compare metric values: ==, !=, >, <, >=, <=.
The image displays a table of comparison operators with their descriptions, including equal, not equal, greater than, less than, greater or equal, and less or equal.
Comparison operator examples: Example — filter network flags greater than 100:

The bool modifier

The bool modifier changes a comparison from a filter (dropping non-matching series) into a 0/1 indicator for each input series. This is especially useful for alerting rules where you need an on/off numeric signal rather than a filtered set. Example — check which filesystems have less than 1000 bytes available:
A 1 indicates the comparison evaluated to true; 0 indicates false. Use these boolean vectors directly in alert expressions or downstream calculations.

Operator precedence

PromQL evaluates expressions according to operator precedence. Higher-precedence operators are evaluated before lower-precedence ones. Operators on the same precedence level are left-associative (evaluated left-to-right), except exponentiation (^) which is right-associative.
The image explains the precedence order of binary operators in PromQL, listing them from highest to lowest, with additional information on operator associativity.
Examples:
  • 2 * 3 % 2 is evaluated as (2 * 3) % 2 (left-to-right).
  • 2 ^ 3 ^ 2 is evaluated as 2 ^ (3 ^ 2) (right-to-left).
Always use parentheses when in doubt to make your intent explicit and avoid surprises.

Logical operators: or, and, unless

PromQL provides three set-level logical operators that operate on series sets: or, and, and unless.
The image lists PromQL's three logical operators: OR, AND, and UNLESS, each with a colored checkmark.
Behavior overview: Examples
  • Return filesystems with available bytes greater than 1000 and less than 3000 (intersection):
  • Union: filesystems with available bytes less than 500 or greater than 70000:
  • unless (left set difference): return series greater than 1000 unless they are greater than 30000:

Putting it together: quick interactive examples

Combine arithmetic, comparison, and logical operators to build targeted queries. Example — add 50 to node_arp_entries:
Example — filter filesystems greater than 6_000_000 bytes:
Add a second filter to exclude very large filesystems (greater than 1_000_000_000 bytes):
or example — values less than 6_000_000 OR greater than 10_000_000_000:

Summary

  • Arithmetic operators (+, -, *, /, %, ^) perform numeric transformations and unit conversions.
  • Comparison operators (==, !=, >, <, >=, <=) filter series; use bool to emit 0/1 results for alerting.
  • Operator precedence determines evaluation order; use parentheses to make expressions explicit.
  • Logical set operators (and, or, unless) combine or subtract series sets to build complex queries.
Further reading and references:

Watch Video