PromQL: Operators
A PromQL operator is a symbol that combines or compares values. Arithmetic changes numbers, and comparison tests them.
Add ten to a counter
Arithmetic adds ten to the single matching value.
http_requests_total{route="/",status="200"} + 10Keep only large counters
The comparison keeps the three series above 50 and drops the rest.
http_requests_total > 50Ask for a true or false answer
The bool modifier returns 1 because 80 is greater than 50.
http_requests_total{route="/",status="200"} > bool 50Example
curl -s -G "http://localhost:19102/api/v1/query" --data-urlencode 'query=up == 0'Key points
- An arithmetic operator like + adds a number to every value in a result.
- A comparison operator like > tests every value against a number.
- A comparison without bool keeps only the series that pass the test.
- A comparison without bool returns the original values, not true or false.
- The bool modifier makes a comparison return 1 for true and 0 for false.
- A comparison that matches nothing returns an empty result, not an error.
In this example, the comparison asks which targets are down. The result is empty, so no target is down. A comparison without bool filters instead of answering, so an empty result is good news here and not a broken query.
Note
An empty result means no series passed, so check the query before assuming the system is healthy.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does http_requests_total > 50 return?