Aggregation Functions
This module covers PromQL aggregation functions, which allow you to summarize data across multiple time series. You will learn how to group metrics, calculate sums, averages, and other statistical functions.
Understanding Aggregation
Aggregation functions reduce multiple time series into a single time series by grouping them and applying a function (sum, average, max, etc.) to each group.
Basic Aggregation Syntax
<aggregation-function>([parameter,] <vector expression>) [without|by (<label list>)]
Sum Aggregation
Statistical Aggregations
PromQL provides several statistical aggregation functions.
Standard Deviation
The stddev() function calculates the standard deviation:
# Standard deviation of memory usage per namespace
stddev(container_memory_usage_bytes) by (namespace)
Variance
The stdvar() function calculates the variance:
# Variance of memory usage per namespace
stdvar(container_memory_usage_bytes) by (namespace)
Quantiles
The quantile() function calculates quantiles over grouped time series:
# 95th percentile of memory usage per namespace
quantile(0.95, container_memory_usage_bytes) by (namespace)
# 50th percentile (median) of CPU usage per node
quantile(0.50, container_cpu_usage_seconds_total) by (node)
Common quantile values:
* 0.50 - Median
* 0.90 - 90th percentile
* 0.95 - 95th percentile
* 0.99 - 99th percentile
Top-K and Bottom-K
Combining Aggregations
Common Aggregation Patterns in OpenShift
Total Resource Usage per Namespace
# Total CPU usage per namespace
sum(container_cpu_usage_seconds_total) by (namespace)
# Total memory usage per namespace
sum(container_memory_usage_bytes) by (namespace)
Best Practices
Choose Appropriate Aggregation
-
Use
sum()for additive metrics (counters, bytes) -
Use
avg()for metrics where you want the average -
Use
max()ormin()when you need extremes -
Use
quantile()for percentile analysis
Summary
In this module, you learned:
-
How aggregation functions work in PromQL
-
Using
byandwithoutclauses for grouping -
Common aggregation functions:
sum(),avg(),min(),max(),count() -
Statistical functions:
stddev(),stdvar(),quantile() -
Top-K and bottom-K functions
-
Combining aggregations with rate functions
-
Common aggregation patterns for OpenShift
-
Best practices for effective aggregation
In the next module, you will learn advanced query patterns including rate functions, subqueries, and logical operators.