nagios 添加自訂監控項目監控mysql資料庫死結

來源:互聯網
上載者:User

標籤:nagios監控   mysql資料庫   自訂監控   

nagios 添加自訂監控項目

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

系統內容:CentOS Linux release 7.2.1511 (Core)

nagios 版本: 2.15 


這裡配合pt-dead-logger外掛程式了,運行了這個外掛程式,有死結就會在test.deadlocks表寫入死結的資訊

這裡通過檢測這個表是否增加了行數來發警示


nagios用戶端自訂指令碼:

###這裡為了省事,直接把資料庫的使用者,密碼,IP地址給寫到指令碼裡去了,其實應該做成參數傳進去的,但是我們只需要監控一個資料庫,就簡單一點做了

###最起碼應該在這個指令碼裡把-u,-p,-h這幾個變數的值像status_ok 那樣在指令碼最前面定義好的


vim  /usr/local/nagios/libexec/check_mysql_deadlock

#!/bin/bash


status_ok=0

status_critical=2

#這裡的狀態用2是因為我把資料庫死結這種警示層級定義為critical ,對應nagios預設的critical層級,如果用1就是warn


odls=`cat /tmp/dl.txt`

#/tmp/dl.txt裡儲存的是上次一死結的個數(行數)


dls=$(mysql -utestuser -p‘yourpassword‘ -h 172.28.12.9 -e ‘select count(*) from test.deadlocks;‘ | awk ‘{t=$0}END{print $NF }‘)


if [ $dls -ne $odls ]; then

     echo $dls > /tmp/dl.txt

     echo "deadlock is CRITICAL ! total deadlocks: $dls"

     exit $status_critical

else

     echo "total deadlocks : $dls, is OK"

     exit $status_ok

fi


修改檔案屬性:

chmod 755 /usr/local/nagios/libexec/check_mysql_deadlock

chown nagios.nagios /usr/local/nagios/libexec/check_mysql_deadlock


用戶端添加命令:

/usr/local/nagios/etc/nrpe.cfg

command[check_mysql_deadlock]=/usr/local/nagios/libexec/check_mysql_deadlock


service xinetd restart

這裡nagios的用戶端nrpe服務是整合進了xinetd伺服器,所以這樣重啟,如果你們

[[email protected]_12_107_centos nagios]# cat /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port= 5666
wait = no
user = nagios
group= nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 172.28.12.17
}


nagios 伺服器端:

172.28.12.17


在服務端測試一下剛才的指令碼:

/usr/local/nagios/libexec/check_nrpe -H 172.28.12.107 -c check_mysql_deadlock

total deadlocks : 290, is OK

有返回,說明是正常工作的,這裡返回的是test.deadlocks這個表裡已有的死結記錄行數,只要行數不增加就OK,增加了說明有新的死結


在服務端添加我們自訂的命令

vim /usr/local/nagios/etc/objects/commands.cfg

define command{

         command_name check_mysql_dealock

         command_line $USER1$/chech_mysql_deadlock

         }


添加監控選項,這樣在我們web監控介面才能看到

vim /usr/local/nagios/etc/servers/callcenter107.cfg

define service{

        use generic-service ; Name of service template to use

        host_name pyt_callcenter107

        service_description mysql_deadlock

        check_command check_nrpe!check_mysql_deadlock

        }


service nagios restart 

重啟服務之後,就有能在web監控介面看到自己定義的監控項了

這裡可以看到mysql_deadlock這個監控項是在callcenter107這個主機下面的

650) this.width=650;" src="https://s2.51cto.com/wyfs02/M02/8F/99/wKiom1jmD6_ysGiTAALe9Zmp438112.png-wh_500x0-wm_3-wmp_4-s_2329563447.png" title="bb.png" style="float:left;" alt="wKiom1jmD6_ysGiTAALe9Zmp438112.png-wh_50" />






這裡的指令碼有個問題,就是第一次發現行數不對的時候,發了郵件警示,第二次檢測,同一個死結還在的時候,就會警示OK了。其實這是個錯誤,指令碼有待完善。

本文出自 “BYWIND” 部落格,請務必保留此出處http://bywind.blog.51cto.com/7598847/1913585

nagios 添加自訂監控項目監控mysql資料庫死結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.