Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

nginx-module-vts

> DevOps
Open source

Nginx virtual host traffic status module

3.5K stars0 likes0 views
WebsiteGitHub

About

Nginx virtual host traffic status module

Nginx virtual host traffic status module

Nginx virtual host traffic status module

Table of Contents

  • Version
  • Test
  • Dependencies
  • Compatibility
  • Screenshots
  • Installation
  • Synopsis
  • Description
  • Calculations and Intervals
  • Control
    • To get status of traffic zones on the fly
      • To get fully zones
      • To get group zones
      • To get each zones
    • To reset traffic zones on the fly
      • To reset fully zones
      • To reset group zones
      • To reset each zones
    • To delete traffic zones on the fly
      • To delete fully zones
      • To delete group zones
      • To delete each zones
  • Set
  • JSON
    • Json used by status
    • Json used by control
  • Variables
  • Limit
    • To limit traffic for server
    • To limit traffic for filter
    • To limit traffic for upstream
  • Use cases
    • To calculate traffic for individual country using GeoIP
    • To calculate traffic for individual storage volume
    • To calculate traffic for individual user agent
    • To calculate traffic for detailed http status code
    • To calculate traffic for dynamic dns
    • To calculate traffic except for status page
    • To maintain statistics data permanently
  • Customizing
    • To customize after the module installed
    • To customize before the module installed
  • React Dashboard
  • Directives
    • vhost_traffic_status
    • vhost_traffic_status_zone
    • vhost_traffic_status_dump
    • vhost_traffic_status_display
    • vhost_traffic_status_display_format
    • vhost_traffic_status_display_jsonp
    • vhost_traffic_status_display_sum_key
    • vhost_traffic_status_filter
    • vhost_traffic_status_filter_by_host
    • vhost_traffic_status_filter_by_set_key
    • vhost_traffic_status_filter_check_duplicate
    • vhost_traffic_status_filter_max_node
    • vhost_traffic_status_limit
    • vhost_traffic_status_limit_traffic
    • vhost_traffic_status_limit_traffic_by_set_key
    • vhost_traffic_status_limit_check_duplicate
    • vhost_traffic_status_set_by_filter
    • vhost_traffic_status_average_method
    • vhost_traffic_status_histogram_buckets
    • vhost_traffic_status_bypass_limit
    • vhost_traffic_status_bypass_stats
    • vhost_traffic_status_stats_by_upstream
  • Releases
  • See Also
  • TODO
  • Author

Version

See the GitHub Releases for the latest tagged release.

Test

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.

Dependencies

  • nginx

Compatibility

  • Nginx
    • 1.30.x (last tested: 1.30.4)
    • 1.27.x (last tested: 1.27.3)
    • 1.22.x (last tested: 1.22.0)
    • 1.19.x (last tested: 1.19.6)
    • 1.18.x (last tested: 1.18.0)
    • 1.16.x (last tested: 1.15.1)
    • 1.15.x (last tested: 1.15.0)
    • 1.14.x (last tested: 1.14.0)
    • 1.13.x (last tested: 1.13.12)
    • 1.12.x (last tested: 1.12.2)
    • 1.11.x (last tested: 1.11.10)
    • 1.10.x (last tested: 1.10.3)
    • 1.8.x (last tested: 1.8.0)
    • 1.6.x (last tested: 1.6.3)
    • 1.4.x (last tested: 1.4.7)

Earlier versions is not tested.

Screenshots


Installation

  1. Clone the git repository.
shell> git clone git://github.com/vozlt/nginx-module-vts.git
  1. Add the module to the build configuration by adding --add-module=/path/to/nginx-module-vts

  2. Build the nginx binary.

  3. Install the nginx binary.

Installtion with Profile-Guided Optimization

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.

  1. Compile with fprofile-generate.
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
  1. Execute this module tests.
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)
  1. Recompile with fprofile-use
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

Synopsis

nginx
http {
    vhost_traffic_status_zone;

    ...

    server {

        ...

        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

Description

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
    • If you request /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
    • If you request /status/format/html, will respond with the built-in live dashboard in HTML that requests internally to /status/format/json.
  • /status/format/jsonp
    • If you request /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
    • If you request /status/format/prometheus, will respond with a prometheus document containing the current activity data.
  • /status/control
    • If you request /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:

…
  • main
    • Basic version, uptime((nowMsec - loadMsec)/1000)
    • nowMsec, loadMsec is a millisecond.
  • connections
    • Total connections and requests(same as stub_status_module in NGINX)
  • sharedZones
    • The shared memory information using in nginx-module-vts.
  • serverZones
    • Traffic(in/out) and request and response counts and cache hit ratio per each server zone
    • Total traffic(In/Out) and request and response counts(It zone name is *) and hit ratio
  • filterZones
    • Traffic(in/out) and request and response counts and cache hit ratio per each server zone filtered through the vhost_traffic_status_filter_by_set_key directive
    • Total traffic(In/Out) and request and response counts(It zone name is *) and hit ratio filtered through the vhost_traffic_status_filter_by_set_key directive
  • upstreamZones
    • Traffic(in/out) and request and response counts per server in each upstream group
    • Current settings(weight, maxfails, failtimeout...) in nginx.conf
  • cacheZones
    • Traffic(in/out) and size(capacity/used) and hit ratio per each cache zone when using the proxy_cache directive.

The 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:

  • 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
    • an attempt that 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.
  • cacheZones
    • in += requested_bytes via the ServerZones
    • out += sent_bytes via the ServerZones

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:

  • nginx-module-sts
  • nginx-module-stream-sts

Calculations and Intervals

Averages

All averages are currently calculated as AMM(Arithmetic Mean) over the last 64 values.

Control

It is able to reset or delete traffic zones through a query string. The request responds with a JSON document.

  • URI Syntax
    • /{status_uri}/control?cmd={command}&group={group}&zone={name}[&expire={seconds}]
nginx
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

Issues· 11 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ccmonitoringnginxnginx-module

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理