首页 > 代码库 > nagios监控nginx状态(check_nginx_status.pl)
nagios监控nginx状态(check_nginx_status.pl)
1、安装所需组件
yum install perl perl-devel perl-CPAN bc -y
perl -MCPAN -eshell & cpan> install Bundle::LWP
编译安装nrpe(参考教程:http://2860664.blog.51cto.com/2850664/1559056)
以下是被监控端设置
2、下载check_nginx_status.pl脚本
下载地址:https://codeload.github.com/regilero/check_nginx_status/zip/master
解压文件后,上传check_nginx_status.pl到/usr/local/nagios/libexec
chmod +x check_nginx_status.pl
chown nagios.nagcmd check_nginx_status.pl
3、在被监控端测试脚本
cd /usr/local/nagios/libexec
./check_nginx_status.pl -H 192.168.1.247 -s www.xxx.com -P 80
NGINX OK - 0.067 sec. response time, Active: 1 (Writing: 1 Reading: 0 Waiting: 0) ReqPerSec: 0.111 ConnPerSec: 0.111 ReqPerConn: 1.000|Writing=1;;;; Reading=0;;;; Waiting=0;;;; Active=1;;;; ReqPerSec=0.111111;;;; ConnPerSec=0.111111;;;; ReqPerConn=1.000000;;;;
其中红色为nginx服务器的IP地址;绿色为需要监控的网站网址。
4、vi /usr/local/nagios/etc/nrpe.cfg 添加
command[check_nginx]=/usr/local/nagios/libexec/check_nginx_status.pl -H 192.168.1.247 -s www.xxx.com -P 80
5、删除/tmp生成的192.168.1.247_check_nginx_status8d727909e5ace94dc547c3af50af6cb9不然后面后报错!提示无法生成文件。
rm /tmp/192.168.1.247_check_nginx_status8d727909e5ace94dc547c3af50af6cb9
以下是nagios主机的设置
5、服务器端测试
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.247 -c check_nginx
NGINX OK - 0.065 sec. response time, Active: 1 (Writing: 1 Reading: 0 Waiting: 0) ReqPerSec: 0.020 ConnPerSec: 0.020 ReqPerConn: 1.000|Writing=1;;;; Reading=0;;;; Waiting=0;;;; Active=1;;;; ReqPerSec=0.020000;;;; ConnPerSec=0.020000;;;; ReqPerConn=1.000000;;;;
vi /usr/local/nagios/etc/nagios.cfg 添加
cfg_file=/usr/local/nagios/etc/objects/nginx.cfg
6、touch /usr/local/nagios/etc/objects/nginx.cfg
vi /usr/local/nagios/etc/objects/nginx.cfg (注意修改被监控端的IP)内容如下
****************************************我是分割线************************************
define host{ use linux-server host_name nginx alias nginx address 被监控端IP } define service{ use generic-service host_name nginx service_description check-swap check_command check_nrpe!check_swap } define service{ use generic-service host_name nginx service_description check-load check_command check_nrpe!check_load } define service{ use generic-service host_name nginx service_description check-disk check_command check_nrpe!check_sda1 } define service{ use generic-service host_name nginx service_description check-users check_command check_nrpe!check_users } define service{ use generic-service host_name nginx service_description otal_procs check_command check_nrpe!check_total_procs } define service{ use generic-service ; Name of service template to use host_name nginx service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ use generic-service host_name nginx service_description nginx_status check_command check_nrpe!check_nginx! notifications_enabled 0 }
****************************************我也是分割线************************************
报错信息
7、nagios服务器报错
NGINX UNKNOWN - unable to write temporary data in:/tmp/192.168.1.247_check_nginx_status8d727909e5ace94dc547c3af50af6cb9
解决方法:删除被监控主机/tmp下的文件192.168.1.247_check_nginx_status8d727909e5ace94dc547c3af50af6cb9
rm /tmp/192.168.1.247_check_nginx_status8d727909e5ace94dc547c3af50af6cb9
本文出自 “linux相关分享” 博客,请务必保留此出处http://2860664.blog.51cto.com/2850664/1564225
nagios监控nginx状态(check_nginx_status.pl)