Tuesday, May 26, 2015

Docker: check the memory used by docker containers at specific host


for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do echo "" && docker ps | grep $line | awk '{printf $NF" "}' && echo -e "\nmemory usage: $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB" && echo max memory usage: $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.max_usage_in_bytes` / 1024 / 1024 ))MB ; done