Paris
Paris

Reputation: 6771

Memory usage of Docker containers

I am using Docker to run some containerized apps. I am interested in measuring how much resources they consume (as far as regarding CPU and Memory usage).

Is there any way to measure the resources consumed by Docker containers like RAM & CPU usage?

Thank you.

Upvotes: 85

Views: 96826

Answers (5)

linux.cnf
linux.cnf

Reputation: 807

Kindly check out below commands for getting CPU and Memory usages of docker containers:-

docker stats container_ID #to check single container resources

enter image description here

for i in $(docker ps -q); do docker stats $i --no-trunc --no-stream ; echo "--------";done #to check/list all container resources enter image description here

docker stats --all #to check all container resources live enter image description here

docker system df -v #to check storage related information enter image description here

Upvotes: 9

Johan Potgieter
Johan Potgieter

Reputation: 55

This is the command I use:

 docker stats CONTAINER_ID --no-stream --format "{{.Container}}: {{.MemUsage}}"

replace the CONTAINER_ID with the container id you find by using this command:

docker container ps

Upvotes: 4

johncosta
johncosta

Reputation: 3807

Update: See @Adrian Mouat's answer below as docker now supports docker stats!

There isn't a way to do this that's built into docker in the current version. Future versions will support this via an api or plugin.

It does look like there's an lxc project that you should be able to use to track CPU and Memory.

Upvotes: 18

Adrian Mouat
Adrian Mouat

Reputation: 46548

You can get this from docker stats e.g:

$ 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

Upvotes: 132

Viacheslav Kovalev
Viacheslav Kovalev

Reputation: 1745

Also, you can read resource metrics directly from cgroups. See example below (I am running on Debian Jessie and docker 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

Upvotes: 6

Related Questions