Exercises
Exercise 1: Basic Aggregations
Practice using basic aggregation functions to summarize metrics.
Step 1: Sum Aggregation
Write a query to calculate the total memory usage across all containers in your cluster:
sum(container_memory_usage_bytes)
Execute this query in Prometheus and observe the result.
Exercise 2: Min, Max, and Count
Practice using min, max, and count aggregation functions.
Step 1: Maximum Memory Usage
Find the maximum memory usage per namespace:
max(container_memory_usage_bytes) by (namespace)
Which namespace has the highest maximum memory usage?
Exercise 3: Statistical Aggregations
Practice using statistical functions like quantiles and standard deviation.
Step 1: Median Memory Usage
Calculate the median (50th percentile) memory usage per namespace:
quantile(0.50, container_memory_usage_bytes) by (namespace)
Exercise 4: Top-K and Bottom-K
Practice identifying the top and bottom resource consumers.
Step 1: Top 5 Memory Consumers
Find the top 5 containers by memory usage:
topk(5, container_memory_usage_bytes)
Note which containers are using the most memory.
Exercise 5: Combining Aggregations
Practice combining multiple aggregation functions and filters.
Step 1: Average of Maximums
Calculate the average of the maximum memory usage per pod, grouped by namespace:
avg(max(container_memory_usage_bytes) by (namespace, pod)) by (namespace)
This shows the average peak memory usage per pod in each namespace.
Exercise 6: OpenShift-Specific Aggregations
Practice writing aggregation queries specific to OpenShift metrics.
Step 1: Pod Count per Namespace
Count the number of pods in each namespace:
count(kube_pod_info) by (namespace)
Verification
After completing these exercises, verify your understanding:
-
Can you calculate sums, averages, and counts across time series?
-
Can you use min, max, and quantile functions?
-
Can you identify top and bottom resource consumers?
-
Can you combine multiple aggregation functions?
-
Can you group metrics by multiple labels?
If you can answer yes to all these questions, you are ready to proceed to the next module on advanced query patterns.