Docker Community Forums

Share and learn in the Docker community.

Docker stats vs top not equal

docker

(Alarmikus) #1

Hello,
Maybe someone know why Memory usage is different using Top and Docker stats?
45% top VS15% docker stats

System:
Ubuntu 14.04.5 LTS (3.16)
Docker version 17.09.0-ce

docker stats

CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c11b2741a274 2.81% 1.836GiB / 11.74GiB 15.64% 17.5GB / 18.8GB 92MB / 24.6kB 0
88a2b3cce09e 257.52% 521.5MiB / 11.74GiB 4.34% 1.01TB / 365GB 190MB / 5.51GB 0
1b2984fdf0cb 16.51% 436.9MiB / 11.74GiB 3.64% 218GB / 1.01TB 24.1GB / 870GB 0
fe7ad3936125 0.02% 11.49MiB / 11.74GiB 0.10% 1.04kB / 0B 34MB / 8.19kB 0

docker@docker-01:~$ top
top - 10:31:44 up 22:43, 2 users, load average: 4.95, 5.08, 5.11
Tasks: 208 total, 6 running, 202 sleeping, 0 stopped, 0 zombie
%Cpu(s): 83.3 us, 7.8 sy, 0.0 ni, 6.0 id, 1.2 wa, 0.0 hi, 1.8 si, 0.0 st
KiB Mem: 12305260 total, 9539128 used, 2766132 free, 387676 buffers
KiB Swap: 1044476 total, 0 used, 1044476 free. 3875460 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                      
 2063 syslog    20   0 2040876 1.797g   7700 S   3.4 15.3  39:00.57 nginx-debug                                                                                                                                  
 1977 root      20   0 2023304 1.796g  10664 S   0.0 15.3   0:26.49 nginx-debug                                                                                                                                  
 2066 syslog    20   0 2031736 1.788g   2596 S   0.0 15.2   0:22.37 nginx-debug                                                                                                                                  
 1817 999       20   0 1133428 467968  17040 S  33.9  3.8 397:08.95 mysqld

(Siju Oommen George) #2

From your doc stats output, the containers alone consume 2.785 GiB

The top command shows memory consumption by these containers + memory consumption by the docker daemon itself + memory consumption by what ever else is running in the system.

htteps://serverfault.com/questions/85470/meaning-of-the-buffers-cache-line-in-the-output-of-free
gives a detailed explanation of how memory is displayed in Linux

Hope this helps :slight_smile:


(Alarmikus) #3

Hello George,

Thanks for reply, I read the link.
But still do not clear for me why top show 45% Memory usage of system, but docker stats show 15.64% one container.


(Siju Oommen George) #4

Please show the outputs of

  1. top
  2. free -m

–Siju


(Alarmikus) #5

Hello Siju,
I appreciate your answer. Please output:
docker@docker-01:~$ top

top - 10:19:54 up 7 days, 22:30,  1 user,  load average: 0.00, 0.01, 0.05
Tasks: 201 total,   1 running, 200 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
 KiB Mem:  12305260 total, 10763312 used,  1541948 free,   612844 buffers
 KiB Swap:  8388604 total,    13468 used,  8375136 free.  3663204 cached Mem

docker@docker-01:~$ free -m

             total       used       free     shared    buffers     cached
Mem:         12016      10510       1505         28        598       3577
-/+ buffers/cache:       6335       5681
Swap:         8191         13       8178

docker@docker-01:~$ docker stats

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
c11b2741a274        0.08%               1.827GiB / 11.74GiB   15.57%              75.6GB / 83.5GB     101MB / 10.4MB      0
88a2b3cce09e        0.23%               345.3MiB / 11.74GiB   2.87%               156GB / 47.6GB      9.06MB / 880MB      0
1b2984fdf0cb        0.05%               478.8MiB / 11.74GiB   3.98%               935GB / 4.29TB      109GB / 3.74TB      0
fe7ad3936125        0.02%               11.75MiB / 11.74GiB   0.10%               19.2kB / 0B         34.3MB / 8.19kB     0