Story #3826

Updated by Tom Clegg over 5 years ago

(TC) sysfs provides traffic statistics. I tried this in a docker container, after doing a few pings:

# head /sys/devices/virtual/net/*/statistics/*_bytes
==> /sys/devices/virtual/net/eth0/statistics/rx_bytes <==

==> /sys/devices/virtual/net/eth0/statistics/tx_bytes <==

==> /sys/devices/virtual/net/lo/statistics/rx_bytes <==

==> /sys/devices/virtual/net/lo/statistics/tx_bytes <==

In order to This does require that we run crunchstat inside docker (hence blocked by #3824), instead of monitoring statistics from outside using cgroups. Fortunately this is easy and greatly simplifies crunchstat (e.g., call runtime.NumCPU() instead of reading and parsing @/sys/fs/cgroup/..../cpuset/cpus@, and read these stats from outside predictable parts of @/sys@ instead of requiring the container, use the "setns" syscall caller to set your network namespace to match the netns specify parts of any process inside the container. Close the filehandle after each use, though: otherwise it will keep the container alive after all processes exit. cgroup path).

docker run --volume=/usr/bin/crunchstat:/usr/bin/crunchstat ... /usr/bin/crunchstat {command...}

See (summary: parse /proc/stat)