Web Hosting Talk







View Full Version : Disk usage, SwapIO, load avg scripts


sysconfig
08-30-2006, 02:43 AM
Hello,

I have found this script from below mention URL: Linux Web Admin (http://forums.linuxwebadmin.info/index.php/topic,44.0.html)

I want some more suggestion and modification on this script to make it batter.

Some useful script for yoru server maintenance:

Script which will send you email alert when disk space usage is more than 70%:
----------------------------------------------------------------------------------------------

#!/bin/bash
usage=`df -h | awk '{print $5}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -d % -s "\n"`
devnm=`df -h | awk '{print $1}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -s "\n"`
str="============================="

if [ $usage -ge 70 ]; then
info="Disk usage for $devnm is more than 70% , Current Disk usage is $usage % "
echo -e "$str\n$info\n$str" |mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com

else
info="Disk Usage is $usage% for $devnm"
# echo -e "$str\n$info\n$str" | mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com
fi

------------------------------------------------------------------------------------------------
Script which will send you email alert when swapIO us more than 100 MB:
---------------------------------------------------------------------------------------------------

#!/bin/bash
io=`free -m | awk '{print $3}' | sed '1,3 d'`
info1="SwapIO is : $io MB"
str="============================="

if [ $io -ge 100 ]; then
info="SwapIO is more than 100 MB"
echo -e "$str\n$info\n$info1\n$str" | mail -s "Alert: SwapIO for `hostname` on `date`" abc@yourdom.com
else
# echo -e "$str\n$info1\n$str" | mail -s "Alert: SwapIO for `hostname` on `date`" abc@yourdom.com
fi

------------------------------------------------------------------------------------------------
Script which will send you email alert wehn load average is more than 5:
-----------------------------------------------------------------------------------------------

#!/bin/bash
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`uptime | awk '{print $10}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"

if [ $cur -ge 5 ]; then
info1="Server load is high presently"
echo -e "$str\n$info\n$info1\n$str" | mail -s "Alert: Load Average for `hostname` on `date`" abc@yourdom.com
else
# echo -e "$str\n$info\n$str"
fi


-----------------------------------------------------------------------------------------------

sysconfig
08-31-2006, 05:41 AM
trendhoper:I will recomend nagios for this.
It's great for check your service

Nagios is always batter, than this script but this is a simple scripts at first level there should not be any comparision of this with nagios.

However, Nagios is powerful tool for server monitoring at all level.

rat0042
09-07-2006, 09:16 AM
I agree nagios is the way to go for that kind of monitoring. I've got it running with gnokii, so that I get sms alerts if anything is going wrong.

I also have nagios via nrpe checking some static files on the server. I update the static file once a week with scripts that...
- Check if there are any updates available via yum
- Check for smart disk errors/run a badblocks scan
- Check daily that backups have run and have been verified on the backup server
- Run a nessus scan of the server and warn me if there are any changes

sysconfig
09-07-2006, 10:33 AM
Yes, I agree with you