首先,我们在nginx.conf中简单配置下vts有关的指令。
http {
vhost_traffic_status_zone;
...
server {
...
location /status {
vhost_traffic_status_display;
}
}
}
其中指令vhost_traffic_status_zone是必需的,如果指令vhost_traffic_status_display被设置,访问/status将会返回当前server的活动数据,默认以JSON格式返回。当然,你也可以设置vhost_traffic_status_display_format html,此时访问/status/format/html,将会用一个内置的html仪表板网页进行响应,其余的格式有jsonp和prometheus。
返回的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":...
}
},
...
}
}
其中
- main
- nginx版本,nginx运行时间((nowMsec - loadMsec)/1000)
- nowMsec,loadMsec是毫秒数.
- connections
- 统计总连接数和总请求数(和nginx的stub_status_module相同)
- sharedZones
- 统计nginx-module-vts中使用的共享内存信息
- serverZones
- 统计每个server的流量(in/out)以及请求和响应计数和缓存命中率
- 统计总流量(in/out)以及总请求和总响应计数(区域名称为*)和总缓存命中率
- filterZones
- 通过vhost_traffic_status_filter_by_set_key指令过滤统计的server的流量(输入/输出),请求和响应计数以及缓存命中率。
- 总流量(in/out)以及总请求和总响应计数(区域名称为*)和命中率通过vhost_traffic_status_filter_by_set_key指令过滤。
- upstreamZones
- 统计每个upstream组中每个server的流量(in/out)以及请求和响应计数
- nginx.conf中的当前设置(权重,maxfails,failtimeout …)
- cacheZones
- 使用proxy_cache指令时,每个缓存区域的流量(in/out)和大小(capacity/used)以及命中率。