Last active
January 2, 2016 18:39
-
-
Save kennedyj/8344663 to your computer and use it in GitHub Desktop.
See memory being used by a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
getmem() { | |
name=$1 | |
image=$(docker ps | grep $name | awk '{print $2}') | |
short=$(docker ps | grep $name | awk '{print $1}') | |
long=$(docker inspect $short | grep ID | awk '{print $2}' | sed 's~[",]~~g') | |
rss=$(grep total_rss /sys/fs/cgroup/memory/lxc/$long/memory.stat | awk '{print $2}') | |
mem=$(echo "($rss/1024)/1024" | bc) | |
echo "$image is using $mem MB" | |
} | |
name=$1 | |
if [ -z $name ]; | |
then | |
echo "get all containers" | |
for id in $(docker ps | grep -v '^CONTAINER ID' | awk '{print $1}') | |
do | |
getmem $id | |
done | |
else | |
getmem $name | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment