MySQL status monitor


                This script is actually another slow log detector, but it will also send mail instead of writing logs only.1. monitor  MySQL, if the connection >= 30 then call the sendmail function
---------------------------------------------------------
$ more master_mysql_monitor.sh
               
               
               
                #!/bin/sh
flag=30  //more than 30 connections
path=/root/xxd/monitor
user=username
pass=password
host=IP
logd=`date +%Y%m%d`
logf=$path/logs/mm_run_$logd.log
errf=$path/logs/mm_err_$logd.log
comm="set names utf8;show full processlist;"
date=`date`
shel=`echo $comm | mysql -u$user -p$pass -h$host | awk '{print $0"$"}'`
line=`echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij | awk '{if ($7!="NULL") print $7
;}' | wc -l`
line=$[line-3]
                   
. $path/include/functions //the sendmail function see 2
if [ $line -gt $flag ];
then
        echo "--------------------------------" >> $errf
        echo "$date ---- not NULL:$line" >> $errf
        echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij >> $errf
        echo "--------------------------------" >> $errf
        send_mail "m_mysql"
fi
echo "----------------------------------------" >> $logf
echo "$date ---- not NULL:$line" >> $logf
echo $shel | awk '{zcou=split($0,mcom,"$");for (leij=0;leij >> $logf
echo "----------------------------------------" >> $logf
2. The sendmail function
--------------------
$ more /root/xxd/monitor/include/functions
#!/bin/sh
function send_mail() {
send=$1
case "$send" in
        "m_mysql")
                /usr/sbin/sendmail -t  $path/templates/master_mysql_mail
        ;;
        "s_mysql")
                /usr/sbin/sendmail -t  $path/templates/slave_mysql_mail
        ;;
        "m_web")
                /usr/sbin/sendmail -t  $path/templates/master_web_mail
        ;;
        "s_web")
                /usr/sbin/sendmail -t  $path/templates/slave_web_mail
        ;;
        "mm_netstat")
                /usr/sbin/sendmail -t  $path/templates/master_mysql_netstat_mail
        ;;
esac
}