Search code examples
dockernetworkingnetwork-traffic

Docker stat network traffic


I want ask 2 question about docker stats

for example

NAME                              CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
container_1                       1.52%               11.72MiB / 7.388GiB   0.15%               2.99GB / 372MB      9.4MB / 0B          9

in this situation net i/o statement 2.99GB / 372MB how much time reflected in that?

for one hour? or all of time?

and how can check docker container network traffic for an hour or minute?

i would appreciate if you any other advice. thank you


Solution

  • This blog explains the network io of the docker stats command

    Displays total bytes received (RX) and transmitted (TX).

    If you need finer grained access, the blog also suggests to use the network pseudo files on your host system.

    $ CONTAINER_PID=`docker inspect -f '{{ .State.Pid }}' $CONTAINER_ID`
    $ cat /proc/$CONTAINER_PID/net/dev
    

    To your second part: I'm not aware of any build-in method to get the traffic over the specific period, others might correct me. I think the easiest solution is to poll one of the two interfaces and calculate the differences yourself.