您的位置:首页 > 数据库 > MySQL

nagios利用NRPE监控CPU负载 磁盘 & mysql nginx 的一些方法

2010-11-26 15:15 531 查看
关于nagios监控 mysql nginx 的一些方法

nagios 就默认配置安装时不能监控mysql 和 nginx的,mysql 还好一点,但nginx的监控看了很多文档还是不成功,不过在一个外国网站找到了一个监控nginx的方法给大家分享一下

通过nrpe 来监控nginx的进程是否运行 还可以顺便监控 CPU 硬盘呢

1.在监控机上安装NRPE

tar -zxvf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure --prefix=/usr/local/nagios

make all

make install-plugin

2.在被监控机上安装nagios插件和NRPE

(1).先增加nagios用户:

useradd nagios

(2.)安装nagios插件:

tar -zxvf nagios-plugins-1.4.14.tar.gz

cd nagios-plugins-1.4.14

./configure --prefix=/usr/local/nagios

make

make install

(3).安装nrpe:

tar -zxvf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure --prefix=/usr/local/nagios

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd nrpe安装为xinetd服务

(4).编辑nrpe配置文件,增加监控机地址:

#vi /etc/xinetd.d/nrpe

only_from = 127.0.0.1 10.1.1.14

(5).修改services文件,增加端口

#vi /etc/services

nrpe 5666/tcp #NRPE

(6).重启xinetd服务

service xinetd restart

(7).查看服务是否启动

#/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.12

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

command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2 --意思是监控第二个分区

参考#command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% -监控内存

如果出现Connection refused by host 需要安装yum intall openssl*

至此被监控机上的操作就结束了,如果有需要增加监控项,需修改/etc/xinetd.d/nrpe文件。

3.修改监控机上commands.cfg文件,增加check_nrpe的定义:

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

4.在监控机上测试与被监控机的通讯是否正常:

[root@test1 objects]# /usr/local/nagios/libexec/check_nrpe -H 10.1.1.6(被监控IP) -c check_load

OK - load average: 0.05, 0.06, 0.00|load1=0.050;15.000;30.000;0; load5=0.060;10.000;25.000;0; load15=0.000;5.000;20.000;0;

能够正常获取信息。

5.修改服务配置文件:

增加:

define service {

host_name nginx1.dog.com

max_check_attempts 5

check_period 24x7

notification_interval 10

normal_check_interval 1

retry_check_interval 1

service_description diskINFO

check_command check_nrpe!check_sda2

notification_period 24x7

notification_options w,u,c,r

contact_groups doggroup

}

define service {

host_name nginx1.dog.com

max_check_attempts 5

check_period 24x7

notification_interval 10

normal_check_interval 1

retry_check_interval 1

service_description checkLoad

check_command check_nrpe!check_load

notification_period 24x7

notification_options w,u,c,r

contact_groups doggroup

}

define service {

host_name nginx1.dog.com

max_check_attempts 5

check_period 24x7

notification_interval 10

normal_check_interval 1

retry_check_interval 1

service_description checkswap

check_command check_nrpe!check_swap

notification_period 24x7

notification_options w,u,c,r

contact_groups doggroup

}

3.有关于check_load的用法及意义这个插件是用来检测系统当前的cpu负载,使用的方法为check_load [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15在unix里面负载的均值通常表示是1分钟,5分钟,15分钟内平均有多少进程处于等待状态.例如check_load -w 15,10,5 -c 30,25,20这个命令的意义如下当1分钟多于15个进程等待,5分钟多于10个,15分钟多于5个则为warning状态当1分钟多于30个进程等待,5分钟多于25个,15分钟多于20个则为critical状态

监控NGINX 进程是否运行(所有进程都适用哦。很有用)

在被监控机(10.1.1.2)上运行,可以测试是否有进程运行

/usr/local/nagios/libexec/check_procs -c 1:30 -C nginx

在被监控机上编辑 /usr/local/nagios/etc/nrpe_local.cfg

加入:

command[check_nginx]=/usr/local/nagios/libexec/check_procs -c 1:30 -C nginx

进入监控机

/usr/local/nagios/etc/services.cfg

define service {

host_name nginx1.dog.com

service_description CHECK_NGINX

check_period 24x7

max_check_attempts 3

normal_check_interval 5

retry_check_interval 3

contact_groups sagroup

notification_interval 480

notification_period 24x7

notification_options w,u,c,r

check_command check_nrpe!check_nginx

notifications_enabled 1

}

重启nagios服务

监控mysql

cd /usr/lib/nagios/plugins

./check_mysql -H 10.1.1.2 -u tt -p 123 -P 3306

通这命令可以检测mysql 的状况 注意:tt 是我先再mysql授权的用户,密码是123

vim commands.cfg

增加以下:

define command{

command_name check_mysql

command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u tt -p 123 -P 3306

}

vi /etc/nagios/services.cfg

加入:

define service {

host_name mysql1.dog.com

max_check_attempts 5

check_period 24x7

notification_interval 10

normal_check_interval 1

retry_check_interval 1

service_description check_mysql

check_command check_mysql ----注意哦。

notification_period 24x7

notification_options w,u,c,r

contact_groups doggroup

}

故障:

不知道为什么我用守护进程启动的时候发现不行的,以前是可以的,郁闷死了,后来找了另一方法:

将nrpe独立运行

vi /etc/server

将原来的nrpe 5666/tcp 注释

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

加入 allowed_hosts=127.0.0.1,10.1.1.14(监控机)

command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2 --意思是监控第二个分区

参考#command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% -监控内存

保存

删除原来的进程(没有就不需要):

lsof -i:5666

kill -9 nrpe的ID

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 重新启动

开机运行

vi /etc/rc.d/rc.local

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

本文出自 “有那么一棵树” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: