Monitor Kubernetes Pod CPU Consumption Usage in Milicores

In the previous article, we looked at how to get CPU usage in percentage for a Kubernetes pod in Grafana.

Now we’re going one level deeper and pulling out the actual CPU usage in millicores.

Why bother with millicores?

CPU percentage is fine for dashboards and quick glances, but once you start debugging real issues, it can get a bit annoying. Seeing something like 137% CPU usage doesn’t immediately translate into something intuitive when you are in a deep troubleshooting session. You end up doing mental math to figure out what that actually means in real CPU terms. When things get messy, millicores just make life easier.

To achieve this millicores reading, create a Time Series panel in Grafana and use the following PromQL query:

sum(rate(container_cpu_usage_seconds_total{namespace=~"^$namespace$",container!="", pod!=""}[1m])) by (pod)* 1000

Here's a breakdown on this query:

  • container_cpu_usage_seconds_total → total CPU time a container has used
  • rate(...[1m]) → turns that into “CPU per second” over the last minute
  • sum(... by (pod)) → adds up all containers inside the same pod
  • * 1000 → converts cores into millicores (mCPU)




Configure the graph as above and it should return CPU usage in millicores, similar to what you would see when running kubectl top pod.

#grafana #prometheus

0 Comments