In the previous article, we looked at how to get CPU usage as a percentage for a Kubernetes pod in Grafana.
Now we're going one level deeper and displaying the actual CPU usage in millicores (mCPU).
Why Use Millicores?
CPU percentage is great for dashboards and quick health checks, but once you start troubleshooting performance issues, it can become a little less intuitive.
Seeing something like 137% CPU usage doesn't immediately tell you how much CPU the pod is actually consuming. You often end up doing mental math to convert that percentage into CPU cores.
Using millicores (mCPU) gives you an exact CPU consumption value, making it much easier to compare against Kubernetes CPU requests and limits.
To display CPU usage in millicores, create a Time Series panel in Grafana and use the following PromQL query:
How the Query Works
container_cpu_usage_seconds_total→ Total CPU time consumed by a container.rate(...[1m])→ Calculates the average CPU usage rate over the last minute.sum(... by (pod))→ Adds together the CPU usage of all containers belonging to the same pod.* 1000→ Converts CPU cores into millicores (mCPU).
Configure the panel as shown above and Grafana will display CPU usage in millicores (mCPU), closely matching the values returned by kubectl top pod.
#grafana #prometheus #monitoring
0 Comments