码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix 监控 nginx

时间:2016-10-31 22:36:09      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:zabbix 监控 nginx

1、nginx里面添加配置:

server {

        listen       80;

        server_name  192.168.1.143;

        location /nginx-status {

                stub_status on;

                access_log  off;

                allow 127.0.0.1;

                allow 192.168.1.109;

                deny all;

         }

}

访问效果:

技术分享

nginx Status 详细说明:

Activeconnections:对后端发起的活动连接数;

server accepts 2349542:nginx 总共处理了2349542个连接;

handled:成功创建了64603417次握手;

requests:总共处理了8798670请求。

Reading:nginx读取客户端的header数;

Writing: nginx 返回给客户端的header数;

Waiting: nginx 请求处理完成,正在等待下一请求指令的连接。

2、在agentd上编写监控nginx的自定义key

   编辑# vim /etc/zabbix/zabbix_agentd.conf

   找到UserParameter

   添加:

UserParameter=Nginx.accepts,  /usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| awk ‘NR==3{print $1}‘  


UserParameter=Nginx.handled,  /usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| awk ‘NR==3{print $2}‘  


UserParameter=Nginx.requests, /usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| awk ‘NR==3{print $3}‘  


UserParameter=Nginx.Connections.Active, /usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘  


UserParameter=Nginx.Connections.Reading,/usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘ 


UserParameter=Nginx.Connections.Writing,/usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘  


UserParameter=Nginx.Connections.Waiting,/usr/bin/curl "http://192.168.1.143/nginx-status" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘


3、重启zabbix-agent 并测试KEY是否可以获取到数据

[root@bogon ~]# /etc/init.d/zabbix-agent restart

Shutting down Zabbix agent:                                [确定]

Starting Zabbix agent:                                     [确定]

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.accepts"

30758

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.handled"

30763

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.requests"

53012

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.Connections.Active"

10

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.Connections.Reading"

0

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.Connections.Writing"

1

[root@bogon ~]# zabbix_get -s 192.168.1.143 -p 10050 -k "Nginx.Connections.Waiting"

28

[root@bogon ~]# /usr/bin/curl "http://192.168.1.143/nginx-status"

Active connections: 37

server accepts handled requests

 30818 30818 53134


4、添加 Items 和 Graphs 监控结果

   技术分享



zabbix 监控 nginx

标签:zabbix 监控 nginx

原文地址:http://wangqh.blog.51cto.com/5367393/1867713

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!