Skip to main content

🗓️ 27102025 0000

PROMETHEUS RANGE FUNCTIONS

Core Concept: Aggregate time series data over time windows to compute rates, averages, and statistics.

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

rate() vs irate(): 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 > scrape interval (if scrape = 30s, use ≥ 1-2m)

Common Patterns

Rate vs Increase

  • rate(metric[5m]) * 300 = increase(metric[5m])
  • Use rate() for per-second rates, increase() for total counts

Smoothing vs Responsiveness

  • Longer ranges = smoother but slower to react
  • rate(metric[10m]) - smooth, slow
  • irate(metric[1m]) - responsive, noisy

Percentiles

  • Histogram: histogram_quantile(0.95, rate(http_duration_bucket[5m])) - accurate
  • Gauge: quantile_over_time(0.95, http_duration_seconds[5m]) - approximate

Key Rules

  • rate() for counters, deriv()/delta() for gauges
  • rate() handles counter resets, delta() doesn't
  • Range must be > scrape interval

References