zhmg23

我们是如此的不同
资深运维工程师互荐群: 102123162

总结nagios监控MysQL方法

1. 在要监控的数据库服务器新建库和用户(或者你用所需要监控的数据库名、用户名):

CREATE DATABASE nagiosdb DEFAULT CHARSET=utf8;  

GRANT SELECT ON nagiosdb.* TO 'nagios'@'192.168.100.%'; 

UPDATE mysql.user SET 'Password' = PASSWORD('nagpasswd123') WHERE 'User' = 'nagios' 

FLUSH PRIVILEGES;  


2.被监控端安装nagios客户端:

这个安装过程,前面的文章有介绍

安装完成后,修改nrpe.cfg

vi /usr/local/nagios/etc/nrpe.cfg  

command[check_mysql_status]=/usr/local/nagios/libexec/check_mysql -H 192.168.100.200 -u nagios -d nagiosdb -p 'nagpasswd123'


#找出nrpe的pid,并结束进程

#netstat -ntpl |grep nrpe |awk '{print $7}'

28855/nrpe


# kill -9 28855


重新启动

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d



3.监控端服务器:

vi /usr/local/nagios/etc/objects/commands.cfg  

#check_mysql  

define command{

command_name check_mysql

command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagiosdb -p nagpasswd123

}


4.在监控端服务器的*.cfg中添加:

define service {


                host_name 192.168.100.200

                service_description                   Check mysql

                check_command                         check_nrpe!check_mysql_status

                check_period                          24x7

                notification_period                   24x7

                use                                   generic-service,srv-pnp

                contact_groups                        +admins

}


5. 重启nagios 观察监控页面

总结nagios监控MysQL方法 - zhm - 合肥运维

 


注:也可以服务端或客户用命令检测是否能收集到信息,如下:

被监控端执行:

# /usr/local/nagios/libexec/check_mysql -H 192.168.100.200 -u nagios -d nagiosdb -p 'nagpasswd123'

Uptime: 11821543  Threads: 3  Questions: 37048  Slow queries: 0  Opens: 49  Flush tables: 1  Open tables: 42  Queries per second avg: 0.003|Connections=556c;;; Open_files=23;;; Open_tables=42;;; Qcache_free_memory=33305944;;; Qcache_hits=29985c;;; Qcache_inserts=1337c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=411c;;; Qcache_queries_in_cache=18;;; Queries=37049c;;; Questions=35973c;;; Table_locks_waited=0c;;; Threads_connected=3;;; Threads_running=1;;; Uptime=11821543c;;;


监控端服务器执行:

# /usr/local/nagios/libexec/check_mysql -H 192.168.100.200 -u nagios -d nagiosdb -p 'nagpasswd123'

Uptime: 11821576  Threads: 3  Questions: 37051  Slow queries: 0  Opens: 49  Flush tables: 1  Open tables: 42  Queries per second avg: 0.003


上面-H 被监控端IP地址  -u 数据库用户名  -d 数据库名  -p  数据库密码

评论