具体步骤如下:
1、安装
#wget http://www.olinux.org.cn/wp-content/uploads/2012/02/check_mysql_health-2.1.tar.gz
#tar -zxvf check_mysql_health-2.1.tar.gz
#cd check_mysql_health-2.1
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl
#make && make install
2、命令测试
#cd /usr/local/nagios/libexec
#./check_mysql_health --hostname 192.168.0.1 --port 3306 --username myname --password mypassword --mode threads-connected --warning 700 --critical 1000
当出现Can't locate DBI.pm的错误时:是由于你没有安装perl DBD-MySQL驱动,可以直接用yum安装,也可以利用源码安装perl DBD-MySQL驱动
#yum install perl-DBI perl-DBD-MySQL -y
再次执行,结果如下:
OK - 5 client connection threads
监控mysql主从状态
./check_mysql_health --hostname 192.168.0.1 --port 3306 --username myname --password mypassword --mode slave-io-running/slave-sql-running
正确输出:OK - Slave io is running /OK - Slave sql is running
nagios监控配置文件
cd /usr/local/nagios/etc/object
vi command.cfg 添加
#'check_mysql_health'
define command{
command_name check_mysql_health
command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
--warning $ARG6$ --critical $ARG7$
}
在需要监控的机器上 例如localhost.cfg中添加
define service{
use local-service ; Name of service template to use
host_name myhostname
service_description check_mysql_connections
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!threads-connected!1000!1500
}
define service{
use local-service ; Name of service template to use
host_name myhostname
service_description check_mysql_table_lock
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!slave-io-running
}
define service{
use local-service ; Name of service template to use
host_name myhostname
service_description check_mysql_table_lock
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!slave-sql-running
}
您可以选择一种方式赞助本站
支付宝转账赞助
