Script to Calculate the SWAP usage on Solaris Server.

Just using the free time in office. On one server we were facing continuous high SWAP usage message. I though of monitoring the SWAP usage for these kind of servers.

Created the below simple and small script to get the SWAP usage of server. I have placed this script in crontab to run at gap of 1 minute.

#!/bin/bash
##Script to calculate the SWAP usage in Solaris
##Created by Vikrant Aggarwal
swapused=`swap -s | awk ‘{print $9}’ | sed s’/.$//’`
swapavailable=`swap -s | awk ‘{print $11}’ | sed s’/.$//’`
swaptotal=`echo $swapused + $swapavailable | bc`
swappercentage=`echo “scale=4;($swapused/$swaptotal)*100″|bc`
date >> /tmp/SwapCalculate.Output
echo “SWAP utilization is: $swappercentage%” >> /tmp/SwapCalculate.Output

To edit the crontab entry issue the below command.

bash-3.2# echo $EDITOR

bash-3.2# export EDITOR=vi
bash-3.2# echo $EDITOR
vi

Added the below entry in crontab where swapcalculation.sh is the name of my script.

* * * * * /tmp/swapcalculation.sh

Excerpt of output from file /tmp/SwapCalculate.Output in which I am redirecting the output.

bash-3.2# cat /tmp/SwapCalculate.Output
Sun Jun 8 13:30:00 IST 2014
SWAP utilization is: 18.0000%
Sun Jun 8 13:31:00 IST 2014
SWAP utilization is: 18.0000%

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s