Accurate Docker Container CPU Utilization Monitoring
Monitoring Docker container CPU utilization can sometimes be misleading, especially when using traditional tools like top. In this guide, we explore why the top command might not give you accurate readings inside Docker containers and suggest effective alternatives for precise monitoring.
Why ‘Top’ is Inaccurate for Docker Container CPU Utilization Monitoring
The top command is widely used to report system-wide resource usage on Linux. However, when used inside Docker containers, top often produces inaccurate results, particularly in terms of CPU utilization. This issue can lead to misinterpretations about the container’s performance.
To illustrate, let’s conduct a simple test to highlight this problem.

CPU Stress Test in a Docker Container
We’ll run a Docker container with an Ubuntu image and intentionally stress the CPU to observe the reported CPU usage. The following command initiates the container:
docker run -ti --rm --name tmp-limit --cpus="1" -m="1G" ubuntu bash -c 'apt update; apt install -y stress; stress --cpu 4'
What this command does:
- Launches a Docker container using the Ubuntu image.
- Limits the container to 1 CPU core and 1 GB of memory.
- Runs a CPU stress test inside the container using the
stresstool.
Host-Level CPU Utilization
Next, let’s examine the CPU utilization reported by the top command on the host machine:
As seen in the image above, the host reports 25% CPU utilization, which is correct. The host has 4 CPU cores, and since the container is limited to 1 core, full utilization of that core results in 25% CPU usage on the host.
Container-Level CPU Utilization
Now, let’s check the top command output inside the container:
As shown, the container’s top command reports 25% CPU utilization, identical to the host’s reading. This is misleading, as the container is limited to using only 1 CPU core, which it is fully utilizing. The container’s CPU utilization should be shown as 100%.
Although the top command accurately lists the container’s processes, it fails to reflect the correct CPU usage within the container.
How to Accurately Monitor Docker Container CPU Utilization
To get an accurate view of Docker container CPU utilization, consider using the following tools:
1. Docker Stats
The docker stats command provides resource usage metrics for each running container. This tool is ideal for obtaining accurate CPU statistics. Below is an example of the output from the docker stats command:
docker stats
As seen above, the docker stats command shows the container’s CPU usage, which in this case is 100.64%. However, docker stats must be run from the host, as it’s not available inside the container. Passing the Docker socket into the container is possible but introduces security risks.
2. cAdvisor (Container Advisor)
Another option is cAdvisor, which is a tool built specifically for monitoring Docker containers. cAdvisor collects and displays resource utilization data at the container level, offering more detailed insights than the top command.
3. yCrash
For more in-depth analysis, consider yCrash, a tool that provides detailed container-level metrics and application-level insights. yCrash can analyze logs, memory dumps, and garbage collection data, offering comprehensive root cause analysis reports.
Conclusion for Docker Container CPU Utilization
While the top command can provide useful information on system resource utilization, its accuracy diminishes within Docker containers, particularly when it comes to CPU usage. As demonstrated, top reports 25% CPU utilization inside the container, even though the container fully utilizes its allocated CPU.
For accurate Docker container CPU utilization monitoring, tools like docker stats, cAdvisor, and yCrash offer more reliable metrics. These tools can help optimize performance and ensure that your containerized applications are running efficiently.
At ZippyOPS, we offer consulting, implementation, and managed services for DevOps, DevSecOps, DataOps, Cloud, AIOps, Microservices, Infrastructure, and Security. For expert advice and solutions, visit our services page, explore our products, and check out our solutions.
To learn more, visit our YouTube channel for demos, or contact us at sales@zippyops.com.



