Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker stats shows zero memory usage even for running containers

Tags:

java

docker

jvm

I have two containers ran by Docker Swarm:

# docker ps
CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS              PORTS               NAMES
18f1e7d79f5b        default/image1:latest               "/bin/sh -c 'java ..."   12 hours ago        Up 12 hours                             image1.1.x56zz152kmqtqpxzle5nkbs8r
11d1f05fcff1        default/image2:latest               "java -cp /app/sca..."   13 hours ago        Up 13 hours                             image2.1.ljztzeeh8i5r6ebr3n4hcj45e

$ docker stats --no-stream
CONTAINER           CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
18f1e7d79f5b        0.92%               0B / 0B             0.00%               648B / 0B           0B / 0B             0
11d1f05fcff1        0.91%               0B / 0B             0.00%               39.9MB / 26.9MB     51.2MB / 0B         0

Host OS is Debian Jessie. There are JVM applications in both containers. Why does docker stats show zero memory usage? Should I configure my Java apps somehow to be able to see memory usage in docker stats? Is there some other way to check memory usage?

like image 486
Evgeny Veretennikov Avatar asked Aug 07 '17 07:08

Evgeny Veretennikov


People also ask

How does Docker stats calculate memory usage?

On Linux, the Docker CLI reports memory usage by subtracting cache usage from the total memory usage. The API does not perform such a calculation but rather provides the total memory usage and the amount from the cache so that clients can use the data as needed.

How do I check the memory of a Docker container?

You can look it up with docker inspect or docker ps --no-trunc . Putting everything together to look at the memory metrics for a Docker container, take a look at the following paths: /sys/fs/cgroup/memory/docker/<longid>/ on cgroup v1, cgroupfs driver. /sys/fs/cgroup/memory/system.

Does Docker consume memory?

Docker does not apply memory limitations to containers by default. The Host's Kernel Scheduler determines the capacity provided to the Docker memory. This means that in theory, it is possible for a Docker container to consume the entire host's memory.

How much memory does a Docker container use?

The maximum amount of memory the container can use. If you set this option, the minimum allowed value is 6m (6 megabytes). That is, you must set the value to at least 6 megabytes.


1 Answers

It is quite possible that memory cgroup accounting is not enabled in your kernel (which is a common problem that others have hit as well over time on Debian/Ubuntu based installs).

Can you verify with docker info or the output from the daemon that you aren't seeing messages like the following, nicely summarized in this blog post: Debian Jessie w/Docker? If so, the fix is also listed there, as well as in the GitHub issue I linked in the first sentence. There is also a section in the install documentation about enabling cgroup memory accounting although it only mentions Ubuntu and not Debian.

like image 109
Phil E Avatar answered Nov 14 '22 23:11

Phil E