wget http://labs.consol.de/wp-content/uploads/2011/08/check_mysql_health-2.1.7.tar.gz
wget http://labs.consol.de/wp-content/uploads/2010/03/check_mysql_health-2.1.1.tar.gz
wget http://www.shinguz.ch/MySQL/nagios-mysql-plugins-0.3.tar.gz
1、check_mysql_health安装
在监控服务器上安装
# cd /usr/local/src/tarbag
# wget http://labs.consol.de/wp-content/uploads/2010/03/check_mysql_health-2.1.1.tar.gz
64位centos安装check_mysql_health插件,需要以下2个包支持
yum install -y perl-DBD-MySQL
yum install -y perl-DBD-Pg
# tar zxvf check_mysql_health-2.1.1.tar.gz -C ../software/
./configure --prefix=/usr/local/nagios
make
make install
2、查看check_mysql_health选项
cd /usr/local/nagios/libexec
chmod 777 check_mysql_health
./check_mysql_health
Options:
�Chostname
the database server’s hostname
�Cport
the database’s port. (default: 3306)
�Csocket
the database’s unix socket.
�Cusername
the mysql db user
�Cpassword
the mysql db user’s password
�Cdatabase
the database’s name. (default: information_schema)
�Cwarning
the warning range
�Ccritical
the critical range
�Cmode
the mode of the plugin. select one of the following keywords:
connection-time 连接到服务器上的时间
uptime 服务器运行的时间
threads-connected 当前连接到数据库的连接数
threadcache-hitrate 线程缓存命中率
slave-lag slave落后master多少时间
slave-io-running slave复制是否正常
slave-sql-running slave复制是否正常
qcache-hitrate 查询缓存命中率 //这个命中率越高,表明服务器的select查询性能越好。
qcache-lowmem-prunes (Query cache entries pruned because of low memory:由于内存较小从缓存中删除的查询量) // 增大query_cache_size的值,以减小lowmem,增加缓存命中率。
keycache-hitrate (MyISAM key cache hitrate :key缓存命中率)如果命中率过低,则调大key_buffer_size
bufferpool-hitrate (InnoDB buffer pool hitrate:innodb缓冲池命中率)
bufferpool-wait-free (InnoDB buffer pool waits for clean page available:innodb的缓存池等等清理页。)
log-waits (InnoDB log waits because of a too small log buffer:因为太小log缓冲区导致innodb log等待。)
tablecache-hitrate 表缓存命中率
table-lock-contention 表锁率
table_locks_waited;不能立即获得的表的锁表次数。
table_locak_waited;立即获得的表的锁表次数。
小于1%较优,如果1%需要引起注意,大于3%性能有问题。
index-usage 索引使用情况
tmp-disk-tables (Percent of temp tables created on disk:建立的临时表)
slow-queries 慢查询
long-running-procs 长时间运行的进程
cluster-ndbd-running ndb节点运行状况
sql 返回一个数字的任何SQL语句
3、check_mysql_health监控配置
监控服务器:192.168.10.107
MySQL数据授权:
在被监控的MySQL数据库服务器上
mysql> grant usage on *.* to [email protected] identified by "123456";(注意ip为监控端的ip)
mysql> grant usage on *.* to [email protected] identified by "123456";
mysql> flush privileges;
在监控服务器上
1》查看当前连接到数据库的连接数
cd /usr/local/nagios/libexec
./check_mysql_health -hostname 127.0.0.1 -username root -password 123456 -mode threads-connected
OK �C 2 client connection threads | threads_connected=2;10;20
threads_connected=3;10;20
3表示连接数
10 表示warning阀值(默认)
20 表示critical阀值(默认)
―――――――――――――――――――�C
nagios-mysql-plugins插件监控数据库(插件见附件)
插件内容
check_db_mysql.pl 检测mysql是否运行
check_errorlog_mysql.pl 检测mysql数据库错误日志
check_repl_mysql_cnt_slave_hosts.pl 统计连接到从主机数
check_repl_mysql_heartbeat.pl 检测心跳 (安装完默认名字是check_repl_mysql_hearbeat.pl)
check_repl_mysql_io_thread.pl 检测IO线程
check_repl_mysql_read_exec_pos.pl
check_repl_mysql_readonly.pl 检测从是否设置为只读
check_repl_mysql_seconds_behind_master.pl检测从多少时间与主同步
check_repl_mysql_sql_thread.pl 检测SQL线程
perf_mysql.pl 收集性能数据
perf_mysql.pl -m 选项
connections,
thread_cache,
network_traffic,
queries,query_cache,
myisam_key_buffer,
table_cache,
temporary_tables,
tables,
slow_queries,
bin_log,uptime,
innodb_buffer_pool,
innodb_buffer_pool_io,
innodb_io,innodb_data,
innodb_logfile,
innodb_row_locking,
innodb_queries
./perf_mysql.pl -m connections
./perf_mysql.pl -m myisam_key_buffer
++++++++++++++++++++++++++++++++++++++
�C查看当前连接到数据库的连接数:
[root@localhost mysql]# /usr/local/nagios/libexec/check_mysql_health --hostname IP --port 3306 --username "USER" --password "PASSWORD" --mode threads-connected
OK - 10 client connection threads | threads_connected=10;10;20
如果此处报错:
CRITICAL - cannot connect to information_schema. Can't locate DBI.pm in @INC (@INC contains: /usr/local/nagios/libexec /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .)
或者当出现Can't locate DBI.pm的错误时
安装dbd-mysql:
yum install perl-DBD-MySQL perl-DBI
===============
注意:阀值设置
-w 1-c 2
-w 1: -c 2: (有的需要在阀值后加冒号)