Blog Archives

 

Jun
23

Swap Watch

Posted in Linux by Admin

0


Every so occasionally a process or two (I’m looking at you, apache) gets a little out of hand and swallows up a crapload of RAM.  Well, those of us on a budget rent servers with very little available memory and running out of it can quickly bring your server to a halt.  Throw this little script into a 15 minute cronjob and you’ll get emailed when your server starts using more than 20% of its swap. #!/bin/sh free -m | grep Swap | while read output; do swap=$(echo $output | awk '{print $2}' ) used=$(echo $output | awk '{ print $3 }' ) freed=$(echo $output | awk '{ print $4 }' ) echo "Swap : $swap" echo "Used : $used" echo "Free : $freed" usep=`expr $used \* 100 / $swap` echo $usep if [ $usep -ge 20 ]; then echo "Swap Usage Alert Total Swap: \"$swap\" Used: \"$used ($usep%)\" Free: \"$freed\" on $(hostname) as on $(date)" | mail -s "Alert: Swap Usage space $usep%"
Read More...


Switch to our mobile site