Nginx 虚拟主机流量状态模块
Nginx virtual host traffic status module
See the GitHub Releases for the latest tagged release.
Run sudo prove -r t after you have installed this module. The sudo is required because
the test requires Nginx to listen on port 80.
Earlier versions is not tested.
shell> git clone git://github.com/vozlt/nginx-module-vts.git
Add the module to the build configuration by adding
--add-module=/path/to/nginx-module-vts
Build the nginx binary.
Install the nginx binary.
It can be built with Profile-Guided Optimization (PGO) using gcc fprofile options. The detail of the PGO mechanisms has refer to the section 7.4 of this paper.
Here is an example of the process to make a PGO supported binary. Please use at your own risk.
shell> pwd
/somewhere/nginx
shell> CC=gcc ./auto/configure --with-cc-opt='-fprofile-generate -fprofile-dir=./objs' --with-ld-opt='-lgcov' --add-module=/somewhere/nginx-module-vts
shell> make
shell> pwd
/somewhere/nginx-module-vts
shell> sudo PATH=/somewhere/nginx/objs:$PATH prove -r t/000.display_html.t
...(during runtime it records coverage data into .gcda files)
shell> pwd
/somewhere/nginx
shell> CC=gcc ./auto/configure --with-cc-opt='-fprofile-use -fprofile-dir=/somewhere/nginx-module-vts/objs' --with-ld-opt='-lgcov' --add-module=/somewhere/nginx-module-vts
shell> make
http {
vhost_traffic_status_zone;
...
server {
...
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
This is an Nginx module that provides access to virtual host status information. It contains the current status such as servers, upstreams, caches. This is similar to the live activity monitoring of nginx plus. The built-in html is also taken from the demo page of old version.
First of all, the directive vhost_traffic_status_zone is required,
and then if the directive vhost_traffic_status_display is set, can be access to as follows:
/status/format/json, will respond with a JSON document containing the current activity data for using in live dashboards and third-party monitoring tools./status/format/html, will respond with the built-in live dashboard in HTML that requests internally to /status/format/json./status/format/jsonp, will respond with a JSONP callback function containing the current activity data for using in live dashboards and third-party monitoring tools./status/format/prometheus, will respond with a prometheus document containing the current activity data./status/control, will respond with a JSON document after it reset or delete zones through a query string. See the Control.JSON document contains as follows:
…
*) and hit ratiovhost_traffic_status_filter_by_set_key directive*) and hit ratio filtered through the vhost_traffic_status_filter_by_set_key directiveThe overCounts objects in JSON document are mostly for 32bit system and will be increment by 1 if its value is overflowed.
The directive vhost_traffic_status_display_format sets the default ouput format that is one of json, jsonp, html, prometheus. (Default: json)
Traffic calculation as follows:
proxy_next_upstream passed on adds neither, having served no client request. It is still counted in requestCounter and in responses, and its own time in responseMsecCounter.All calculations are working in log processing phase of Nginx. Internal redirects(X-Accel-Redirect or error_page) does not calculate in the UpstreamZones.
Caveats: this module relies on nginx logging system(NGX_HTTP_LOG_PHASE:last phase of the nginx http), so the traffic may be
in certain cirumstances different that real bandwidth traffic.
Websocket, canceled downloads may be cause of inaccuracies.
The working of the module doesn't matter at all whether the access_log directive "on" or "off".
Again, this module works well on "access_log off".
When using several domains it sets to be first domain(left) of server_name directive.
If you don't want it, see the vhost_traffic_status_filter_by_host, vhost_traffic_status_filter_by_set_key directive.
See the following modules for the stream traffic statistics:
All averages are currently calculated as AMM(Arithmetic Mean) over the last 64 values.
It is able to reset or delete traffic zones through a query string. The request responds with a JSON document.
{status_uri}/control?cmd={command}&group={group}&zone={name}[&expire={seconds}]http {
geoip_country /usr/share/GeoIP/GeoIP.dat;
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_set_key $geoip_country_code country::*;
...
server {
se
Should the statistics count a subrequest, and on whose say-so
The dump has no format version, so a changed node layout is either dropped in silence or read as wrong numbers
Support for lua balanced upstreams
Need a way to query domain within a filter group
[Feature Request]: API for filterGroup
ENH: Add filter option to exclude SSE request response time
Feature request: hit_in_bytes hit_out_bytes miss_in_bytes miss_out_bytes
Summary type support