Metric definition
container_cpu_usage_seconds_total
- CPU usage time in seconds of a specific container, as the name suggests. A rate on top of this will show how many CPU seconds a container uses per second.
container_spec_cpu_period
- Denotes the period in which container CPU utilization is tracked. I understood this as the duration of a CPU "cycle". Typically 100000
microseconds for docker containers.
container_spec_cpu_quota
- How much CPU time your container has for each cpu_period in microseconds—results from multiplying a "CPU unit" by the container_spec_cpu_period
. You only have it if you define a limit for your container.
container_spec_cpu_quota / container_spec_cpu_period
will actually tell you how many CPU seconds you have in each second, then the CPU usage of the container could be container_cpu_usage_seconds_total
/(container_spec_cpu_quota / container_spec_cpu_period).
One sample
sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name)
/sum(container_spec_cpu_quota{name!~".*prometheus.*", image!="", container_name!="POD"}
/container_spec_cpu_period{name!~".*prometheus.*", image!="", container_name!="POD"}) by (pod_name, container_name)
Source:
Average CPU % usage per container