In this article, i will explain how we can monitor server memory utilization

This Script can be  use for to monitor server memory utilization. Dont forget; Threshold is the maximum percentage of memory used

Memory Monitor script

#Script used to monitor server memory utilization
#Threshold is the maximum percentage of memory used
THRESHOLD=$1
TMPFILE=/tmp/tmp_mem.txt
LOGFILE=/tmp/memory_utilization.log
HOSTNAME=`hostname`
sar -r 2 2 > $TMPFILE
MEM_USAGE=`tail -1 $TMPFILE | awk ‘{ print $4 }’`
if [ $MEM_USAGE –gt $THRESHOLD ]
then
echo “$HOSTNAME – Server Memory utilization High – $MEM_USAGE”
> $LOGFILE
exit 1
else
exit 0
fi

Advertisements