Swap monitoring Script
The script below can be run from a crontab, It will grep the status of swap memory in a server and email it to you if the ratio of swap used exceeds 40%.
I think this is very useful !
FREE=`/usr/sbin/swap -s |awk '{print $11}'|cut -f1 -d 'k' `
USED=`/usr/sbin/swap -s |awk '{print $9}'|cut -f1 -d 'k' `
TOTAL=`expr $FREE + $USED`
LEFT=`expr $TOTAL - $USED`
RATIO=`expr $USED \* 100 / $TOTAL`
echo `date` > /tmp/swap.log
echo "Space left : $LEFT " >>/tmp/swap.log
echo "Total space : $TOTAL " >>/tmp/swap.log
echo "" >> /tmp/swap.log
echo "$RATIO% of the available swap space is utilized" >> /tmp/swap.log
echo "" >> /tmp/swap.log
ps -e -o user,pid,ppid,vsz,rss,time,comm | sort -k 4rn | head -15 >> /tmp/swap.log
echo "" >> /tmp/swap.log
/opt/freeware/bin/top >> /tmp/swap.log
#change the threshold here:
if [ $RATIO -ge 40 ]
then mailx -s "Swap issue on `hostname`" fayoubi@gmail.com < /tmp/swap.log
fi
rm /tmp/swap.log
-Thanks for reading
