How to calculate CPU Utilization in Prometheus?

Viewed 843

I'm new to Prometheus and I got confused about CPU usage metrics. Here are my two cents about CPU usage. (Please correct me if I'm wrong.)

  1. container_cpu_usage_seconds_total = container_cpu_user_seconds_total + container_cpu_system_seconds_total

  2. "cores" = container_spec_cpu_quota / container_spec_cpu_period

  3. This is the pod used CPU time in 1 second:

    rate(container_cpu_usage_seconds_total{image!=""}[1m]) by (pod, namespace)
    
  4. This is the pod allowed CPU time in 1 second:

    (sum(container_spec_cpu_quota{image!=""}/100000) by (pod, namespace))
    
  5. So the utilizations is like:

    rate(container_cpu_usage_seconds_total{image!=""}[1m]) by (pod, namespace) / (sum(container_spec_cpu_quota{image!=""}/100000) by (pod, namespace)) *100
    
  6. But what about those pods don't have spec.cpu.limits? I presume:

    rate(container_cpu_usage_seconds_total{image!=""}[1m]) by (pod, namespace) / CORES_ON_NODE *100
    
0 Answers
Related