当前位置: > Linux服务器 > 监控工具 >

Nagios监控MySQL运行的脚本

时间:2014-10-26 00:45来源:linux.it.net.cn 作者:IT网

Nagios监控MySQL运行的脚本代码。
 

复制代码代码如下:

#!/bin/sh
#====================================
# $Name:         mysql_check.sh
# $Revision:     1.0
# $Function:     This Nagios plugin can be check MySQL status
# $Author:       Shundong Zhao
# $organization: UnixHot
# $Create Date:  2010-08-10
#===================================

MYSQLC="/usr/local/mysql/bin/mysql"
MYSQLADC="/usr/local/mysql/bin/mysqladmin"
MUSER="nagios"
MPASSWD="nagios"
SLOWLOGW="2"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

mysqlstatus(){
        STATUSSTR=`$MYSQLADC -u $MUSER -p$MPASSWD ping`
        if [ "$STATUSSTR" == "mysqld is alive" ];then
                echo -n "$STATUSSTR";
                return 0;
        else
                echo -n "$STATUSSTR";
                exit 2;
        fi
}

mysqlslowlog(){
    SLOWLOGTMP=`$MYSQLADC -u $MUSER -p$MPASSWD status`
        SLOWLOGNU=`echo $SLOWLOGTMP | awk -F ' ' '{print $9}'`
        if [ "$SLOWLOGNU" -gt "$SLOWLOGW" ];then
        echo -n "Slow queriesSLOWLOGNU";
        exit 2;
        else
        echo -n "Slow QueriteSLOWLOGNU";
        fi
}


main(){
        mysqlstatus;
        echo -n ";";
#        mysqlreplication;
        mysqlslowlog;
}

main


(责任编辑:IT)
------分隔线----------------------------