zabbix-3.2.1监控nginx-1.11.5

声明参考地址:http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/

1.zabbix需要监控nginx,则nginx需要配置ngx_status

  (1) 编译安装时带上--with-http_stub_status_module参数:

    ./configure --prefix=/usr/local/nginx-1.11.5 --with-http_ssl_module --with-http_stub_status_module --with-pcre

  (2)vim /usr/local/nginx-1.11.5/conf/nginx.conf  在server内添加以下内容:

location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.0.150; #(zabbix服务器的IP地址,一般是内网地址)
deny all;
}

 (3)检测--with-http_stub_status_module参数是否生效

    

2.编写客户端脚本 vim /usr/local/zabbix-3.2.1/scripts/ngx-status.sh  赋予执行权限chmod a+x /usr/local/zabbix-3.2.1/scripts/ngx-status.sh  内容如下:

#!/bin/bash

HOST="127.0.0.1"
PORT="80"
 
# 检测nginx进程是否存在
function ping {
    /sbin/pidof nginx | wc -l
}
# 检测nginx性能
function active {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
    /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
# 执行function
$1
 
3.将自定义的UserParameter加入zabbix_agentd.conf配置文件,然后重启agentd
 vim /usr/local/zabbix-3.2.1/etc/zabbix_agentd.conf
   UserParameter=nginx.status[*],/usr/local/zabbix-3.2.1/scripts/ngx-status.sh $1
   
   重启agentd
4.zabbix_get 获取数据,检测配置是否正确
   /usr/local/zabbix-3.2.1/bin/zabbix_get -s 127.0.0.1 -k 'nginx.status[accept]'
   /usr/local/zabbix-3.2.1/bin/zabbix_get -s 127.0.0.1 -k 'nginx.status[ping]'
   
5.模板附件下载:zabbix_monitor_nginx_template_ttlsa_com  :http://www.ttlsa.com/wp-content/uploads/2015/10/zabbix_monitor_nginx_template_ttlsa_com.zip
6.导入模板:配置、模板、导入模板
   

7.给该主机添加nginx的监控项:

   

8.完成,查看图形:

   

 

 交流qq1071179133

 
posted @ 2016-12-06 17:37  chenjianwen  阅读(4454)  评论(3编辑  收藏  举报