Kubernetes metric expression

19 views
Skip to first unread message

sri L

unread,
Nov 22, 2023, 8:10:35 AM11/22/23
to Prometheus Users
Hi all,
I am looking for metric expression for CPU usage of pod in percentage in kubernetes. I found following expression from the blog but the result is coming in seconds instead of percentage. Kindly suggest how we can get CPU utilization in percentage, Thanks

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)

Bryan Boreham

unread,
Nov 22, 2023, 11:04:49 AM11/22/23
to Prometheus Users
rate(container_cpu_usage_seconds_total) is in cpu-seconds per second, or cpus.
container_spec_cpu_quota  /  container_spec_cpu_period is also in cpus.
Therefore the ratio is unitless, just a fraction.

To see it as a percentage, multiply by 100.

Bryan
Reply all
Reply to author
Forward
0 new messages