SIMPLE Monitoring on Linux
Simple Monitor Disk Usage and CPU Load Usage shell Scripts
Threshold Value 0 : OK 1 : Warning 2 :Critical
mohan# vi disk.sh
#!/bin/bash
##checks the used disk space for nagios
##usage disk.sh mountpoint critical_used%value warning_used%value
size=`df -Ph $1 | tail -1 | awk '{print $5}'`
size=$(echo ${size%\%})
if [ $size -gt $2 ]
then
echo "Critical $1 size exceeded $2 % current size $size "
exit 2;
fi
if [ $size -gt $3 ]
then
echo "Warning $1 size exceeded $3 % current size $size"
exit 1;
fi
echo "OK $1 curent size $size %"
exit 0;
mohan# vi load.sh
#!/bin/bash
##checks last 15 minutes load average, if more than 3 critical, more than 2 warning
##usage load.sh
loadavg=`uptime | awk '{print $11}'`
# bash doesn't understand floating point
# so convert the number to an interger
thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`
if [ "$thisloadavg" -ge "3" ]; then
echo "Critical - Load Average $loadavg ($thisloadavg) "
exit 2
else
if [ "$thisloadavg" -ge "2" ]; then
echo "Warning - Load Average $loadavg ($thisloadavg) "
exit 1
else
echo "Okay - Load Average $loadavg ($thisloadavg) "
exit 0
fi
fi
No comments:
Post a Comment