5) 没错的话,重载nagios就行了。
nagios -v /etc/nagios/nagios.cfg
service nagios reload
3. mysql
本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:
connection-time (Time toconnect to the server)
uptime (Time the server is running)
threads-connected (Number ofcurrently open connections)线程数
threadcache-hitrate (Hit rate of thethread-cache)慢查询
slave-lag (Seconds behind master)
slave-io-running (Slave iorunning: Yes)主从热备
slave-sql-running (Slave sql running:Yes)主从热备
qcache-hitrate (Query cache hitrate)
qcache-lowmem-prunes (Query cache entries prunedbecause of low memory)
keycache-hitrate (MyISAM keycache hitrate)
bufferpool-hitrate (InnoDB buffer poolhitrate)
bufferpool-wait-free (InnoDB buffer pool waits forclean page available)
log-waits (InnoDB log waits because of a too small log buffer)
tablecache-hitrate (Table cache hitrate)
table-lock-contention (Table lock contention)锁表率
index-usage (Usage of indices)
tmp-disk-tables (Percentof temp tables created on disk)
slow-queries (Slow queries)
long-running-procs (long running processes)
cluster-ndbd-running (ndnd nodes are up and running)
sql (any sql command returning a single number)
具体步骤如下:
1、安装
#wget http://labs.consol.de/wp-content/uploads/2009/10/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'tlocate DBI.pm的错误时:
#yum install perl-DBI perl-DBD-MySQL -y
再次执行,结果如下:
OK - 607 client connection threads | threads_connected=607;700;1000
命令参数:
–hostname <hostname>
Der Datenbankserver, der überwacht werden soll. Im Falle von"localhost" kann dieser Parameter weggelassen werden.
–username <username>
Der Datenbankuser.
–password <password>
Dessen Passwort.
–mode <modus>
Mit dem mode-Parameter teilt man dem Plugin mit, was es tun soll.
–name <objektname>
Hier kann die Prüfung auf ein einziges Objekt begrenzt werden.
–name2 <string>
Verwendet man –mode=sql, dann erscheint das SQL-Statement in der Ausgabe undden Performancedaten.
–warning <range>
–critical <range>
–environment <variable>=<wert>
–method <connectmethode>
Mit diesem Parameter teilt man dem Plugin mit, wie es sich zur Datenbankverbinden soll.
–units <%|KB|MB|GB>
3、nagios命令、服务配置
#vi /usr/local/nagios/etc/objects/commands.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$ #可以将$ARG1$换成$HOSTADDRESS$
}
...
#vi/usr/local/nagios/etc/objects/servers/localhost.cfg
...
define service{
use local-service ; Name of servicetemplate 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 servicetemplate to use
host_name myhostname
service_description check_mysql_table_lock
check_command check_mysql_health!192.168.0.1!3306!myname!mypassword!table-lock-contention!1!2
}
...
4、重启nagios服务
#service nagios restart
