线上用的是Nagios监控,版本是4.0.8
Nginx用的是Tengine最新版,PHP是5.5版本
Nginx插件下载地址
https://exchange.nagios.org/directory/Plugins/Web-Servers/nginx/check_nginx_status-2Epl/details
PHP-FPM插件下载地址
https://github.com/regilero/check_phpfpm_status
在被监控端需要做如下设置
解压里面的文件
得到2个文件
check_nginx_status.pl
check_phpfpm_status.pl
将这2个文件放到/usr/local/nagios/libexec 目录下面
设置权限
cd /usr/local/nagios/libexec/
chmod 755 check_nginx_status.pl check_phpfpm_status.pl
chmod nagios:nagios check_nginx_status.pl check_phpfpm_status.pl
运行pl插件需要安装组件
yum install -y perl-Time-HiRes
修改Nginx配置文件
vi /usr/local/nginx/conf/vhosts/dts.conf
添加蓝色部分
server {
listen 10.168.45.10:80;
server_name dts.xx.com;
root /www/dts/web/www;
index index.php index.html index.htm;
location / {
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#查看nginx信息
location /nginx_status {
stub_status on;
allow 10.168.45.10;
deny all;
}
#查看php信息
location = /status {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
allow 10.168.45.10;
deny all;
}
}
重启加载Nginx配置
/usr/local/nginx/sbin/nginx -s reload
修改php-fpm配置文件
vi /usr/local/php/etc/php-fpm.conf
去除以下一行的分号,开启查看状态
pm.status_path = /status
重新加载php-fpm
/etc/init.d/php-fpm reload
修改nrpe配置文件
vi /usr/local/nagios/etc/nrpe.cfg
最后一行添加
command[nginx_status]=/kuaibao/server/nagios/libexec/check_nginx_status.pl -H dts.xx.com
command[phpfpm_status]=/kuaibao/server/nagios/libexec/check_phpfpm_status.pl -H dts.xx.com -u /status?full
重启nrpe
killall -9 nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
客户端的配置到这里就结束了。
在服务器端开始测试
[root@iZ23zkz654qZ libexec]# cd /usr/local/nagios/libexec/
[root@iZ23zkz654qZ libexec]# ./check_nginx_status.pl -H 10.168.45.10
NGINX OK - 0.054 sec. response time, Active: 11 (Writing: 11 Reading: 0 Waiting: 0) ReqPerSec: 0.000 ConnPerSec: 0.000 ReqPerConn: 0.000|Writing=11;;;; Reading=0;;;; Waiting=0;;;; Active=11;;;; ReqPerSec=0.000000;;;; ConnPerSec=0.000000;;;; ReqPerConn=0.000000;;;;
[root@iZ23zkz654qZ libexec]# ./check_phpfpm_status.pl -H 10.168.45.10 -u /status?full
PHP-FPM OK - www, 0.073 sec. response time, Busy/Idle 12/1298, (max: 34, reached: 0), ReqPerSec 90.1, Queue 0 (len: 128, reached: 0)|Idle=1298 Busy=12 MaxProcesses=34 MaxProcessesReach=0 Queue=0 MaxQueueReach=0 QueueLen=128 ReqPerSec=90.084746
修改主机文件,添加以下内容
define service{
use generic-service
host_name app_1
service_description nginx_status
check_command check_nrpe!nginx_status
}
define service{
use generic-service
host_name app_1
service_description phpfpm_status
check_command check_nrpe!phpfpm_status
}
重启Nagios
/etc/init.d/nagios restart
查看页面
第一次查看页面,会发现红色信息,提示
/tmp/10.168.45.10_check_nginx_status3b462c1ca9852cf74bb3c8c3c6a10872
/tmp/10.168.45.10_check_phpfpm_status3b683c1ca9817cf74ff3c7c3c6a10884
无法写入
解决办法就是删除这个文件,等待几分钟,就会变成绿色了。
如果Nagios的安装路径不是/usr/local/nagios
那么查看phpfpm_status的时候,提示找不到加载utils.pm文件
解决方法就是修改check_phpfpm_status.pl文件
将use lib "/usr/local/nagios/libexec";
修改为你自己安装的路径
过几分钟查看就会变成绿色了。