1.Backgroundnginx
ngx_http_stub_status_module 是一个 Nginx 的内置 HTTP 模块,该模块能够提供 Nginx 的状态信息。默认状况下这个模块是不被编译进来的,因此在编译 Nginx 时要指定加载该模块:浏览器
--with-http_stub_status_module
固然了,若是你是从新编译,仅仅-s reload是不够的,可能须要用到平滑升级:《高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx》。服务器
为何拿它作例子?由于它也是个足够短小精悍的模块,是一个典型 handler 模块。那么之后咱们讲解模块的过程,都是:并发
1).简要的介绍
2).使用的实例
3).指令介绍
4).源码分析源码分析
2.Simple example性能
location /nginx_status { #copied from http://blog.kovyrin.net/2006/04/29/monitoring-nginx-with-rrdtool/ stub_status on; access_log off; allow SOME.IP.ADD.RESS; deny all; }
咱们假设你是在本机上实验,而且开启的是 80 端口,那么在浏览器中输入:http://localhost/nginx_status 会看到这样的信息:spa
Active connections: 291 server accepts handled requests 16630948 16630948 31070465 Reading: 6 Writing: 179 Waiting: 106
其含义很容易理解:.net
第一行
当前的活跃链接数:291 #我的认为是处于 SYN_RCVD、ESTABLISHED 状态的链接,等于 Reading + Writing + Waiting
第二行
服务器已接受的链接数:16630948(accepted connection #),已接收来自客户端的链接数,也是被Worker进程接收的链接数。
服务器已处理的链接数:16630948(handled connection #),已被处理的链接总数,其值通常与accepts相等,除非受到了某些资源的限制,如:设置了worker_connections的数量限制。
服务器已处理的请求:31070465(能够算出,平均每一个链接有 1.8 个请求)(handled connection #)
第三行
Reading – Nginx 正在读取请求头的链接数为 6;
Writting – Nginx 正在读取请求体、处理请求并发送响应给客户端的链接数为 179;
Waiting – 当前活动的长链接数:106。 #只是keep-alive,没有活动的链接。code
Nginx 官方的解释以下:server
active connections – number of all open connections
server accepts handled requests – nginx accepted 16630948 connections, handled 16630948 connections (no one was closed just it was accepted), and handles 31070465 requests (1.8 requests per connection)
reading – nginx reads request header
writing – nginx reads request body, processes request, or writes response to a client
waiting – keep-alive connections, actually it is active - (reading + writing)
3 Directives
这个模块中的惟一一个指令,是:
stub_status
语法:stub_status on
做用域:location
功能:统计这个 location 的信息。
转自:http://blog.csdn.net/poechant/article/details/7627843