中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自己編寫Nagios 監控Mysql插件

發布時間:2020-07-21 15:00:10 來源:網絡 閱讀:612 作者:amwuqd 欄目:移動開發

主從監控插件編寫:

#!/bin/bash
MYSQL="/usr/local/mysql/bin/mysql -uslave -pslave12345 -h227.0.0.1 -P"
VAR_LOG=/tmp/check_mysql_status.log.$2 && >$VAR_LOG
function usage(){
    cat <<EOF
`basename $0` need at least value: `basename $0` -[s|m] port
第一個參數是 -s 那么以是檢查從模式, -m就是檢查主模式 不能省略
第二個參數是數據庫端口,如3308 3309,不能省略
mysql權限,需執行如下SQL:grant replication client,super on *.* to 'slave'@'127.0.0.1' identified by 'slave12345';
EOF
exit 1
}
function check_mysql_status(){
    #echo $MYSQL $@
    echo "show status;" | $MYSQL$@ | perl -p -e 's/\s+(\w+)/="$1"/g' >> $VAR_LOG
    #echo "$mysql_status"
}
function check_mysql_slave_status(){
    #echo $MYSQL $@
    echo "show slave status\G" | $MYSQL$@ | perl -p -e 's/:\s(.*)$/="$1"/g; s/^\s+//g; s/^\*.*\*//;' >> $VAR_LOG
}
function check_slave_results(){
    if [ "$Slave_IO_Running" == "Yes" ] && [ "$Slave_SQL_Running" == "Yes" ];then
        if [ $tmp_code -ne 0 ] && [ $Seconds_Behind_Master -gt 100 ] ;then
            code=2
        elif [ $Seconds_Behind_Master -lt 50 ] ;then
            code=0
        else
            code=1
        fi
    else
        code=2
    fi      
}
if [ $# -le 0 ] || [ "$1" == "-h" ];then
    usage
fi
if [ "$1" == "-s" ];then
    #echo "檢查從模式"
    check_mysql_slave_status $2
fi
code=0
check_mysql_status $2
. $VAR_LOG
PER_SECOND_QUESTION=`echo "$Uptime $Queries" | awk '{printf ("%4.3f") ,$2/$1}END{if($2/$1<0.05) exit 0 ;else exit 1;}'`
tmp_code=$?
if [ -z $Uptime ];then
    echo "$MYSQL $@ 連接失敗,請檢查服務" && exit 2
fi
if [ "$1" == "-s" ];then    ##輸出不同的信息
check_slave_results
    printf "主庫:$Master_Host:$Master_Port Uptime:$Uptime Threads:$Threads_running Questions:$Questions Slow_queries:$Slow_queries Open_tables:$Open_tables Queries per second avg:%s Slave_IO_Running:$Slave_IO_Running Slave_SQL_Running:$Slave_SQL_Running Seconds_Behind_Master:$Seconds_Behind_Master|Threads=$Threads_running Questions=$Questions Slowqueries=$Slow_queries Opens=$Opened_tables Opentables=$Open_tables Queriespersecondavg=%s BehindMaster=$Seconds_Behind_Master" $PER_SECOND_QUESTION $PER_SECOND_QUESTION
else    ##輸出不同的狀態信息
    printf "Uptime:$Uptime Threads:$Threads_running Questions:$Questions Slow_queries:$Slow_queries Open_tables:$Open_tables Queries per second avg:%s|Threads=$Threads_running Questions=$Questions Slowqueries=$Slow_queries Opens=$Opened_tables Opentables=$Open_tables Queriespersecondavg=%s" $PER_SECOND_QUESTION $PER_SECOND_QUESTION
fi
exit $code


mysql連接數監控:(監控mysql的最大連接數(最大連接數小于1000報警),和當前連接數 ,可用連接數少于50報警)

#!/bin/bash
#MYSQL="/usr/local/mysql/bin/mysql -unagios -pmonitor_slave#status -h$3 -P"
MYSQL="/usr/local/mysql/bin/mysql -unagios -pmonitor_slave#status -h227.0.0.1 -P"
VAR_LOG=/tmp/check_mysql_status_con_$2.log && >$VAR_LOG
#Threads_con_log=/tmp/check_mysql_tread_conn.log.$2 && >$Threads_con_log
#Max_conn_log=/tmp/check_mysql_max_con.log.$2 && >$Max_conn_log
function usage(){
        cat <<EOF
`basename $0` need at least value: `basename $0` -[s|m] port
first arg   -s : monitor slave mode
            -m : moitor master mode
second arg port: mysqld prot 3306 or 3307 or 3308 ...
mysql privilege :you neeed exec :grant replication client,super on *.* to 'slave'@'127.0.0.1' identified by 'slave12345';
EOF
exit 1
}
function check_mysql_status(){
        #echo $MYSQL $@
        echo "show status;" | $MYSQL$@ | perl -p -e 's/\s+(\w+)/="$1"/g' >> $VAR_LOG
        #echo "$mysql_status"
}
function check_mysql_con_status(){
        #echo $MYSQL $@
        echo "show status like 'Threads_connected';" | $MYSQL$@ | perl -p -e 's/\s+(\w+)/="$1"/g' >> $VAR_LOG
        echo "show variables like 'max_connections';" |$MYSQL$@ | perl -p -e 's/\s+(\w+)/="$1"/g' >> $VAR_LOG
        #echo "$mysql_status"
}
function check_mysql_con_results(){
   #echo "$max_connections,$Threads_connected"
   Residue_conn=$(($max_connections-$Threads_connected))
   #echo $Residue_conn
    if [ $max_connections -lt 1000 ];then
        if [ $Residue_conn -lt 50 ] ;then
            code=2
        else
            code=1
        fi
    else
        code=0
    fi      
}
if [ $# -le 0 ] || [ "$1" == "-h" ];then
        usage
fi
code=0
check_mysql_status $2
check_mysql_con_status $2
. $VAR_LOG
Residue_conn=$max_connections
check_mysql_con_results $2
PER_SECOND_QUESTION=`echo "$Uptime $Queries" | awk '{printf ("%4.3f") ,$2/$1}END{if($2/$1<0.05) exit 0 ;else exit 1;}'`
tmp_code=$?
#
if [ -z $Uptime ];then
        echo "$MYSQL $@ Connect Failed,Please check!" && exit 2
fi
#
 printf "Uptime:$Uptime Threads_connected:$Threads_connected Max_connections:$max_connections Residue_connectios:$Residue_conn Open_tables:$Open_tables Queries per second avg:%s|Threads=$Threads_running Questions=$Questions Slowqueries=$Slow_queries Opens=$Opened_tables Opentables=$Open_tables Queriespersecondavg=%s" $PER_SECOND_QUESTION $PER_SECOND_QUESTION
#
exit $code


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

银川市| 巨野县| 汾西县| 资兴市| 松原市| 襄垣县| 康定县| 义乌市| 富川| 上饶县| 新竹市| 南靖县| 孝义市| 临清市| 延边| 福清市| 大冶市| 年辖:市辖区| 贵南县| 涞水县| 吉林省| 兰溪市| 双辽市| 民和| 宜川县| 麻江县| 内江市| 钟祥市| 宜丰县| 鸡西市| 临洮县| 台前县| 巴彦淖尔市| 读书| 万载县| 枣强县| 文山县| 闵行区| 玛曲县| 灵石县| 当涂县|