Skip to content

Instantly share code, notes, and snippets.

@kennedyj
Last active January 2, 2016 18:39
Show Gist options
  • Save kennedyj/8344663 to your computer and use it in GitHub Desktop.
Save kennedyj/8344663 to your computer and use it in GitHub Desktop.
See memory being used by a docker container
#!/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