Nagios adds a custom monitoring project to monitor MySQL database deadlock

Source: Internet
Author: User

Nagios Add a custom monitoring project

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

System Environment: CentOS Linux release 7.2.1511 (Core)

Nagios Version: 2.15


Here with the Pt-dead-logger plug-in, run the plug-in, there will be a deadlock in the Test.deadlocks table to write the deadlock information

This is done by detecting if the table has increased the number of rows to send an alarm.


Nagios Client Custom Script:

# # #这里为了省事, directly to the database user, password, IP address to write to the script to go, in fact, should be made into parameters, but we only need to monitor a database, simply a little done

# # # #最起码应该在这个脚本里把-u,-p,-h The values of these variables, like STATUS_OK, are defined at the very beginning of the script.


Vim/usr/local/nagios/libexec/check_mysql_deadlock

#!/bin/bash


Status_ok=0

status_critical=2

#这里的状态用2是因为我把数据库死锁这种报警级别定义为critical, corresponding to the Nagios default critical level, if using 1 is warn


odls= ' Cat/tmp/dl.txt '

The number of last deadlock (number of rows) saved in #/tmp/dl.txt


dls=$ (mysql-utestuser-p ' YourPassword '-H 172.28.12.9-e ' SELECT COUNT (*) from test.deadlocks; ' | awk ' {t=$0}end{print $N F} ')


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


To modify file properties:

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

Chown Nagios.nagios/usr/local/nagios/libexec/check_mysql_deadlock


Client Add Command:

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

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


Service xinetd Restart

Here Nagios's client Nrpe service is integrated into the XINETD server, so reboot if you

[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 Server side:

172.28.12.17


Test the script you just made on the server:

/usr/local/nagios/libexec/check_nrpe-h 172.28.12.107-c Check_mysql_deadlock

Total deadlocks:290, is OK

There is return, the description is normal work, here is returned test.deadlocks This table has a deadlock record number of rows, as long as the number of rows does not increase on OK, added the description has a new deadlock


Add our custom commands to the server

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

Define Command{

Command_name Check_mysql_dealock

Command_line $USER 1$/chech_mysql_deadlock

}


Add monitoring options so that you can see it in our web monitoring interface

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

After restarting the service, you can see your own defined monitoring items in the Web monitoring interface.

Here you can see mysql_deadlock this monitoring item is under CALLCENTER107 this host

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 "/>






Here the script has a problem, that is, the first time to find the wrong number of rows, sent an email alarm, the second detection, the same deadlock is still in the time, will be the alarm OK. In fact, this is a mistake and the script needs to be perfected.

This article is from the "Bywind" blog, make sure to keep this source http://bywind.blog.51cto.com/7598847/1913585

Nagios adds a custom monitoring project to monitor MySQL database deadlock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.