利用check_mysql_health监控mysql数据

下载地址
https://labs.consol.de/nagios/check_mysql_health/index.html

安装
nagios安装配置省略. . . .


#yum install perl-DBI perl-DBD-MySQL

# tar -zxf check_mysql_health-2.2.1
./configure --prefix=/usr/local/nagios/
make && make install

登录mysql

mysql> grant usage,select on *.* to "nagios"@"%" identified by "nagios";




测试命令1
# ./check_mysql_health --hostname 10.10.9.91 --port 3307 --username nagios --password nagios --mode threads-connected --warning 120 --critical 150
OK - 109 client connection threads | threads_connected=109;120;150


测试命令2(需要执行sql语句)
1.语句转换
#echo 'SELECT COUNT(*)  FROM zjb.zjb_data_tc_only_20160410'|/usr/local/nagios/libexec/check_mysql_health --mode encode
SELECT%20COUNT%28%2A%29%20%20FROM%20zjb%2Ezjb%5Fdata%5Ftc%5Fonly%5F20160410


2.测试
# ./check_mysql_health --hostname 10.10.9.91 --port 3307 --username nagios --password nagios --mode sql --name SELECT%20COUNT%28%2A%29%20%20FROM%20zjb%2Ezjb%5Fdata%5Ftc%5Fonly%5F20160410 --warning 180000 --critical 220000
WARNING - select count(*)  from zjb.zjb_data_tc_only_20160410: 202081 | 'select'=202081;180000;220000




定义命令
# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name check_mysql_connected
        command_line $USER1$/check_mysql_health --hostname 10.10.9.91 --port 3307 --username $ARG1$ --password $ARG2$ --mode threads-connected --warning $ARG3$  --critical $ARG4$
        }





定义服务
vim /usr/local/nagios/etc/objects/91.cfg 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       91
        service_description             Mysql_connected
        check_command                   check_mysql_connected!nagios!nagios!120!150
        }











posted @ 2016-04-11 15:15  消磨_时间  阅读(585)  评论(0)    收藏  举报