prometheusgrafanapromqlkubernetes-metrics

Is there any way to represent POD CPU usage in terms of CPU cores using prometheus metrics


I just want to represent the CPU metrics of a POD as below

enter image description here

I am able to represent the CPU requests and limits in terms of CPU cores which are directly available through prometheus scrape metrics.

But in prometheus I don't see any direct metric to get the CPU cores used by a POD so, Can someone give me a work around or a way to represent the CPU usage of a POD in the terms of CPU cores.

Thanks in advance


Solution

  • The query you are looking for is this one:

    sum(rate(container_cpu_usage_seconds_total{container_name!="POD"}[1m])) by (pod_name)
    

    Here the explanation (from within to out, as Prometheus calculates this query):

    For further information about Prometheus in Kubernetes you can read this blog here: https://blog.freshtracks.io/a-deep-dive-into-kubernetes-metrics-part-3-container-resource-metrics-361c5ee46e66