Skip to content

nagios 检查 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]

-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!!! <== Your clear-text password could be visible as a process table entry -S, --check-slave Check if the slave thread is running properly. -w, --warning Exit with WARNING status if slave server is more than INTEGER seconds behind master -c, --critical Exit with CRITICAL status if slave server is more then INTEGER seconds behind master There are no required arguments. By default, the local database is checked using the default unix socket. You can force TCP on localhost by using an IP address or FQDN ('localhost' will use the socket as well). Send email to [email protected] if you have questions regarding use of this software. To submit patches or suggest improvements, send email to [email protected]


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


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

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’


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

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


service nagios reload

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


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



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

    check_mysql_health更好一些,还可以同时输出performance data,有利于性能视图的生成。

  2. C1G says


Continuing the Discussion

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

    […] 安装参考: […]

Some HTML is OK

or, reply to this post via trackback.