Sunday, December 21, 2014

Script for getting load, Memory usage and apache connection count in Linux

Following script can be used to format the Average load, Memory used and Apache connection count in Linux format it and present it in a human readable form.

The script is designed to read the hostname , date and time of execution, Average load, Apache process count, physical and swap memory usage

# The script is used for the Load Testing and will provide the Load, Memory,apache process count
Load=`uptime | awk -F "load average: " '{print $2}' | awk -F"," '{print $1$2$3}'
totalmemory=`free -m | gawk  '/Mem:/{print $2}'`
usedmemory=`free -m | gawk  '/Mem:/{print $3}'`
freememory=`free -m | gawk  '/Mem:/{print $4}'`
totalswapmemory=`free -m | gawk  '/Swap:/{print $2}'`
usedswapmemory=`free -m | gawk  '/Swap:/{print $3}'`
freeswapmemory=`free -m | gawk  '/Swap:/{print $4}'`
process=`ps -ef | grep -c httpd`

echo "Reading from "$host" on "$dat""
echo "Load is "$Load" , Apache proces count "$process""
echo "Total Memory "$totalmemory"MB, used "$usedmemory"MB ,free "$freememory"MB"
echo "Total Swap Memory "$totalswapmemory"MB, used "$usedswapmemory"MB ,free "$freeswapmemory"MB "
echo "============================================================================"
echo ""



Post a Comment