
Quick reference: common function categories
Math-based functions
These functions operate on each sample value in an instant vector.
Example (instant vector values and results shown inline):
Date and time functions
Prometheus exposes functions to extract parts of the current evaluation time. These are useful for calendar-aware calculations, scheduling logic in queries, or tagging alerts with time components. Key functions:time()— current Unix time in seconds (float).minute(),hour(),day_of_week(),day_of_month(),days_in_month(),month(),year()— return the specified component of the current evaluation timestamp.
Converting between scalars and vectors
scalar(v)— Converts an instant vectorvcontaining exactly one sample into a scalar value. Ifvcontains more than one element, the result isNaN.vector(s)— Converts a scalarsinto an instant vector containing a single sample (useful for combining scalar thresholds with vector operations).
Sorting
Sort instant vectors by the sample values.sort(v)— ascending order.sort_desc(v)— descending order.
Presence checks: absent / present (and their _over_time variants)
These functions help detect missing series or whether a series has samples inside a specified range.absent(v)— Ifvcontains any elements, returns an empty vector. If no elements exist, returns a single-element vector with the value1and the labels taken from the expression.absent_over_time(v[range])— Returns1for each series that has no samples inside the specified range; returns nothing if at least one sample exists.present_over_time(v[range])— Returns1for each series that has at least one sample in the range; otherwise returns nothing for that series.
Refer to the Prometheus documentation under Querying → Functions for a complete list of functions and their exact semantics.

delta, deriv, exp, etc.). The names tend to be descriptive; trying examples in the Prometheus console is an effective way to learn them.
Counters and rate calculations
Counters are monotonically increasing metrics (e.g., bytes sent, requests served). Plotting the raw counter typically shows a continuously rising line, which is often not as useful as the rate of change.
rate(v[range])— computes the average per-second rate of increase across the provided time range. It uses the first and last sample of the range (accounting for counter resets).irate(v[range])— computes an instant rate using only the last two samples in the range (i.e., slope between the most recent samples).

rate() works (conceptual):
rate(http_errors[1m])divides the series into overlapping 1-minute windows for each evaluation.- If the scrape interval is 15s, each 1-minute window typically contains 4 samples.
- For each window,
rate()computes (last_sample - first_sample) / window_seconds, yielding a per-second average across the window.
irate() differs:
irate(http_errors[1m])still evaluates over the 1-minute range, but uses the last two samples within that window.- Rate is (last - second_last) / time_difference_between_these_two_samples (often equal to the scrape interval, e.g., 15s).

rate() / irate():
- Ensure the chosen range contains enough samples. With a 15s scrape interval,
1myields ~4 samples; more samples improve stability. - When aggregating across series, compute the rate first, then aggregate. This preserves correct counter-reset handling per series.
Example: network transmit bytes
A raw counter such asnode_network_transmit_bytes_total shows cumulative bytes transmitted per interface. The web UI helps explore series and labels.


Summary and references
- PromQL offers many functions across categories: math, time/date, sorting, presence checks, conversions, and counter-rate computations.
- Use
rate()for stable averages (preferred for alerting), andirate()for instant slopes (preferred for responsive graphs). - Always compute rates per series before aggregation to properly handle resets.
- For a complete list and exact semantics, see the Prometheus docs: https://prometheus.io/docs/prometheus/latest/querying/functions/