Permalink
Browse files

Add memory usage calculator to octo status.

  • Loading branch information...
darron committed Jan 21, 2014
1 parent aa2b540 commit 4e9276d8ea2efa7e0203637ef86f15e5a5fe542d
Showing with 34 additions and 2 deletions.
  1. +34 −2 bin/octo
View
@@ -5,16 +5,48 @@ SRC_DIR="/home/git/src/"
PUBLIC_IP=$(curl -s http://ipv4.icanhazip.com)
DOMAIN_SUFFIX="$PUBLIC_IP.xip.io"
get_short_container_id ()
{
docker ps | grep "octohost/$1" | cut -d ' ' -f 1
}
get_long_container_id ()
{
docker inspect $1 | jq '.[0].ID' | cut -d '"' -f 2
}
get_memory_usage ()
{
cat /sys/fs/cgroup/memory/lxc/$1/memory.usage_in_bytes
}
reformat_bytes ()
{
(( size = $1/1024/1024 ))
echo "($size MB)"
}
show_memory_usage ()
{
ID=$(get_short_container_id $1)
LONG=$(get_long_container_id $ID)
MEMORY=$(get_memory_usage $LONG)
MB=$(reformat_bytes $MEMORY)
echo -n "$MB: "
}
case "$1" in
status)
cd $SRC_DIR
for i in *.git; do
site=`basename $i .git`
echo -n "$site "
show_memory_usage $site
if (wget -S -t 1 -T 2 --delete-after -qO- http://$site.$DOMAIN_SUFFIX 2>&1 | grep -q "HTTP/1.1 200 OK"); then
echo -e "$site: \e[32mOK\e[0m"
echo -e "\e[32mOK\e[0m"
else
echo -e "$site: \e[31mDOWN\e[0m"
echo -e "\e[31mDOWN\e[0m"
fi
done
;;

0 comments on commit 4e9276d

Please sign in to comment.