nagios mysql 监控(linux服务器)

安装mysql之后,需要对mysql服务进行监控。

nagios开源自带的check_mysql 对 mysql 的slave 机监控倒是不错。但是对数据库主机监控就略显不足了。

使用一个监控插件:check_mysql_health

下载和使用方法见:

http://exchange.nagios.org/directory/MySQL/check_mysql_health/details

具体监控:

对于slave 机 ,使用nagios 自带的 check_mysql 监控

command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql -H localhost -s /tmp/mysql.sock -u root -p xxx -S -w 1 -c 3

其中用户和密码有可能会更改。延迟1秒警告,延迟3秒报警。

check_mysql_health 监控mysql master 服务器

/usr/local/nagios/libexec/custom/check_mysql_health --hostname localhost --socket /tmp/mysql.sock --username root --password xxxxxx --mode xxxxx --warning xxxxx --criticalxxxxx

mode:

connection-time (Time to connect to the server) 

uptime (Time the server is running) 

threads-connected (Number of currently open connections) 

threadcache-hitrate (线程缓存命中率) 

slave-lag (Seconds behind master) 

slave-io-running (Slave io running: Yes) 

slave-sql-running (Slave sql running: Yes) 

qcache-hitrate (查询命中率,如果这个值接近100%,说明服务器select的优化就越好) 

qcache-lowmem-prunes (因为内存小,从内存删除缓存查询的数量,可以增大query_cache_size,减小lowmem,增加命中率的优化) 

keycache-hitrate (MyISAM key 缓存命中率,如果命中率太低,增大key_buffer_size) 

bufferpool-hitrate (InnoDB 缓冲池命中率) 

bufferpool-wait-free (InnoDB 缓冲池等待清理的页面) 

log-waits (InnoDB log 等待写入时间,如果这个等待时间太大,增大log缓冲池大小) 

tablecache-hitrate (Table 缓存命中率) 

table-lock-contention (Table 的lock率) 

index-usage (索引使用率,越大说明索引越好,越小说明索引优化不充分) 

tmp-disk-tables (临时表创建的数量) 

slow-queries (慢查询占所有查询的比率,这个值如果很高说明mysql数据库优化不够) 

long-running-procs (长期运行的进程) 

cluster-ndbd-running (mysql集群监控) 

sql (执行一个返回一个数字的SQL,检查mysql是否可以链接查询)


举例:
nrpe.cfg:
command[check_mysql_health]=/usr/local/nagios/libexec/custom/check_mysql_health --hostname localhost --socket /tmp/mysql.sock --username xxxxx --password xxxxx --mode $ARG1$ --warning $ARG2$ --critical $ARG3$ 

xxx.cfg:
define service{
        use                     xxxxxx
        host_name               xxxxxx
        service_description     mysql数据库连接数
        check_command           check_nrpe_args!check_mysql_health!threads-connected!80!120
}

define service{
        use                     xxxxx
        host_name               xxxxx
        service_description     mysql数据库innodb缓存命中
        check_command           check_nrpe_args!check_mysql_health!bufferpool-hitrate
}
define service{
        use                     xxxxx
        host_name               xxxxx
        service_description     mysql数据库innodb缓冲池等待清理的页
        check_command           check_nrpe_args!check_mysql_health!bufferpool-wait-free
}
define service{
        use                     xxxxx
        host_name               xxxxx
        service_description     mysql数据库innodblog写入等待时间
        check_command           check_nrpe_args!check_mysql_health!log-waits
}
define service{
        use                     xxxxx
        host_name               xxxxx                                                                                   
        service_description     mysql数据库锁表率
        check_command           check_nrpe_args!check_mysql_health!table-lock-contention
}
define service{
        use                     xxxxx                                                                                  
        host_name               xxxxx
        service_description     mysql数据库打开文件数
        check_command           check_nrpe_args!check_mysql_health!open-files!80!90
}
define service{
        use                     xxxxx                                                                                 
        host_name               xxxxx
        service_description     mysql数据库慢查询率
        check_command           check_nrpe_args!check_mysql_health!slow-queries!5!10
}

搞定。

PS:对 warnging 和 critical 的值 :  10 就是 大于10%报警, 10: 就是小于10%报警, 不填就是默认的数值。
mode 一个语句只能一个,

--mode xxx1  xxx2    : xxx1 生效
--mode xxx1  --mode xxx2  : xxx2 生效

OVER

猜你喜欢

转载自blog.csdn.net/heli_lieren/article/details/19982173