Nagios监控MySQL运行的脚本

发布时间:2019-11-03编辑:脚本学堂
Nagios监控MySQL运行的脚本代码。

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 | linuxjishu/13830.html target=_blank class=infotextkey>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