前面的博文Nginx安装,开箱即用?讲了NG的安装。装完NG,为了拿到各种状态指标,就要对NG做监控。 Github 2.3k的开源项目nginx-module-vts没准真是你需求的。 链接数应用说明,qps,1xx、2xx,、3xx、4xx、5xx的响应数,响应耗时,响应时间分布,访问用户国家分布;甚至是基于各种状态的流量控制统统能满足你的需求。 nginx-module-vts具体怎么用?我们还是从官方文档开始撸吧,还是英文的,那就翻译一下吧。 内容有点长,你看到的文档会四篇文档的方式分别出现。这里是第一篇,余下的三篇会在后面分别发出。
Nginx虚拟主机流量状态模块
目录1、版本
本文件描述了2018年6月22日发布的nginx-module-vtsv0.1.18。
2、依赖3、兼容性
早期版本不进行测试。
4、状态截图


5、安装克隆git存储库。
shell> git clone git://github.com/vozlt/nginx-module-vts.git
通过--add-module=/path/to/nginx-module-vts将该模块添加到构建配置中
构建nginx二进制文件。
安装nginx二进制文件。
6、概要
http {
vhost_traffic_status_zone;
...
server {
...
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
7、描述
这是一个Nginx模块,提供对虚拟主机状态信息的访问。 它包含当前状态,例如servers, upstreams, caches。 这类似于nginx plus的实时活动监视。 内置的html和旧版本的演示页面也保持一致。
首先,指令vhost_traffic_status_zone是必需的,如果指令vhost_traffic_status_display被设置,可以通过下方式访问:
JSON文档包含以下内容:
{
"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":...
}
},
...
}
}
JSON文档中的overCounts对象主要用于32位系统,如果其值溢出,则将递增1。使用指令vhost_traffic_status_display_format设置默认的输出格式,即json、jsonp、html、prometheus之一。(默认值为json)
流量的计算规则如下:
所有计算都在Nginx的日志处理阶段中进行。 内部重定向(X-Accel-Redirect或error_page)不在UpstreamZones中计算。
注意:此模块依赖于nginx日志记录系统(NGX_HTTP_LOG_PHASE:nginx http的最后阶段),因此流量可能在某些情况下和实际带宽流量会有所不同。 Websocket以及取消的下载可能是造成差异的原因。 无论access_log指令是on还是off,模块的工作都没有关系。 同样,此模块在access_log off时也可以正常工作。 当使用多个域时,它将设置为server_name指令的第一个域(左侧)。 如果不需要,请参见, 指令。
有关stream流量统计信息请参见以下模块: nginx-module-sts nginx-module-stream-sts
8、计算和间隔平均值
所有的平均值目前都是用算术平均值AMM(Arithmetic Mean)基于最新的64 个值来计算的。
凋谢的不是花,萎蔫的是时间;星辰大海,点滴为途。
(编辑:海南站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|