ngx_http_status_module
5 分钟阅读
Module ngx_http_status_module
https://nginx.org/en/docs/http/ngx_http_status_module.html
The ngx_http_status_module module provides access to various status information.
This module was available as part of our commercial subscription until 1.13.10. It was superseded by the ngx_http_api_module module in 1.13.3.
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;
}
}
Examples of status requests with this configuration:
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
The simple monitoring page is shipped with this distribution, accessible as “/status.html” in the default configuration. It requires the locations “/status” and “/status.html” to be configured as shown above.
Directives
status
Syntax: status;
Default: —
Context: location
The status information will be accessible from the surrounding location. Access to this location should be limited.
status_format
Syntax:status_format json; status_format jsonp [callback];
Default: status_format json;
Context: http, server, location
By default, status information is output in the JSON format.
Alternatively, data may be output as JSONP. The callback parameter specifies the name of a callback function. Parameter value can contain variables. If parameter is omitted, or the computed value is an empty string, then “ngx_status_jsonp_callback” is used.
status_zone
Syntax:status_zone zone;
Default: —
Context: server
Enables collection of virtual http or stream (1.7.11) server status information in the specified zone. Several servers may share the same zone.
Data
The following status information is provided:
versionVersion of the provided data set. The current version is 8.
nginx_versionVersion of nginx.
nginx_buildName of nginx build.
addressThe address of the server that accepted status request.
generationThe total number of configuration reloads.
load_timestampTime of the last reload of configuration, in milliseconds since Epoch.
timestampCurrent time in milliseconds since Epoch.
pidThe ID of the worker process that handled status request.
ppidThe ID of the master process that started the worker process.
processesrespawnedThe total number of abnormally terminated and respawned child processes.connectionsacceptedThe total number of accepted client connections.droppedThe total number of dropped client connections.activeThe current number of active client connections.idleThe current number of idle client connections.sslhandshakesThe total number of successful SSL handshakes.handshakes_failedThe total number of failed SSL handshakes.session_reusesThe total number of session reuses during SSL handshake.requeststotalThe total number of client requests.currentThe current number of client requests.server_zonesFor each status_zone:
processingThe number of client requests that are currently being processed.requestsThe total number of client requests received from clients.responsestotalThe total number of responses sent to clients.1xx,2xx,3xx,4xx,5xxThe number of responses with status codes 1xx, 2xx, 3xx, 4xx, and 5xx.discardedThe total number of requests completed without sending a response.receivedThe total number of bytes received from clients.sentThe total number of bytes sent to clients.slabsFor each shared memory zone that uses slab allocator:
pagesusedThe current number of used memory pages.freeThe current number of free memory pages.slotsFor each memory slot size (8, 16, 32, 64, 128, etc.) the following data are provided:usedThe current number of used memory slots.freeThe current number of free memory slots.reqsThe total number of attempts to allocate memory of specified size.failsThe number of unsuccessful attempts to allocate memory of specified size.upstreamsFor each dynamically configurable group, the following data are provided:
peersFor each server, the following data are provided:idThe ID of the server.serverAn address of the server.nameThe name of the server specified in the server directive.serviceThe service parameter value of the server directive.backupA boolean value indicating whether the server is a backup server.weightWeight of the server.stateCurrent state, which may be one of “up”, “draining”, “down”, “unavail”, “checking”, or “unhealthy”.activeThe current number of active connections.max_connsThe max_conns limit for the server.requestsThe total number of client requests forwarded to this server.responsestotalThe total number of responses obtained from this server.1xx,2xx,3xx,4xx,5xxThe number of responses with status codes 1xx, 2xx, 3xx, 4xx, and 5xx.sentThe total number of bytes sent to this server.receivedThe total number of bytes received from this server.failsThe total number of unsuccessful attempts to communicate with the server.unavailHow many times the server became unavailable for client requests (state “unavail”) due to the number of unsuccessful attempts reaching the max_fails threshold.health_checkschecksThe total number of health check requests made.failsThe number of failed health checks.unhealthyHow many times the server became unhealthy (state “unhealthy”).last_passedBoolean indicating if the last health check request was successful and passed tests.downtimeTotal time the server was in the “unavail”, “checking”, and “unhealthy” states.downstartThe time (in milliseconds since Epoch) when the server became “unavail”, “checking”, or “unhealthy”.selectedThe time (in milliseconds since Epoch) when the server was last selected to process a request (1.7.5).header_timeThe average time to get the response header from the server (1.7.10). Prior to version 1.11.6, the field was available only when using the least_time load balancing method.response_timeThe average time to get the full response from the server (1.7.10). Prior to version 1.11.6, the field was available only when using the least_time load balancing method.keepaliveThe current number of idle keepalive connections.zombiesThe current number of servers removed from the group but still processing active client requests.zoneThe name of the shared memory zone that keeps the group’s configuration and run-time state.queueFor the requests queue, the following data are provided:sizeThe current number of requests in the queue.max_sizeThe maximum number of requests that can be in the queue at the same time.overflowsThe total number of requests rejected due to the queue overflow.cachesFor each cache (configured by proxy_cache_path and the likes):
sizeThe current size of the cache.max_sizeThe limit on the maximum size of the cache specified in the configuration.coldA boolean value indicating whether the “cache loader” process is still loading data from disk into the cache.hit,stale,updating,revalidatedresponsesThe total number of responses read from the cache (hits, or stale responses due to proxy_cache_use_stale and the likes).bytesThe total number of bytes read from the cache.miss,expired,bypassresponsesThe total number of responses not taken from the cache (misses, expires, or bypasses due to proxy_cache_bypass and the likes).bytesThe total number of bytes read from the proxied server.responses_writtenThe total number of responses written to the cache.bytes_writtenThe total number of bytes written to the cache.streamserver_zonesFor each status_zone:processingThe number of client connections that are currently being processed.connectionsThe total number of connections accepted from clients.sessionstotalThe total number of completed client sessions.2xx,4xx,5xxThe number of sessions completed with status codes 2xx, 4xx, or 5xx.discardedThe total number of connections completed without creating a session.receivedThe total number of bytes received from clients.sentThe total number of bytes sent to clients.upstreamsFor each dynamically configurable group, the following data are provided:peersFor each server the following data are provided:idThe ID of the server.serverAn address of the server.nameThe name of the server specified in the server directive.serviceThe service parameter value of the server directive.backupA boolean value indicating whether the server is a backup server.weightWeight of the server.stateCurrent state, which may be one of “up”, “down”, “unavail”, “checking”, or “unhealthy”.activeThe current number of connections.max_connsThe max_conns limit for the server.connectionsThe total number of client connections forwarded to this server.connect_timeThe average time to connect to the upstream server. Prior to version 1.11.6, the field was available only when using the least_time load balancing method.first_byte_timeThe 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 load balancing method.response_timeThe 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 load balancing method.sentThe total number of bytes sent to this server.receivedThe total number of bytes received from this server.failsThe total number of unsuccessful attempts to communicate with the server.unavailHow many times the server became unavailable for client connections (state “unavail”) due to the number of unsuccessful attempts reaching the max_fails threshold.health_checkschecksThe total number of health check requests made.failsThe number of failed health checks.unhealthyHow many times the server became unhealthy (state “unhealthy”).last_passedBoolean indicating if the last health check request was successful and passed tests.downtimeTotal time the server was in the “unavail”, “checking”, and “unhealthy” states.downstartThe time (in milliseconds since Epoch) when the server became “unavail”, “checking”, or “unhealthy”.selectedThe time (in milliseconds since Epoch) when the server was last selected to process a connection.zombiesThe current number of servers removed from the group but still processing active client connections.zoneThe name of the shared memory zone that keeps the group’s configuration and run-time state.
Compatibility
- The zone field in http and stream upstreams was added in version 8.
- The slabs status data were added in version 8.
- The checking state was added in version 8.
- The name and service fields in http and stream upstreams were added in version 8.
- The nginx_build and ppid fields were added in version 8.
- The sessions status data and the discarded field in stream server_zones were added in version 7.
- The zombies field was moved from nginx debug version in version 6.
- The ssl status data were added in version 6.
- The discarded field in server_zones was added in version 6.
- The queue status data were added in version 6.
- The pid field was added in version 6.
- The list of servers in upstreams was moved into peers in version 6.
- The
keepalivefield of an upstream server was removed in version 5. - The stream status data were added in version 5.
- The generation field was added in version 5.
- The respawned field in processes was added in version 5.
- The header_time and response_time fields in upstreams were added in version 5.
- The selected field in upstreams was added in version 4.
- The draining state in upstreams was added in version 4.
- The id and max_conns fields in upstreams were added in version 3.
- The
revalidatedfield in caches was added in version 3. - The server_zones, caches, and load_timestamp status data were added in version 2.