Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 136 lines (119 sloc) 4.503 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#!/bin/sh

TYPE="node"
NC_STAT="/var/run/eucalyptus/nc-stats"
SC_STAT="/var/log/eucalyptus/sc-stats.log"
WALRUS_STAT="/var/log/eucalyptus/walrus-stats.log"
GMETRIC="`which gmetric 2> /dev/null`"
DEBUG="N"
EUCALYPTUS="/"

usage () {

echo "$0 [options]"
echo
echo " -help this message"
echo " -type [nc|walrus|sc] which stat file to look for"
echo " -d <eucalyptus_dir> where eucalyptus is installed"
echo
}

# let's parse the command line
while [ $# -gt 0 ]; do
if [ "$1" = "-h" -o "$1" = "-help" -o "$1" = "?" -o "$1" = "--help" ]; then
usage
exit 0
fi

if [ "$1" = "-type" ]; then
if [ -z "$2" ]; then
echo "Need the type!"
exit 1
fi
TYPE="$2"
shift; shift
continue
fi
if [ "$1" = "-debug" ]; then
DEBUG="Y"
shift
continue
fi
if [ "$1" = "-d" ]; then
if [ -z "$2" ]; then
echo "Need eucalyptus directory!"
exit 1
fi
EUCALYPTUS="$2"
shift; shift
continue
fi
usage
exit 1
done

# some checks
if [ -z "$GMETRIC" ]; then
echo "Cannot find gmetric: do you have ganglia installed?"
exit 1
fi
if [ ! -e "$EUCALYPTUS/etc/eucalyptus/eucalyptus.conf" ]; then
echo "Is Eucalyptus installed in $EUCALYPTUS?"
exit 1
fi
if [ "$TYPE" = "nc" ]; then
# let's check we have the stat file
if [ ! -e ${EUCALYPTUS}${NC_STAT} ]; then
echo "Cannot find NC stat file!"
exit 1
fi

# number of running VMs
NUM="`grep ^id: ${EUCALYPTUS}${NC_STAT}|wc -l`"
# memory available to VMs
M_AVAIL="`grep ^memory ${EUCALYPTUS}${NC_STAT}|sed \"s;memory.*MB: [[:digit:]]*/\([[:digit:]]*\)/[[:digit:]]*;\1;\"`"
# memory used by VMs
M_USED="`grep ^memory ${EUCALYPTUS}${NC_STAT}|sed \"s;memory.*MB: [[:digit:]]*/[[:digit:]]*/\([[:digit:]]*\);\1;\"`"
# cores available to VMs
C_AVAIL="`grep ^cores ${EUCALYPTUS}${NC_STAT}|sed \"s;cores.*: [[:digit:]]*/\([[:digit:]]*\)/[[:digit:]]*;\1;\"`"
# cores used by VMs
C_USED="`grep ^cores ${EUCALYPTUS}${NC_STAT}|sed \"s;cores.*: [[:digit:]]*/[[:digit:]]*/\([[:digit:]]*\);\1;\"`"
# disk available to VMs
D_AVAIL="`grep ^disk ${EUCALYPTUS}${NC_STAT}|sed \"s;disk.*GB: [[:digit:]]*/\([[:digit:]]*\)/[[:digit:]]*;\1;\"`"
# disk used by VMs
D_USED="`grep ^disk ${EUCALYPTUS}${NC_STAT}|sed \"s;disk.*GB: [[:digit:]]*/[[:digit:]]*/\([[:digit:]]*\);\1;\"`"

[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "Running VMs" -v $NUM -t int16
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs available memory" -v $M_AVAIL -t int32 -u MB
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs used memory" -v $M_USED -t int32 -u MB
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs available cores" -v $C_AVAIL -t int32
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs used cores" -v $C_USED -t int32
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs available disks" -v $D_AVAIL -t int32 -u GB
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "VMs used disks" -v $D_USED -t int32 -u GB

$GMETRIC -n "Running VMs" -v $NUM -t int16
$GMETRIC -n "VMs available memory" -v $M_AVAIL -t int32 -u MB
$GMETRIC -n "VMs used memory" -v $M_USED -t int32 -u MB
$GMETRIC -n "VMs available cores" -v $C_AVAIL -t int32
$GMETRIC -n "VMs used cores" -v $C_USED -t int32
$GMETRIC -n "VMs available disks" -v $D_AVAIL -t int32 -u GB
$GMETRIC -n "VMs used disks" -v $D_USED -t int32 -u GB

elif [ "$TYPE" = "sc" ]; then
# let's check we have the stat file
if [ ! -e ${EUCALYPTUS}${SC_STAT} ]; then
echo "Cannot find SC stat file!"
exit 1
fi

V_USED="`tail -n 1 ${EUCALYPTUS}${SC_STAT}|sed \"s/.*Volumes: \([[:digit:]]*\).*/\1/\"`"
S_USED="`tail -n 1 ${EUCALYPTUS}${SC_STAT}|sed \"s/.*Space Used: \([[:digit:]]*\)/\1/\"`"

[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "Volumes" -v $V_USED -t int16
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "Volumes disk usage" -v $S_USED -t int16

$GMETRIC -n "Volumes" -v $V_USED -t int16
$GMETRIC -n "Volumes disk usage" -v $S_USED -t int16

elif [ "$TYPE" = "walrus" ]; then
# let's check we have the stat file
if [ ! -e ${EUCALYPTUS}${WALRUS_STAT} ]; then
echo "Cannot find wlarus stat file!"
exit 1
fi

B_USED="`tail -n 1 ${EUCALYPTUS}${WALRUS_STAT}|sed \"s/.*Buckets: \([[:digit:]]*\).*/\1/\"`"
S_USED="`tail -n 1 ${EUCALYPTUS}${WALRUS_STAT}|sed \"s/.*Space Used: \([[:digit:]]*\)/\1/\"`"

[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "Buckets" -v $B_USED -t int16
[ "$DEBUG" = "Y" ] && echo $GMETRIC -n "Buckets disk usage" -v $S_USED -t int16

$GMETRIC -n "Buckets" -v $B_USED -t int16
$GMETRIC -n "Buckets disk usage" -v $S_USED -t int16
else
echo "Unknown type!"
exit 1
fi
Something went wrong with that request. Please try again.