🗓️ 27102025 0000

PROMETHEUS RANGE FUNCTIONS

Core Concept: Quick reference for range functions - see prometheus_range_function_calculations for detailed formulas and examples.

When to Use

Range functions transform arrays of samples from range selectors [5m] into single values. Understanding prometheus_time_series_basics and prometheus_range_function_calculations is essential for knowing what these actually calculate.

Rate & Counter Functions

FunctionWhat It DoesWhen To Use
rate()Per-second average rateDEFAULT - counters (requests, errors)
irate()Instant rate (last 2 points)Spike detection (use sparingly)
increase()Total increase in range"How many X in last Y?"
TIP

Use rate() for most cases. Only use irate() for catching spikes < 1 minute.

Aggregation Functions

FunctionWhat It DoesWhen To Use
avg_over_time()AverageSmooth noisy gauges
min_over_time() / max_over_time()Min/MaxFind peaks/troughs
sum_over_time()SumTotal accumulated value
count_over_time()Data point countDetect gaps

Statistical Functions

FunctionWhat It DoesWhen To Use
quantile_over_time(φ, v)Percentiles (p50, p95, p99)Latency analysis
stddev_over_time()Standard deviationDetect instability

Change Detection

FunctionWhat It DoesWhen To Use
delta()First - last valueGauge changes (can be negative)
changes()Times value changedFlapping detection
resets()Counter resetsService restart detection

Prediction Functions

FunctionWhat It DoesWhen To Use
deriv()Per-second derivativeTrend analysis (gauges)
predict_linear(v, t)Future value in t secondsCapacity planning

Time Ranges

RangeWhen
[5m]Default - good balance
[1m]Real-time alerts
[1h]Dashboards
[24h]Daily patterns
WARNING

Range must be ≥ 2x scrape interval (if scrape = 30s, use ≥ 1m)

Key Rules

  • rate() for counters, deriv()/delta() for gauges
  • rate() handles counter resets, delta() doesn't
  • Range must be ≥ 2x scrape interval
  • Use prometheus_data_types to understand which functions work with which metric types

References