1、获取 Nginx 状态( HTTP Stub Status )
1
|
/usr/local/nginx/sbin/nginx -V
|
2、配置 nginx.conf
1
2
3
4
5
6
7
8
|
vim /usr/local/nginx/conf/nginx .conf
location ~ /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.1.14;
deny all;
} |
3、编写脚本获取上面的 key 值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
vim /script/nginx_status .sh
#!/bin/bash case $1 in
active)
curl -s http: //127 .0.0.1 /nginx_status | awk '/Active/ {print $3}' ;;
accepts)
curl -s http: //127 .0.0.1 /nginx_status | awk 'NR==3 {print $1}' ;;
handled)
curl -s http: //127 .0.0.1 /nginx_status | awk 'NR==3 {print $2}' ;;
requests)
curl -s http: //127 .0.0.1 /nginx_status | awk 'NR==3 {print $3}' ;;
reading)
curl -s http: //127 .0.0.1 /nginx_status | awk '/Reading/ {print $2}' ;;
writing)
curl -s http: //127 .0.0.1 /nginx_status | awk '/Writing/ {print $4}' ;;
waiting)
curl -s http: //127 .0.0.1 /nginx_status | awk '/Waiting/ {print $6}' ;;
*)
echo "Usage: $0 { active | accepts | handled | requests | reading | writing | waiting }" ;;
esac chmod a+x /script/nginx_status .sh
|
4、添加自定义 key 配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
vim /usr/local/zabbix/etc/zabbix_agentd .conf.d /nginx_status .conf
# Nginx_status UserParameter=nginx.active, /script/nginx_status .sh active
UserParameter=nginx.accepts, /script/nginx_status .sh accepts
UserParameter=nginx.handled, /script/nginx_status .sh handled
UserParameter=nginx.requests, /script/nginx_status .sh requests
UserParameter=nginx.reading, /script/nginx_status .sh reading
UserParameter=nginx.writing, /script/nginx_status .sh writing
UserParameter=nginx.waiting, /script/nginx_status .sh waiting
5、修改zabbix_agentd.conf vim /usr/local/zabbix/etc/zabbix_agentd .conf
LogFile= /tmp/zabbix_agentd .log
Server=192.168.1.14 ServerActive=192.168.1.14 Hostname=Zabbix server Include= /usr/local/zabbix/etc/zabbix_agentd .conf.d/
EnableRemoteCommands=1 UnsafeUserParameters=1 |
6、Zabbix 服务端测试能否拿到 Key
1
|
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.12 -k nginx.active
|
Nginx 监控项解释
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
## Active connections: 对后端发起的活动连接数
## Server accepts handled requests: Nginx 总共处理了 1 个连接,成功创建了 1 次握手(没有失败次数),总共处理了 1 个请求
## Reading: Nginx 读取到客户端的 Header 信息数
## Writing: Nginx 返回给客户端的 Header 信息数
## Waiting: 开启 keep-alive 的情况下,这个值等于 active - ( reading + writing ), 意思是 Nginx 已经处理完成,正在等待下一次请求指令的驻留连接
## 在访问效率很高,请求很快被处理完毕的情况下,Waiting 数比较多是正常的。如果 reading + writing 数较多,则说明并发访问量很大,正在处理过程中
原文网址:http://blog.chinaunix.net/uid-30272825-id-5115194.html
本文转自1321385590 51CTO博客,原文链接:http://blog.51cto.com/linux10000/1727963,如需转载请自行联系原作者