Nagios监控数据库的方法:
check_mysql_health监控数据库
1、check_mysql_health安装
在监控服务器上安装
- #cd/usr/local/src/tarbag
- #wgethttp://labs.consol.de/wp-content/uploads/2010/03/check_mysql_health-2.1.1.tar.gz
- #tarzxvfcheck_mysql_health-2.1.1.tar.gz-C../software/
- #./configure\
- –prefix=/usr/local/nagios/\
- –with-nagios-user=nagios\
- –with-nagios-group=nagios\
- –with-perl=/usr/bin/perl\
- –with-statefiles-dir=/usr/local/nagios/var/tmp\
- –with-perlperl\程序运行路径
- –with-statefiles-dir状态信息文件路径
- #make
- #makeinstall
2、check_mysql_health选项
- Options:
- –hostname
- thedatabaseserver’shostname
- –port
- thedatabase’sport.(default:3306)
- –socket
- thedatabase’sunixsocket.
- –username
- themysqldbuser
- –password
- themysqldbuser’spassword
- –database
- thedatabase’sname.(default:information_schema)
- –warning
- thewarningrange
- –critical
- thecriticalrange
- –mode
- themodeoftheplugin.selectoneofthefollowingkeywords:
- connection-time连接到服务器上的时间
- uptime服务器运行的时间
- threads-connected当前连接到数据库的连接数
- threadcache-hitrate线程缓存命中率
- slave-lagslave落后master多少时间
- slave-io-runningslave复制是否正常
- slave-sql-runningslave复制是否正常
- qcache-hitrate查询缓存命中率
- qcache-lowmem-prunes(Querycacheentriesprunedbecauseoflowmemory)
- keycache-hitrate(MyISAMkeycachehitrate)
- bufferpool-hitrate(InnoDBbufferpoolhitrate)
- bufferpool-wait-free(InnoDBbufferpoolwaitsforcleanpageavailable)
- log-waits(InnoDBlogwaitsbecauseofatoosmalllogbuffer)
- tablecache-hitrate表缓存命中率
- table-lock-contention表锁率
- index-usage索引使用情况
- tmp-disk-tables(Percentoftemptablescreatedondisk)
- slow-queries慢查询
- long-running-procs长时间运行的进程
- cluster-ndbd-runningndb节点运行状况
- sql返回一个数字的任何SQL语句
3、check_mysql_health监控配置
监控服务器:10.59.97.42
MySQL数据授权:
在要监控的MySQL数据库服务器上
- mysql>grantusageon*.*tohonyho@10.59.97.42identifiedby“honyho@8123“;
- mysql>flushprivileges;
在监控服务器上
1》查看当前连接到数据库的连接数
- #./check_mysql_health–hostname10.59.97.57–usernamehonyho–passwordhonyho@8123–modethreads-connected
- OK–3clientconnectionthreads|threads_connected=3;10;20
- threads_connected=3;10;20
3表示连接数
10 表示warning阀值(默认)
20 表示critical阀值(默认)
Nagios相关配置
1》配置commands.cfg文件
- definecommand{
- command_namecheck_mysql_health
- command_line$USER1$/check_mysql_health–hostname$ARG1$–username$ARG2$–password$ARG3$–warning$ARG4$–critical$ARG5$–mode$ARG6$
- }
2》配置121_207_231_17.cfg文件
- defineservice{
- uselocal-service
- host_name121.207.231.17
- service_descriptionthreads-connected
- check_commandcheck_mysql_health!10.59.97.57!honyho!honyho@8123!1000!1500!threads-connected
- }