% cpu utilization

34 views
Skip to first unread message

Venkata Bhagavatula

unread,
Jul 13, 2021, 4:48:05 AM7/13/21
to Prometheus Users
Hi All,

I am trying to add an alert rule, which raises an alert when %utilization of container cpu usage is above a certain threshold. Our scrape interval is 1min

Following is expression, i started with:
sum(rate (container_cpu_usage_seconds_total{container=~'.+'}[4m])*100) by (namespace,container,pod) > 80 

Here we saw "sum(irate (container_cpu_usage_seconds_total{container=~'.+'}[2m])*100) by (namespace,container,pod) > 80", it is showing values as greater than 100.  Below is the snapshot:
image.png

Later after referring to the below ticket: https://github.com/google/cadvisor/issues/2026, changed the expression to the below:
(sum(rate(container_cpu_usage_seconds_total{image!="", container!="POD"}[4m])) by (pod, container, namespace) / sum(container_spec_cpu_quota{ image!="", container!="POD"}/container_spec_cpu_period{ image!="", container!="POD"}) by (pod, container,namespace) ) * 100 > 80

Here also we see the values showing greater than 100. Can you please let us know how to get the percentage of cpu utilization per container?

Thanks n Regards,
Chalapathi.

Ben Kochie

unread,
Jul 13, 2021, 5:36:08 AM7/13/21
to Venkata Bhagavatula, Prometheus Users
Containers can use more than one CPU at a time, and they can exceed requests, but not limits. But also not all Kubernetes containers have requests/limits, which means you can't alert on those.

Here's one way you can represent this:

sum by (pod,container,namespace) (
  rate(container_cpu_usage_seconds_total[4m])
)
/
sum by (pod,container,namespace) (
  kube_pod_container_resource_limits_cpu_cores
  or
  kube_pod_container_resource_requests_cpu_cores
)
* 100

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CABXnQPvDNC-pR%2BiMZMTa9tUv7BPA8OQhcttkiUYe%2BBfEqua7CQ%40mail.gmail.com.

Venkata Bhagavatula

unread,
Jul 15, 2021, 11:09:34 AM7/15/21
to Ben Kochie, Prometheus Users
Thanks Ben

Reply all
Reply to author
Forward
0 new messages