线上用的是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;
#nagios查看nginx信息
location /nginx_status {
stub_status on;
#allow 10.252.12.7;
#deny all;
}
#nagios查看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.252.12.7;
#deny all;
}
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配置
/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
客户端的配置到这里就结束了。
在服务器端开始测试
[[email protected] libexec]# cd /usr/local/nagios/libexec/
[[email protected] 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;;;;
[[email protected] 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
修改文件
vi /usr/local/nagios/etc/objects/commands.cfg
最后一行添加
# check nginx
define command {
command_name check_nginx_status
command_line $USER1$/check_nginx_status.pl -H $HOSTADDRESS$
}
# check phpfpm
define command {
command_name check_phpfpm_status
command_line $USER1$/check_phpfpm_status.pl -H $HOSTADDRESS$ -u /status?full
}
修改主机文件,添加以下内容
define service{
use generic-service
host_name app_1
service_description nginx_status
check_command check_nginx_status
}
define service{
use generic-service
host_name app_1
service_description phpfpm_status
check_command check_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";
修改为你自己安装的路径
过几分钟查看就会变成绿色了。