In this tutorial, you are going to learn how to use the
docker command to check memory and CPU utilization of your running Docker containers.
Monitoring the health of your containers is crucial for a happy and reliable environment. It’s very important to know if your container is hittings its head against a CPU, Memory, Network, or Block limit, which could be severely degrading it.
The Docker command-line tool has a
stats command the gives you a live look at your containers resource utilization. We can use this tool to gauge the CPU, Memory, Networok, and disk utilization of every running container.
docker stats command to display the status of your containers.
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS e51898f31223 lucid-lemon 0.00% 8.824MiB / 1.944GiB 0.44% 0B / 0B 0B / 0B 7 bc97fe8bcd66 funky-monkey 0.01% 12.05MiB / 1.944GiB 0.61% 0B / 0B 0B / 0B 6 17714162a329 hairy-lemon 0.15% 82.09MiB / 1.944GiB 4.12% 0B / 0B 0B / 0B 28 340bec496cf7 silly-sunshine 0.50% 20.28MiB / 1.944GiB 1.02% 0B / 0B 0B / 0B 32
- Memory is listed under the MEM USAGE / LIMIT column. This provides a snapshot of how much memory the container is utilizing and what it’s memory limit is.
- CPU utilization is listed under the CPU % column.
- Network traffic is represented under the NET I/O column. It displays the outgoing and incoming traffic consumption of a container.
- Storage utilization is shown under the BLOCK I/O column. This show you the amount of reads and writes a container is peforming to disk.
By default, the
docker stats command will display a live stream of stats. If you would prefer outputting the first stats pull results, use the
docker stats --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS e51898f31223 k8s_postgres_postgres-778965fcc7-rc2wj_default_8c8e771b-5b1a-43ee-a9ea-e4af2c1e9319_0 0.00% 8.695MiB / 1.944GiB 0.44% 0B / 0B 0B / 0B 7 bc97fe8bcd66 k8s_wordpress_wordpress-69b59478c4-5lvkk_default_1c19bdb0-2dbc-4c74-9c23-fd1f19c785bc_0 0.01% 12.05MiB / 1.944GiB 0.61% 0B / 0B 0B / 0B 6 17714162a329 k8s_mysql_wordpress-mysql-b5ddc8dd9-4xmqr_default_7694cbcb-ae3e-4bc8-a767-56c4261202f8_0 0.12% 82.09MiB / 1.944GiB 4.12% 0B / 0B 0B / 0B 28 340bec496cf7 k8s_mongodb_mongodb-5d75bdb4d7-7phxp_default_14986721-98a2-4e22-9e4a-94c569b7702e_0 0.47% 20.46MiB / 1.944GiB 1.03% 0B / 0B 0B / 0B 32
docker stats will only output results for running containers. If you would like to output stats for all containers you can use the
--all flags with the command.
docker stats --no-stream -a
You maybe wondering why someone would want to output stats for containers that are not running. One use case is ensuring that a container is no longer running, or displaying a list of stopped containers with the running containers and their stats.
The native Docker tools provide a limited glimps into the health of your containers, but its enough to understand how each one is utilizing system resources. We determine whether a container is CPU or Memory blocked, how much network traffic is hitting or being generated by a container, and how hard it’s disk storage is being hit.