1

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.

shashank patel
  • 137
  • 2
  • 6
  • 1
    There is an entry that shows combined CPU usage for the whole pod, your `sum()` combines it with per-container measures. Same as with memory usage in this answer: https://stackoverflow.com/questions/69281327/why-container-memory-usage-is-doubled-in-cadvisor-metrics/69282328#69282328 – anemyte Apr 03 '22 at 11:29

1 Answers1

0

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.

  • This works : sum (rate (container_cpu_usage_seconds_total{image!=""}[1m])) by (pod_name) This gives 2x values : sum (rate (container_cpu_usage_seconds_total{container_name!="POD",pod!=""}[1m])) by (pod_name) Very strange. – shashank patel Apr 02 '22 at 20:08
  • I have never come across this container_name, pod combination. But I am glad that the solution works for you..! – Sai Prasad Sabeson Apr 03 '22 at 00:58
  • 1
    Great, but why are the metrics duplicated, with and without an image tag? – gdabski Aug 09 '22 at 15:11