'prometheus query is showing almost twice value for CPU usage of pod as compared to kubectl top command

Prometheus query that I am running :

sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod!=""}[5m])) by (pod)

this gets me around 450m.

And kubectl top for that particular pod is 225m.

Am I missing something?

Prometheus query is always showing 2x usage.



Solution 1:[1]

Can you check trying as mentioned in https://stackoverflow.com/a/40391872/2310790 ? sum (rate (container_cpu_usage_seconds_total{image!=""}[1m])) by (pod_name)

The kubectl top command returns current CPU and memory usage for a cluster's pods or nodes, or for a particular pod or node if specified. And you had mentioned 5m rate. So i am suspicious if the rates impact your comparison.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sai Prasad Sabeson