Skip to content


nagios 检查 mysql服务

nagios_plugin安装时正确关联mysql后会在libexec下产生check_mysql文件

/usr/local/nagios/libexec/check_mysql -h check_mysql v2034 (nagios-plugins 1.4.13) Copyright (c) 1999-2007 Nagios Plugin Development Team This program tests connections to a mysql server Usage: check_mysql [-d database] [-H host] [-P port] [-s socket] [-u user] [-p password] [-S] Options: -h, –help Print detailed help screen -V, –version Print version information -H, –hostname=ADDRESS Host name, IP Address, or unix socket (must be an absolute path) -P, –port=INTEGER Port number (default: 3306) -s, –socket=STRING Use the specified socket (has no effect if -H is used) -d, –database=STRING Check database with indicated name -u, –username=STRING Connect using the indicated username -p, –password=STRING Use the indicated password to authenticate the connection ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!

创建nagdb空数据库和naguser用户

create database nagemptydb; GRANT select ON nagemptydb.* TO naguser@localhost identified by ‘password123’; FLUSH PRIVILEGES ;

测试check_mysql

sudo -u nagios /usr/local/nagios/libexec/check_mysql -H localhost -u naguser -d nagemptydb -p password123 Uptime: 45850 Threads: 1 Questions: 493233 Slow queries: 0 Opens: 159 Flush tables: 1 Open tables: 153 Queries per second avg: 10.757

修改被子监控机nrpe.cfg增加监控命令 vi /usr/local/nagios/etc/nrpe.cfg

command[check_mysql_status]=/usr/local/nagios/libexec/check_mysql -H localhost -u naguser -d nagemptydb -p ‘password123’

重启被监控机nrpe

ps aux |grep nrpe kill $pid /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

监控机polo.cfg增加 vi /etc/local/nagios/etc/objects/polo.cfg

define service{ use local-service ; Name of service template to use host_name polo service_description mysql_status check_command check_nrpe!check_mysql_status notifications_enabled 0 }

重载入监控机nagios

service nagios reload

访问http://localhost/nagios的service detail

mysql_status Notifications for this service have been disabled PENDING N/A 0d 0h 0m 35s+ 1/4 Service check scheduled for Tue May 19 15:01:30 CST 2009

等一会

mysql_status Notifications for this service have been disabled OK 05-19-2009 15:01:30 0d 0h 1m 5s 1/4 Uptime: 46758 Threads: 1 Questions: 513579 Slow queries: 0 Opens: 160 Flush tables: 1 Open tables: 154 Queries per second avg: 10.983

Posted in Nagios, 技术.

Tagged with , , .


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. 石头 says

    针对mysql的plugin,
    check_mysql_health更好一些,还可以同时输出performance data,有利于性能视图的生成。
    http://www.consol.de/opensource/nagios/check-mysql-health/

  2. C1G says

    那要添加好几项服务呢,
    我主要关注以下两项,每秒查询数好像得不到。
    threads-connected
    slow-queries

Continuing the Discussion

  1. DBA_MYSQL_LINUX_Perl » nagios没有check_mysql与配置 linked to this post on 2012/09/03

    […] 安装参考:http://blog.c1gstudio.com/archives/602 […]



Some HTML is OK

or, reply to this post via trackback.