How to calculate containers’ cpu usage in kubernetes with prometheus as monitoring?

This I’m using to get CPU usage at cluster level:

sum (rate (container_cpu_usage_seconds_total{id="https://stackoverflow.com/"}[1m])) / sum (machine_cpu_cores) * 100

I also track the CPU usage for each pod.

sum (rate (container_cpu_usage_seconds_total{image!=""}[1m])) by (pod_name)

I have a complete kubernetes-prometheus solution on GitHub, maybe can help you with more metrics: https://github.com/camilb/prometheus-kubernetes

enter image description here

enter image description here

Leave a Comment