简体   繁体   English

Memory Docker容器的使用

[英]Memory usage of Docker containers

I am using Docker to run some containerized apps.我正在使用 Docker 来运行一些容器化应用程序。 I am interested in measuring how much resources they consume (as far as regarding CPU and Memory usage).我有兴趣测量他们消耗了多少资源(就 CPU 和 Memory 使用而言)。

Is there any way to measure the resources consumed by Docker containers like RAM & CPU usage?有什么方法可以测量 Docker 容器消耗的资源,例如 RAM 和 CPU 使用率?

Thank you.谢谢你。

You can get this from docker stats eg: 你可以从docker stats得到这个,例如:

$ docker stats --no-stream
CONTAINER           CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O             PIDS
6b5c0fcfa7d4        0.13%               2.203 MiB / 4 MiB   55.08%              5.223 kB / 648 B    102.4 kB / 876.5 kB   3

Update: See @Adrian Mouat's answer below as docker now supports docker stats ! 更新:请参阅下面的@Adrian Mouat的答案,因为docker现在支持docker docker stats

There isn't a way to do this that's built into docker in the current version. 在当前版本中,没有办法在docker中内置这个。 Future versions will support this via an api or plugin. 未来版本将通过api或插件支持此功能。

It does look like there's an lxc project that you should be able to use to track CPU and Memory. 它看起来像是一个lxc项目,你应该能够用它来跟踪CPU和内存。

Also, you can read resource metrics directly from cgroups. 此外,您可以直接从cgroups读取资源指标。 See example below (I am running on Debian Jessie and docker 1.2 ) 请参阅下面的示例(我在Debian Jessiedocker 1.2上运行)

> docker ps -q
afa03c363af5
> ls /sys/fs/cgroup/memory/system.slice/ | grep docker-afa03c363af5
docker-afa03c363af54815d721d938e01fe4cb2debc4f6c15ebff1851e20f6cde3ae0e.scope
> cd docker-afa03c363af54815d721d938e01fe4cb2debc4f6c15ebff1851e20f6cde3ae0e.scope
> cat memory.usage_in_bytes
4358144
> cat memory.limit_in_bytes
1073741824

Kindly check out below commands for getting CPU and Memory usages of docker containers:-请查看以下命令以获取 docker 容器的 CPU 和 Memory 用法:-

docker status container_ID #to check single container resources docker status container_ID #查看单个容器资源

在此处输入图像描述

for i in $(docker ps -q); do docker stats $i --no-trunc --no-stream; echo "--------";done for i in $(docker ps -q); do docker stats $i --no-trunc --no-stream; echo "--------";done #to check/list all container resources for i in $(docker ps -q); do docker stats $i --no-trunc --no-stream; echo "--------";done #检查/列出所有容器资源在此处输入图像描述

docker stats --all #to check all container resources live docker stats --all #实时检查所有容器资源在此处输入图像描述

docker system df -v #to check storage related information docker system df -v #查看存储相关信息在此处输入图像描述

  • Memory usage of docker containers Memory docker容器的使用

    docker system df -v docker 系统 df -v

  • local docker space本地 docker 空间

    df -kh df-kh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM