在nagios上部署check_mysql_health 监控mysql
本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:
connection-time(Timetoconnecttotheserver)
uptime(Timetheserverisrunning)
threads-connected(Numberofcurrentlyopenconnections)线程数
threadcache-hitrate(Hitrateofthethread-cache)慢查询
slave-lag(Secondsbehindmaster)
slave-io-running(Slaveiorunning:Yes)主从热备
slave-sql-running(Slavesqlrunning:Yes)主从热备
qcache-hitrate(Querycachehitrate)
qcache-lowmem-prunes(Querycacheentriesprunedbecauseoflowmemory)
keycache-hitrate(MyISAMkeycachehitrate)
bufferpool-hitrate(InnoDBbufferpoolhitrate)
bufferpool-wait-free(InnoDBbufferpoolwaitsforcleanpageavailable)
log-waits(InnoDBlogwaitsbecauseofatoosmalllogbuffer)
tablecache-hitrate(Tablecachehitrate)
table-lock-contention(Tablelockcontention)锁表率
index-usage(Usageofindices)
tmp-disk-tables(Percentoftemptablescreatedondisk)
slow-queries(Slowqueries)
long-running-procs(longrunningprocesses)
cluster-ndbd-running(ndndnodesareupandrunning)
sql (any sql command returning a single number)具体步骤如下:
1、安装
#wgethttp://labs.consol.de/wp-content/uploads/2009/10/check_mysql_health-2.1.tar.gz
#tar-zxvfcheck_mysql_health-2.1.tar.gz
#cdcheck_mysql_health-2.1
#./configure--prefix=/usr/local/nagios--with-nagios-user=nagios--with-nagios-group=nagios--with-perl=/usr/bin/perl
#make&&makeinstall
2、命令测试
#cd/usr/local/nagios/libexec
#./check_mysql_health--hostname192.168.0.1--port3306--usernamemyname--passwordmypassword--modethreads-connected--warning700--critical1000
当出现Can'tlocateDBI.pm的错误时:
#yuminstallperl-DBIperl-DBD-MySQL-y
再次执行,结果如下:
OK - 607 client connection threads | threads_connected=607;700;1000命令参数:
–hostname<hostname>
DerDatenbankserver,derüberwachtwerdensoll.ImFallevon"localhost"kanndieserParameterweggelassenwerden.
–username<username>
DerDatenbankuser.
–password<password>
DessenPasswort.
–mode<modus>
Mitdemmode-ParameterteiltmandemPluginmit,wasestunsoll.
–name<objektname>
HierkanndiePrüfungaufeineinzigesObjektbegrenztwerden.
–name2<string>
Verwendetman–mode=sql,dannerscheintdasSQL-StatementinderAusgabeunddenPerformancedaten.
–warning<range>
–critical<range>
–environment<variable>=<wert>
–method<connectmethode>
MitdiesemParameterteiltmandemPluginmit,wieessichzurDatenbankverbindensoll.
–units <%|KB|MB|GB>3、nagios命令、服务配置
#vi/usr/local/nagios/etc/objects/commands.cfg
...
#'check_mysql_health'
definecommand{
command_namecheck_mysql_health
command_line$USER1$/check_mysql_health--hostname$ARG1$--port$ARG2$--username$ARG3$--password$ARG4$--mode$ARG5$
--warning$ARG6$--critical$ARG7$
}
...#vi /usr/local/nagios/etc/objects/servers/localhost.cfg...
define service{
uselocal-service;Nameofservicetemplatetouse
host_namemyhostname
service_descriptioncheck_mysql_connections
check_commandcheck_mysql_health!192.168.0.1!3306!myname!mypassword!threads-connected!1000!1500
}define service{
uselocal-service;Nameofservicetemplatetouse
host_namemyhostname
service_descriptioncheck_mysql_table_lock
check_commandcheck_mysql_health!192.168.0.1!3306!myname!mypassword!table-lock-contention!1!2
}
...
4、重启nagios服务
#servicenagiosrestart