In order to adjust my pods limits and requests, I want to know their median CPU usage. But I can't understand how to get this value.
One of my queries is:
max_over_time(
avg by (my_label) (
rate(container_cpu_usage_seconds_total{labels}[3m])
* on (pod) group_left (my_label)
kube_pod_labels{labels}
)
[1d:])
How can I get only one median value, not the array? In this example, it will be something like ~0.9
Any help is appreciated.
Update.
After some research, I've made this query:
quantile_over_time(0.99,
avg by (my_label) (
rate(container_cpu_usage_seconds_total{labels,cpu="total"}[3m])
* on (pod) group_left (my_label)
kube_pod_labels{labels})
[30d:15m])
The 0.5-quantile is known as the median. The 0.95-quantile is the 95th percentile.
For my purpose median isn't suitable, thus I decided to use 0.99-quantile.
This solves my problem, but if anyone can add something or comment my decision it would be great.
