Log “docker stats” to a file

Tag: docke I needed to log the output of docker stats for a few of my containers in order to compare. The following snippet will log container stats to a file (stats.txt), and to stdout, every 1 second. Tweak it to your liking.

1
while true; do docker stats --no-stream | tee --append stats.txt; sleep 1; done

docker stats --format 的默认字符串:"table {{.ID}}\\t{{.Name}}\\t{{.CPUPerc}}\\t{{.MemUsage}}\\t{{.MemPerc}}\\t{{.NetIO}}\\t{{.BlockIO}}\\t{{.PIDs}}"

Empirical Study on Swarm Leaerning 中用的:"table {{.Name}},{{.CPUPerc}},{{.MemUsage}},{{.NetIO}},{{.BlockIO}},{{.PIDs}}"

1
while true; do docker stats --no-stream --format "table {{.Name}},{{.CPUPerc}},{{.MemUsage}},{{.NetIO}},{{.BlockIO}},{{.PIDs}}" | tee --append stats.txt; sleep 10; done