nagios 監(jiān)控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
注:讓該用戶有訪問(wèn)本地mysql的權(quán)限即可,可用mysql -u ming -p123456驗(yàn)證,權(quán)限不一定給all
方式一(localhost監(jiān)控):
# 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
可先測(cè)試一下:
#./check_mysql_health --hostname 192.168.1.10 --port 3306 --username ming --password 123456 --mode threads-connected --warning 700 --critical 1000
注:在線程數(shù)(連接數(shù))超過(guò)1000或無(wú)法連接時(shí)紅燈報(bào)警,線程數(shù)在700以內(nèi)0以上為綠燈,700到1000之間為黃燈。
方式二(nrpe監(jiān)控):
下面要借助于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為監(jiān)控主機(jī)的文件,自建的)
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實(shí)現(xiàn)多種監(jiān)控模式:
connection-time (Time to connect to the server)
uptime (Time the server is running)
threads-connected (Number of currently open connections)線程數(shù)
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)
汝陽(yáng)網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營(yíng)維護(hù)。成都創(chuàng)新互聯(lián)2013年至今到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。
網(wǎng)頁(yè)名稱:nagios監(jiān)控mysql(check_mysql_health插件)
新聞來(lái)源:
http://weahome.cn/article/jseshp.html