PromQL
Prometheus provides a functional query language called PromQL (Prometheus Query Language) that lets the user select and aggregate time series data in real time.
When you send a query request to Prometheus, it can be an instant query, evaluated at one point in time, or a range query at equally-spaced steps between a start and an end time. PromQL works exactly the same in each case; the range query is just like an instant query run multiple times at different timestamps.
In the Prometheus UI, the "Table" tab is for instant queries and the "Graph" tab is for range queries.
Other programs can fetch the result of a PromQL expression via the HTTP API.
Examples
Query functions
Some functions have default arguments, e.g. year(v=vector(time()) instant-vector). This means that there is one argument v which is an instant vector, which if not provided it will default to the value of the expression vector(time()).
- abs()
- absent()
- absent_over_time()
- ceil()
- changes()
- clamp()
- clamp_max()
- clamp_min()
- day_of_month()
- day_of_week()
- day_of_year()
- days_in_month()
- delta()
- deriv()
- double_exponential_smoothing()
- exp()
- floor()
- histogram_avg()
- histogram_count() and histogram_sum()
- histogram_fraction()
- histogram_quantile()
- histogram_stddev() and histogram_stdvar()
- hour()
- idelta()
- increase()
- info()
- Limitations
Trigonometric Functions
The trigonometric functions work in radians. They ignore histogram samples in the input vector.
- acos(v instant-vector) - calculates the arccosine of all float samples in v
- acosh(v instant-vector) - calculates the inverse hyperbolic cosine of all float samples in v
- asin(v instant-vector) - calculates the arcsine of all float samples in v
- asinh(v instant-vector) - calculates the inverse hyperbolic sine of all float samples in v
- atan(v instant-vector) - calculates the arctangent of all float samples in v
- atanh(v instant-vector) - calculates the inverse hyperbolic tangent of all float samples in v
- cos(v instant-vector) - calculates the cosine of all float samples in v
- cosh(v instant-vector) - calculates the hyperbolic cosine of all float samples in v
- sin(v instant-vector) - calculates the sine of all float samples in v
- sinh(v instant-vector) - calculates the hyperbolic sine of all float samples in v
- tan(v instant-vector) - calculates the tangent of all float samples in v
- tanh(v instant-vector) - calculates the hyperbolic tangent of all float samples in v
The following are useful for converting between degrees and radians:
- deg(v instant-vector) - converts radians to degrees for all float samples in v.
- pi() - returns pi.
- rad(v instant-vector) - converts degrees to radians for all float samples in v.