介绍:nginx-module-vts可实现对nginx 所有虚拟主机的并发量监测,发送接收数据监测,还提供json等格式数据用于第三方监测调用。
安装:
1,下载扩展:
git clone git://github.com/vozlt/nginx-module-vts.git没有安装git的需要先安装一下。
2,重新编译nginx 或openresty
./configure --user=nginx --group=nginx --prefix=/openresty --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module --with-luajit --with-http_sub_module --with-http_addition_module --with-http_auth_request_module --with-http_realip_module --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module --add-module=../nginx-module-vts/注意上面的模块路径要改成你自己的,然后模块根据自己需求去加。
3,编译:
gmake编译完成以后 先不要 gmake install
注意如果你是全新安装那么你可以直接 gmake install
如果你是原来已经编译好了现在只是需要添加这个模块 那么你就不能install 你需要进入build/nginx-1.13.6/objs/ 注意nginx版本是你自己的。
然后把里面的nginx文件copy到你自己的生产环境的nginx文件位置进行替换就OK了比如:
cp nginx /openresty/nginx/sbin/然后重启nginx
最后进行配置:
nginx.conf 文件 在 http{段内加入
vhost_traffic_status_zone;然后在任意一个server段中加入:
location /status { allow 127.0.0.1/24; deny all; vhost_traffic_status_display; vhost_traffic_status_display_format html; }
如果不进行限制可以只写下面两行
然后就可以进行访问了。
描述:
这是一个Nginx模块,提供对虚拟主机状态信息的访问。
它包含当前状态,例如servers, upstreams, caches。
这相似于nginx plus的实时活动监视。
内置的html和旧版本的演示页面也保持一致。json
首先,指令vhost_traffic_status_zone是必需的,若是指令vhost_traffic_status_display被设置,能够经过下方式访问:缓存
/status/format/json
请求/status/format/json将用一个包含当前活动数据的json文档进行响应,以便在实时仪表板和三方监视工具中使用。
/status/format/html
请求/status/format/html将会用一个内置的内置的html仪表板网页进行响应,该仪表盘的内部请求走/status/format/json。
/status/format/jsonp
请求/status/format/jsonp将用一个jsonp回调函数进行响应,该函数包含用于实时仪表板和三方监视工具的当前活动数据。
/status/format/prometheus
请求/status/format/prometheus将用包含当前活动数据的prometheus文档来响应。
/status/control
请求/status/control将返回基于查询语句字符串重置或删除区域后的JSON文档。更多能够参考Control.
JSON文档包含如下内容:socket
{ "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)以及命中率。
JSON文档中的overCounts对象主要用于32位系统,若是其值溢出,则将递增1。使用指令vhost_traffic_status_display_format设置默认的输出格式,即json、jsonp、html、prometheus之一。(默认值为json)函数
流量的计算规则以下:
ServerZones
in += requested_bytes
out += sent_bytes
FilterZones
in += requested_bytes via the filter
out += sent_bytes via the filter
UpstreamZones
in += requested_bytes via the ServerZones
out += sent_bytes via the ServerZones
cacheZones
in += requested_bytes via the ServerZones
out += sent_bytes via the ServerZones
全部计算都在Nginx的日志处理阶段中进行。
内部重定向(X-Accel-Redirect或error_page)不在UpstreamZones中计算。
注意:此模块依赖于nginx日志记录系统(NGX_HTTP_LOG_PHASE:nginx http的最后阶段),所以流量可能在某些状况下和实际带宽流量会有所不一样。
Websocket以及取消的下载多是形成差别的缘由。
不管access_log指令是on仍是off,模块的工做都没有关系。
一样,此模块在access_log off时也能够正常工做。
当使用多个域时,它将设置为server_name指令的第一个域(左侧)。
除特别注明外,本站所有文章均为博文家原创,转载请注明出处来自https://www.32e.top/services/linux/article-171.html
暂无评论