Module ngx_http_status_module

ngx_http_status_module模块提供对各种状态信息的访问。

Note

在 1.13.10 之前,此模块是我们commercial subscription的一部分。在 1.13.3 中已被ngx_http_api_module模块取代。

Example Configuration

http {
    upstream backend {
        zone http_backend 64k;

        server backend1.example.com weight=5;
        server backend2.example.com;
    }

    proxy_cache_path /data/nginx/cache_backend keys_zone=cache_backend:10m;

    server {
        server_name backend.example.com;

        location / {
            proxy_pass  http://backend;
            proxy_cache cache_backend;

            health_check;
        }

        status_zone server_backend;
    }

    server {
        listen 127.0.0.1;

        location /upstream_conf {
            upstream_conf;
        }

        location /status {
            status;
        }

        location = /status.html {
        }
    }
}

stream {
    upstream backend {
        zone stream_backend 64k;

        server backend1.example.com:12345 weight=5;
        server backend2.example.com:12345;
    }

    server {
        listen      127.0.0.1:12345;
        proxy_pass  backend;
        status_zone server_backend;
        health_check;
    }
}

使用此配置的状态请求示例:

http://127.0.0.1/status
http://127.0.0.1/status/nginx_version
http://127.0.0.1/status/caches/cache_backend
http://127.0.0.1/status/upstreams
http://127.0.0.1/status/upstreams/backend
http://127.0.0.1/status/upstreams/backend/peers/1
http://127.0.0.1/status/upstreams/backend/peers/1/weight
http://127.0.0.1/status/stream
http://127.0.0.1/status/stream/upstreams
http://127.0.0.1/status/stream/upstreams/backend
http://127.0.0.1/status/stream/upstreams/backend/peers/1
http://127.0.0.1/status/stream/upstreams/backend/peers/1/weight

此发行版随附了简单的监视页面,在默认配置中,该页面可通过“ /status.html”访问。它要求如上所示配置位置“ /status”和“ /status.html”。

Directives

Syntax:status;
Default:
Context:location

可以从周围位置访问状态信息。可以访问此位置limited

Syntax:status_format json;

status_format jsonp [callback];
默认值:status_format json;
上下文: httpserverlocation

默认情况下,状态信息以 JSON 格式输出。

或者,数据可以作为 JSONP 输出。 callback参数指定回调函数的名称。参数值可以包含变量。如果省略参数,或者计算值是一个空字符串,则使用“ ngx_status_jsonp_callback”。

Syntax:status_zone zone;
Default:
Context:server

允许在指定的zone中收集虚拟httpstream(1.7.11)服务器状态信息。多个服务器可以共享同一区域。

Data

提供以下状态信息:

version

  • 提供的数据集的版本。当前版本是 8.

  • nginx_version

    • Nginx 的版本。

nginx_build

  • Nginx 构建的名称。

  • address

    • 接受状态请求的服务器的地址。

generation

load_timestamp

  • 上一次重新配置的时间,以毫秒为单位,以毫秒为单位。

  • timestamp

    • 自大纪元以来的当前时间(以毫秒为单位)。

pid

  • 处理状态请求的工作进程的 ID。

ppid

processes

    • connections
    • accepted

    • 接受的客户端连接总数。

  • dropped

    • 断开的客户端连接总数。
  • active

    • 当前活动的客户端连接数。
  • idle

    • 当前空闲的客户端连接数。

ssl

    • handshakes

    • 成功的 SSL 握手总数。

  • handshakes_failed

    • SSL 握手失败的总数。
  • session_reuses

    • SSL 握手期间会话重用的总数。
  • requests

      • total

      • 客户端请求总数。

    • current

      • 当前的客户端请求数。

server_zones

  • 对于每个status_zone

  • processing

    • 当前正在处理的客户端请求数。

    • requests

      • 从客户端收到的客户端请求总数。
    • responses

        • total

        • 发送给客户的响应总数。

      • 1xx , 2xx , 3xx , 4xx , 5xx

        • 状态码为 1xx,2xx,3xx,4xx 和 5xx 的响应数。

discarded

 - The total number of requests completed without sending a response\.
  • received

    • 从客户端收到的字节总数。
  • sent

    • 发送给客户端的字节总数。

slabs

  • 对于使用平板分配器的每个共享内存区域:

  • pages

      • used

      • 当前已使用的内存页数。

    • free

      • 当前的可用内存页数。
    • slots

      • 对于每种内存插槽大小(8、16、32、64、128 等),提供以下数据:
  • used

     - The current number of used memory slots\.
    
    • free

      • 当前的可用内存插槽数。
    • reqs

      • 分配指定大小的内存的总尝试次数。
    • fails

      • 尝试分配指定大小的内存失败的次数。

upstreams

peers

 - For each [server](http-ngx_http_upstream_module.html#server), the following data are provided: 

id

   - The ID of the server\.

 - `server`

   - An [address](http-ngx_http_upstream_module.html#server) of the server\.

name

   - The name of the server specified in the [server](http-ngx_http_upstream_module.html#server) directive\.

service

   - The [service](http-ngx_http_upstream_module.html#service) parameter value of the [server](http-ngx_http_upstream_module.html#server) directive\.

 - `backup`

   - A boolean value indicating whether the server is a [backup](http-ngx_http_upstream_module.html#backup) server\.

 - `weight`

   - [Weight](http-ngx_http_upstream_module.html#weight) of the server\.

state

   - Current state, which may be one of "  `up` ", "  `draining` ", "  `down` ", "  `unavail` ", "  `checking` ", or "  `unhealthy` "\.

 - `active`

   - The current number of active connections\.

max_conns

   - The [max_conns](http-ngx_http_upstream_module.html#max_conns) limit for the server\.

 - `requests`

   - The total number of client requests forwarded to this server\.

 - `responses`

   - - `total`

     - The total number of responses obtained from this server\.

   - `1xx` ,  `2xx` ,  `3xx` ,  `4xx` ,  `5xx`

     - The number of responses with status codes 1xx, 2xx, 3xx, 4xx, and 5xx\.

 - `sent`

   - The total number of bytes sent to this server\.

 - `received`

   - The total number of bytes received from this server\.

 - `fails`

   - The total number of unsuccessful attempts to communicate with the server\.

 - `unavail`

   - How many times the server became unavailable for client requests \(state "  `unavail` "\) due to the number of unsuccessful attempts reaching the [max_fails](http-ngx_http_upstream_module.html#max_fails) threshold\.

 - `health_checks`

   - - `checks`

     - The total number of [health check](http-ngx_http_upstream_hc_module.html#health_check) requests made\.

   - `fails`

     - The number of failed health checks\.

   - `unhealthy`

     - How many times the server became unhealthy \(state "  `unhealthy` "\)\.

   - `last_passed`

     - Boolean indicating if the last health check request was successful and passed [tests](http-ngx_http_upstream_hc_module.html#match)\.

 - `downtime`

   - Total time the server was in the "  `unavail` ", "  `checking` ", and "  `unhealthy` " states\.

 - `downstart`

   - The time \(in milliseconds since Epoch\) when the server became "  `unavail` ", "  `checking` ", or "  `unhealthy` "\.

selected

   - The time \(in milliseconds since Epoch\) when the server was last selected to process a request \(1\.7\.5\)\.

header_time

   - The average time to get the [response header](http-ngx_http_upstream_module.html#var_upstream_header_time) from the server \(1\.7\.10\)\. Prior to version 1\.11\.6, the field was available only when using the [least_time](http-ngx_http_upstream_module.html#least_time) load balancing method\.

response_time

   - The average time to get the [full response](http-ngx_http_upstream_module.html#var_upstream_response_time) from the server \(1\.7\.10\)\. Prior to version 1\.11\.6, the field was available only when using the [least_time](http-ngx_http_upstream_module.html#least_time) load balancing method\.
  • keepalive

zombies

 - The current number of servers removed from the group but still processing active client requests\.

zone

 - The name of the shared memory [zone](http-ngx_http_upstream_module.html#zone) that keeps the group's configuration and run\-time state\.

queue

 - For the requests [queue](http-ngx_http_upstream_module.html#queue), the following data are provided: 
  • size

     - The current number of requests in the queue\.
    

max_size

   - The maximum number of requests that can be in the queue at the same time\.

 - `overflows`

   - The total number of requests rejected due to the queue overflow\.

caches

  • 对于每个缓存(由proxy_cache_path等配置):

  • size

    • 当前缓存的大小。

    • max_size

      • 配置中指定的最大缓存大小限制。
    • cold

      • 一个布尔值,指示“缓存加载器”进程是否仍在将数据从磁盘加载到缓存中。
    • hit , stale , updating , revalidated

      • bytes

        • 从缓存读取的字节总数。
    • miss , expired , bypass

        • responses

        • 未从缓存中获取的响应总数(由于proxy_cache_bypass等导致丢失,过期或绕过)。

      • bytes

        • 从代理服务器读取的字节总数。
      • responses_written

        • 写入缓存的响应总数。
      • bytes_written

        • 写入缓存的总字节数。

stream

  • processing

    • The number of client connections that are currently being processed.
  • connections

    • 客户端接受的连接总数。

sessions

   - - `total`

     - The total number of completed client sessions\.

   - `2xx` ,  `4xx` ,  `5xx`

     - The number of sessions completed with [status codes](stream-ngx_stream_core_module.html#var_status) 2xx, 4xx, or 5xx\.

discarded

   - The total number of connections completed without creating a session\.

 - `received`

   - The total number of bytes received from clients\.

 - `sent`

   - The total number of bytes sent to clients\.

upstreams

 - For each [dynamically configurable](stream-ngx_stream_upstream_module.html#zone) [group](stream-ngx_stream_upstream_module.html#upstream), the following data are provided: 
  • peers

     - For each [server](stream-ngx_stream_upstream_module.html#server) the following data are provided: 
    
  • id

       - The ID of the server\.
    
     - `server`
    
       - An [address](stream-ngx_stream_upstream_module.html#server) of the server\.
    

name

     - The name of the server specified in the [server](stream-ngx_stream_upstream_module.html#server) directive\.

service

     - The [service](stream-ngx_stream_upstream_module.html#service) parameter value of the [server](stream-ngx_stream_upstream_module.html#server) directive\.

   - `backup`

     - A boolean value indicating whether the server is a [backup](stream-ngx_stream_upstream_module.html#backup) server\.

   - `weight`

     - [Weight](stream-ngx_stream_upstream_module.html#weight) of the server\.

   - `state`

     - Current state, which may be one of "  `up` ", "  `down` ", "  `unavail` ", "  `checking` ", or "  `unhealthy` "\.

   - `active`

     - The current number of connections\.

   - `max_conns`

     - The [max_conns](stream-ngx_stream_upstream_module.html#max_conns) limit for the server\.

   - `connections`

     - The total number of client connections forwarded to this server\.

   - `connect_time`

     - The average time to connect to the upstream server\. Prior to version 1\.11\.6, the field was available only when using the [least_time](stream-ngx_stream_upstream_module.html#least_time) load balancing method\.

   - `first_byte_time`

     - The average time to receive the first byte of data\. Prior to version 1\.11\.6, the field was available only when using the [least_time](stream-ngx_stream_upstream_module.html#least_time) load balancing method\.

   - `response_time`

     - The average time to receive the last byte of data\. Prior to version 1\.11\.6, the field was available only when using the [least_time](stream-ngx_stream_upstream_module.html#least_time) load balancing method\.

   - `sent`

     - The total number of bytes sent to this server\.

   - `received`

     - The total number of bytes received from this server\.

   - `fails`

     - The total number of unsuccessful attempts to communicate with the server\.

   - `unavail`

     - How many times the server became unavailable for client connections \(state "  `unavail` "\) due to the number of unsuccessful attempts reaching the [max_fails](stream-ngx_stream_upstream_module.html#max_fails) threshold\.

   - `health_checks`

     - - `checks`

       - The total number of [health check](stream-ngx_stream_upstream_hc_module.html#health_check) requests made\.

     - `fails`

       - The number of failed health checks\.

     - `unhealthy`

       - How many times the server became unhealthy \(state "  `unhealthy` "\)\.

     - `last_passed`

       - Boolean indicating if the last health check request was successful and passed [tests](stream-ngx_stream_upstream_hc_module.html#match)\.

   - `downtime`

     - Total time the server was in the "  `unavail` ", "  `checking` ", and "  `unhealthy` " states\.

   - `downstart`

     - The time \(in milliseconds since Epoch\) when the server became "  `unavail` ", "  `checking` ", or "  `unhealthy` "\.

   - `selected`

     - The time \(in milliseconds since Epoch\) when the server was last selected to process a connection\.

 - `zombies`

   - The current number of servers removed from the group but still processing active client connections\.

 - `zone`

   - The name of the shared memory [zone](stream-ngx_stream_upstream_module.html#zone) that keeps the group's configuration and run\-time state\.

Compatibility