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

Aggregation Operators

Combine time series using sum, avg, max, min, count, and other aggregation functions.

Aggregation Operators

You'll learn how to combine and summarize multiple time series into single, meaningful metrics using PromQL aggregation functions.

When monitoring infrastructure, you often collect the same metric from many sources—CPU usage from dozens of pods, request counts from multiple instances, or memory consumption across regions. Aggregation operators let you roll up these individual time series into summary values that answer questions like "What's my total request rate?" or "What's the average memory usage across my cluster?"

Core Aggregation Functions

Prometheus provides several aggregation operators that work across time series:

  • sum() – Adds values together (total requests, combined bandwidth)
  • avg() – Calculates the mean (average CPU, typical response time)
  • max() / min() – Finds highest/lowest values (peak memory, minimum replicas)
  • count() – Counts the number of time series (how many instances are up)
  • stddev() / stdvar() – Measures variance (detecting outliers)
  • topk() / bottomk() – Selects top or bottom N series

How They Work

Aggregation operators take an instant vector (the result of a label selector) and collapse it by removing labels. You specify which labels to preserve using by or which to remove using without:

sum(http_requests_total) by (job)

This sums all request counters, grouping results by the job label—giving you per-service totals instead of per-instance counts.

avg(node_memory_used) without (instance)

This averages memory across all instances, removing the instance-specific detail.

The Analogy

Think of aggregation like looking at sales data: you can view every individual transaction (raw time series), or summarize by store, region, or product category (aggregated metrics). Aggregation gives you the "big picture" view.

Key Takeaway:
Aggregation operators like sum, avg, max, min, and count combine multiple time series into summary metrics, letting you answer cluster-wide questions instead of instance-level details.