#!/bin/ksh
TEMPFILE=$XYMONTMP/memstat.tmp
COLOUR=green
ALERT=0 # 1= alert on high usage
YELLOW=75
RED=90
USE_SUDO=yes
date > $TEMPFILE
echo >> $TEMPFILE
if [ "$USE_SUDO" = "yes" ]
then
# You are probably on Solaris 11, and/or have set up sudo to grant Xymon user elevated access.
sudo $XYMONCLIENTHOME/ext/getmemstat.ksh | egrep -v "temporary|^Guest" \
| sed "s/ZFS Metadata/ZFS_Metadata/g" \
| sed "s/ZFS File Data/ZFS /g" > $TEMPFILE.data
else
# We can assume you have another way of granting elevated access, like setUID
$XYMONCLIENTHOME/ext/getmemstat.ksh | egrep -v "temporary|^Guest" \
| sed "s/ZFS Metadata/ZFS_Metadata/g" \
| sed "s/ZFS File Data/ZFS /g" > $TEMPFILE.data
fi
cat $TEMPFILE.data >> $TEMPFILE
if [ $ALERT -eq 1 ]
then
cat $TEMPFILE.data | egrep "^Kernel|^Anon|^Exec" | cut -c52-56 | while read a
do
if [ $a -gt $YELLOW -a "$COLOUR" = "green" ]
then
COLOUR=yellow
else
[ $a -gt $RED ] && COLOUR=red
fi
done
fi
echo '' >> $TEMPFILE
cat $TEMPFILE.data | egrep -v -- "-----|Summary|^$|^Total|^Physical" \
| sed "s/^Free //g" \
| sed "s/[(|)|%]//g" \
| awk '{ print $1" : "$NF }' >> $TEMPFILE
echo '
' >> $TEMPFILE
rm $TEMPFILE.data
$XYMON $XYMSRV "status $MACHINE.memstat $COLOUR $(cat $TEMPFILE)"
rm $TEMPFILE
#!/bin/ksh
echo "::memstat" | mdb -k