nagios 監控mysql(check_mysql_health插件)
nagios 監控
mysql(check_mysql_health插件)
http://labs.consol.de/wp-content/uploads/2011/08/check_mysql_health-2.1.7.tar.gz
# mount /dev/cdrom /media/cdrom
# rpm -ivh /media/cdrom/Server/perl-DBI-1.52-2.el5.i386.rpm
# rpm -ivh /media/cdrom/Server/perl-DBD-MsSQL-3.0007-2.el5.i386.rpm --nodeps
# tar zxf check_mysql_health-2.1.7.tar.gz
# cd check_mysql_health-2.1.7
# ./configure
# make && make install
# mysql -u root -p123456
> grant all on *.* to ming@'localhost' identified by '123456';
> quit
注:讓該用戶有訪問本地mysql的權限即可,可用mysql -u ming -p123456驗證,權限不一定給all
方式一(localhost監控):
# vi /usr/local/nagios/etc/objects/commands.cfg
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$
}
:wq
# vi /usr/local/nagios/etc/objects/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.1.10!3306!ming!123456!threads-connected!700!1000
}
:wq
可先測試一下:
#./check_mysql_health --hostname 192.168.1.10 --port 3306 --username ming --password 123456 --mode threads-connected --warning 700 --critical 1000
注:在線程數(連接數)超過1000或無法連接時紅燈報警,線程數在700以內0以上為綠燈,700到1000之間為黃燈。
方式二(nrpe監控):
下面要借助于nrpe(nrpe安裝步驟略)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_mysql]=/usr/local/nagios/libexec/check_mysql_health --hostname 192.168.1.10 --port 3306 --username ming --password 123456 --mode threads-connected --warning 700 --critical 1500
:wq
重啟nrpe:
# killall nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# vi /usr/local/nagios/etc/objects/ming.cfg (ming.cfg為監控主機的文件,自建的)
define service{
use local-service ; Name of service template to use
host_name myhostname
service_description check_mysql
check_command check_nrpe!check_mysql
}
:wq
附:
利用check_mysql_health實現多種監控模式:
connection-time (Time to connect to the server)
uptime (Time the server is running)
threads-connected (Number of currently open connections)線程數
threadcache-hitrate (Hit rate of the thread-cache)慢查詢
slave-lag (Seconds behind master)
slave-io-running (Slave io running: Yes)主從熱備
slave-sql-running (Slave sql running: Yes)主從熱備
qcache-hitrate (Query cache hitrate)
qcache-lowmem-prunes (Query cache entries pruned because of low memory)
keycache-hitrate (MyISAM key cache hitrate)
bufferpool-hitrate (InnoDB buffer pool hitrate)
bufferpool-wait-free (InnoDB buffer pool waits for clean 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 (Percent of 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)