自动监控tomcat+mysql+heartbeat的脚本
该脚本的作用是检测到tomat+mysql+heartbeat服务出现问题的是自动处理并且报警#!/bin/bash
path=/usr/local/nagios/libexec/
logfile=/var/log/moniter.log
date=`(date +%D--%T)`
hostname=localhost
sleeptime=30
tomcatmessege="the tomcat server down but it up now"
mysqlmessege="the mysql serverdownbut it up now"
tomcat_restart_succeed=/usr/local/iSpaceServer/tomcat/context/tomcat_restart_succeed
mysql_restart_succeed=/usr/local/iSpaceServer/tomcat/context/mysql_restart_succeed
heartbeat_restart_failed=/usr/local/iSpaceServer/tomcat/context/heartbeat_restart_failed
tomcat_restart_failed=/usr/local/iSpaceServer/tomcat/context/tomcat_restart_failed
mysql_restart_failed=/usr/local/iSpaceServer/tomcat/context/mysql_restart_failed
email="qubq@qian-gao.com"
q=refused
level=1000
sqlcode=500
echo "the tomcat server down but it up now">/usr/local/iSpaceServer/tomcat/context/tomcat_restart_succeed
echo "the mysql server down but it up now">/usr/local/iSpaceServer/tomcat/context/mysql_restart_succeed
echo "the tomcat server restart failed!">/usr/local/iSpaceServer/tomcat/context/tomcat_restart_failed
echo "the mysqlserver restart failed!">/usr/local/iSpaceServer/tomcat/context/mysql_restart_failed
echo "the heartbeat server restart failed!">/usr/local/iSpaceServer/tomcat/context/heartbeat_restart_failed
result=`(ps -eo pid,tty,user,comm,stime,etime | more |grep java|sed 's/://g'| awk '{print $6}' |sed -e 's/://g' -e 's/-//g')`
valuse=`($path/check_http-w 5 -c 10-H localhost |awk '{print $4}')`
f=`($path/check_http-w 5 -c 10-H localhost |awk '/refused/'|awk'{print $2}')`
if [ $valuse != 200 ]
then
if[ "$f" = "$q" ]
then
service heartbeat stop
killall -9 java
/etc/init.d/iSpaceServer start
sleep $sleeptime
a=`($path/check_http-w 5 -c 10-H localhost |awk '{print $4}')`
if [ $a == 200]
then
echo "==============>$date>$logfile
echo $tomcatmessege>>$logfile
mail -s "tomcat_restart_succeed!" $email >$logfile
else
mail -s "heartbeat_restart_failed!" $email"$level" ))
then
service heartbeat stop
killall -9 java
/etc/init.d/iSpaceServer start
sleep $sleeptime
b=`($path/check_http-w 5 -c 10-H localhost |awk '{print $4}')`
if [ $b == 200]
then
echo "==============>$date>$logfile
echo $tomcatmessege>>$logfile
mail -s "tomcat_restart_succeed!" $email >$logfile
else
mail -s "heartbeat_restart_failed!" $email $date>$logfile
echo $mysqlmessege>>$logfile
mail -s "mysql_restart_succeed!" $email >$logfile
else
mail -s "heartbeat_restart_failed!" $email <$heartbeat_restart_failed
fi
else
mail -s "mysql_restart_failed!" $email <$mysql_restart_failed
fi
fi
fi
感谢楼主的分享!
页:
[1]