时间:2023-07-14 12:12:01 | 来源:网站运营
时间:2023-07-14 12:12:01 来源:网站运营
Nginx虚拟主机流量状态模块(nginx-module-vts)使用说明文档(一):前面的博文Nginx安装,开箱即用?讲了NG的安装。装完NG,为了拿到各种状态指标,就要对NG做监控。 Github 2.3k的开源项目nginx-module-vts没准真是你需求的。 链接数,qps,1xx、2xx,、3xx、4xx、5xx的响应数,响应耗时,响应时间分布,访问用户国家分布;甚至是基于各种状态的流量控制统统能满足你的需求。 nginx-module-vts具体怎么用?我们还是从官方文档开始撸吧,还是英文的,那就翻译一下吧。 内容有点长,你看到的文档会四篇文档的方式分别出现。这里是第一篇,余下的三篇会在后面分别发出。
shell> git clone git://github.com/vozlt/nginx-module-vts.git
--add-module=/path/to/nginx-module-vts
将该模块添加到构建配置中http { vhost_traffic_status_zone; ... server { ... location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } }}
vhost_traffic_status_zone
是必需的,如果指令vhost_traffic_status_display
被设置,可以通过下方式访问:/status/format/json
将用一个包含当前活动数据的json文档进行响应,以便在实时仪表板和三方监视工具中使用。/status/format/html
将会用一个内置的内置的html仪表板网页进行响应,该仪表盘的内部请求走/status/format/json
。/status/format/jsonp
将用一个jsonp回调函数进行响应,该函数包含用于实时仪表板和三方监视工具的当前活动数据。/status/format/prometheus
将用包含当前活动数据的prometheus文档来响应。/status/control
将返回基于查询语句字符串重置或删除区域后的JSON文档。更多可以参考Control.{ "hostName": ..., "nginxVersion": ..., "loadMsec": ..., "nowMsec": ..., "connections": { "active":..., "reading":..., "writing":..., "waiting":..., "accepted":..., "handled":..., "requests":... }, "sharedZones": { "name":..., "maxSize":..., "usedSize":..., "usedNode":... }, "serverZones": { "...":{ "requestCounter":..., "inBytes":..., "outBytes":..., "responses":{ "1xx":..., "2xx":..., "3xx":..., "4xx":..., "5xx":..., "miss":..., "bypass":..., "expired":..., "stale":..., "updating":..., "revalidated":..., "hit":..., "scarce":... }, "requestMsecCounter":..., "requestMsec":..., "requestMsecs":{ "times":[...], "msecs":[...] }, "requestBuckets":{ "msecs":[...], "counters":[...] }, } ... }, "filterZones": { "...":{ "...":{ "requestCounter":..., "inBytes":..., "outBytes":..., "responses":{ "1xx":..., "2xx":..., "3xx":..., "4xx":..., "5xx":..., "miss":..., "bypass":..., "expired":..., "stale":..., "updating":..., "revalidated":..., "hit":..., "scarce":... }, "requestMsecCounter":..., "requestMsec":..., "requestMsecs":{ "times":[...], "msecs":[...] }, "requestBuckets":{ "msecs":[...], "counters":[...] }, }, ... }, ... }, "upstreamZones": { "...":[ { "server":..., "requestCounter":..., "inBytes":..., "outBytes":..., "responses":{ "1xx":..., "2xx":..., "3xx":..., "4xx":..., "5xx":... }, "requestMsecCounter":..., "requestMsec":..., "requestMsecs":{ "times":[...], "msecs":[...] }, "requestBuckets":{ "msecs":[...], "counters":[...] }, "responseMsecCounter":..., "responseMsec":..., "responseMsecs":{ "times":[...], "msecs":[...] }, "responseBuckets":{ "msecs":[...], "counters":[...] }, "weight":..., "maxFails":..., "failTimeout":..., "backup":..., "down":... } ... ], ... } "cacheZones": { "...":{ "maxSize":..., "usedSize":..., "inBytes":..., "outBytes":..., "responses":{ "miss":..., "bypass":..., "expired":..., "stale":..., "updating":..., "revalidated":..., "hit":..., "scarce":... } }, ... }}
vhost_traffic_status_filter_by_set_key
指令过滤统计的server的流量(输入/输出),请求和响应计数以及缓存命中率。vhost_traffic_status_filter_by_set_key
指令过滤。overCounts
对象主要用于32位系统,如果其值溢出,则将递增1。使用指令vhost_traffic_status_display_format
设置默认的输出格式,即json、jsonp、html、prometheus之一。(默认值为json)注意:
此模块依赖于nginx日志记录系统(NGX_HTTP_LOG_PHASE:nginx http的最后阶段),因此流量可能在某些情况下和实际带宽流量会有所不同。 Websocket以及取消的下载可能是造成差异的原因。 无论access_log指令是on
还是off
,模块的工作都没有关系。 同样,此模块在access_log off
时也可以正常工作。 当使用多个域时,它将设置为server_name指令的第一个域(左侧)。 如果不需要,请参见vhost_traffic_status_filter_by_host, vhost_traffic_status_filter_by_set_key指令。stream
流量统计信息请参见以下模块: nginx-module-sts nginx-module-stream-sts关键词:使用,虚拟,主机,流量,状态