Check Resources Used by each Docker Container

半城伤御伤魂 提交于 2021-02-04 12:25:26

问题


How do you check the amount of resources (CPU, memory etc) being used by each Docker container that is running on the (Ubuntu) server?


回答1:


you have docker stats see the doc

http://docs.docker.com/reference/commandline/stats/

for example you can do

docker stats $(docker ps -q)

(that will display the id of the containers or if you want the name, see

Is there any way to display container names in docker stats?

, you can also you docker top if you are interested in a specific container

http://docs.docker.com/reference/commandline/top/




回答2:


this displays real-time resource usage across all running containers on a single docker engine or entire swarm cluster

docker stats $( docker ps --format '{{ .Names }}' )

sample output

CONTAINER              CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/O           PIDS
dockercoins_webui_1    0.66%               19.23 MB / 16.72 GB   0.12%               309.8 kB / 605.8 kB   61.44 kB / 0 B      9
dockercoins_worker_1   4.01%               13.18 MB / 16.72 GB   0.08%               834.5 kB / 920.5 kB   98.3 kB / 0 B       1
dockercoins_rng_1      0.70%               19.03 MB / 16.72 GB   0.11%               412.8 kB / 441.7 kB   2.388 MB / 0 B      1
dockercoins_hasher_1   0.59%               19.67 MB / 16.72 GB   0.12%               477.6 kB / 372.7 kB   1.438 MB / 0 B      22
dockercoins_redis_1    0.18%               6.877 MB / 16.72 GB   0.04%               178.8 kB / 80.11 kB   5.771 MB / 0 B      3
web                    0.02%               11.06 MB / 16.72 GB   0.07%               87.19 kB / 648 B      0 B / 0 B           1
db                     0.01%               14.11 MB / 16.72 GB   0.08%               87.84 kB / 648 B      0 B / 9.851 MB      7



回答3:


You can try and use docker-scout (not free though) or cAdvisor (Apache license).

It seems better than:

  • install the agent and its dependencies directly on the host (it's better as a container)
  • Running an agent in every container is bad (lots of overhead)

cAdvisor (Container Advisor) provides container users an understanding of the resource usage and performance characteristics of their running containers.
It is a running daemon that collects, aggregates, processes, and exports information about running containers.
Specifically, for each container it keeps resource isolation parameters, historical resource usage, histograms of complete historical resource usage and network statistics

sudo docker run \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --publish=8080:8080 \
  --detach=true \
  --name=cadvisor \
  google/cadvisor:latest



回答4:


I suggest using Google cAdvisor - cAdvisor monitors resource usage and performance characteristics for Docker containers. Its free and provides all the resource usage statistics for each container that you need.

If you want to store the cAdvisor performance statistics for visualization, analytics and capacity planning, you can use ATSD. You can visualize the statistics for each container or each host, there are also consolidated portals for multiple hosts and portals for custom sets of containers sorted by role/type.



来源:https://stackoverflow.com/questions/31153394/check-resources-used-by-each-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!