Course contentsShow
← Cloud and Infrastructure
Lesson 1972 of 2,98942. Observability - MetricsFree lesson

Prediction and Trending Functions

Forecast metric behavior using predict_linear() and deriv() for capacity planning and alerting.

Prediction and Trending Functions

What you'll learn: How to forecast future metric behavior and detect trends using PromQL's predict_linear() and deriv() functions for proactive capacity planning and alerting.

Why Forecast Metrics?

Monitoring what's happening now is essential, but predicting what will happen lets you act before problems strike. Will your disk fill up next week? Is CPU usage climbing steadily? Prediction functions turn historical metric data into actionable foresight.

The Core Functions

predict_linear() extrapolates a range vector into the future using simple linear regression. Think of it like drawing a trend line through recent data points and extending it forward.

# Predict disk usage 4 hours from now
predict_linear(node_filesystem_avail_bytes[1h], 4*3600)

This examines the last hour of available disk space and forecasts where it'll be in 14,400 seconds (4 hours). Perfect for alerting: "At this rate, you'll run out of disk by 3pm."

deriv() calculates the per-second rate of change (derivative) of a gauge metric over time. It tells you how fast something is changing right now.

# How quickly is memory usage increasing per second?
deriv(node_memory_Active_bytes[5m])

A positive value means increasing, negative means decreasing. Combine with thresholds to catch accelerating problems early.

Practical Application

Use predict_linear() in alerts for capacity planning:

predict_linear(node_filesystem_avail_bytes[1h], 24*3600) < 0

This fires when you'll run out of disk space within 24 hours based on current trends.

Use deriv() to detect sudden behavioral shifts—like detecting when memory leaks start accelerating.

Key Takeaway: predict_linear() forecasts future metric values for capacity planning, while deriv() measures the rate of change to detect trends—both enable proactive alerting before issues become critical.