k8s cadvisor cpu seconds to cpu cores

2,445 views
Skip to first unread message

ishu...@gmail.com

unread,
Dec 30, 2021, 5:46:00 AM12/30/21
to Prometheus Users
Hi All,

I have a question on understanding cpu usage of a pod that is running in k8s cluster. 

Cadvisor is only reporting the cpu seconds container_cpu_usage_seconds_total. While I want to know how to convert to cpu cores(as the pods are scheduled in terms of cpu cores) and thus alerting for high cpu usage. 

I quite could not get, how to convert the cpu seconds reported to cpu cores.

I have read https://www.robustperception.io/understanding-machine-cpu-usage but cadvisor is not reporting idle time. so anyone who solved and let me know could be great help.

Thanks
Eswar 

Brian Candler

unread,
Dec 30, 2021, 6:10:57 AM12/30/21
to Prometheus Users
rate(container_cpu_usage_seconds_total[2m])   # choose your interval as appropriate to cover at least 2 sampling periods

The rate of increase of container_cpu_usage_seconds_total gives you the number of CPU-seconds consumed per second.

If this value is 1, then you are effectively using 1 whole core (or something equivalent, e.g. 1/4 each of 4 cores).  If the value is 2, then you are effectively using 2 whole cores.  And so on.

You haven't shown any examples of your metric: you say there's no "idle" label, but not what other labels you have.  Therefore if there are multiple metrics for the same pod, you may need to sum over them.  See:
Reply all
Reply to author
Forward
0 new messages