Kubernetes pod cpu usage percentage

8/22/2018

I try to calculate how many percent cpu of limits pod use. I try to use this expression:

sum(irate(container_cpu_usage_seconds_total{cluster!="production",namespace="devops"}[2m])) by (pod_name) / kube_pod_container_resource_limits_cpu_cores{cluster!="production",namespace="devops"}

But it show 0 series. Left and right sided expressions return scalar values.

-- Алексей Калинин
kubernetes
prometheus

1 Answer

11/9/2018

I suppose the problem is that not every pod container has resource limits of CPU cores. Therefore you get two vectors of different length and expression fails without an error message.

You can verify my guess the following way:

count(sum(irate(container_cpu_usage_seconds_total{cluster!="production",namespace="devops"}[2m])) by (pod_name))

and:

count(kube_pod_container_resource_limits_cpu_cores{cluster!="production",namespace="devops"})

These two values should be the same, if not - here is the reason your query doesn't work.

-- mibrl12
Source: StackOverflow