How to visualize current CPU usage of a pod with Grafana

cpu-usagegrafanakubernetesmonitoringprometheus

Is there a way to visualize current CPU usage of a pod in a K8S cluster?

I tried different Prometheus metrics like namespace_pod_name_container_name:container_cpu_usage_seconds_total:sum_rate and other similar ones, but I always get average value for the last 5 minutes, so I have "stairs" on my graphs even if workload raises abruptly (please, see the screenshot).

At the same time, kubectl top pod shows more precise values, so when I raise workload to 100%, it starts showing 100% utilization in a few seconds.

Is there a way to provide these values to Grafana?

Thanks!

Best Answer

If I understand you correctly you can try the query below:

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

This would track the CPU usage of each of the pods and the results would be shown in 1 minute rate. Of course you can adjust the [1m] parameter (and others) as you need.

Please let me know if that helped.