Nginx-解读内置非默认模块 ngx_http_stub_status_module

1.Background

  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 会看到这样的信息:

Active connections: 291
server accepts handled requests
16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106

  其含义很容易理解:

  第一行
    当前的活跃连接数: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,没有活动的连接。


  Nginx 官方的解释如下:

    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

原文地址:https://www.cnblogs.com/JohnABC/p/6193569.html