Search
Varnish Controller

Varnish Statistics

Varnish Controller has support for reporting Varnish statistics. The statistics gathered are the same as the varnishstat tool produces. The parts that should be gathered can be configured per agent.

The vmod-accounting will be used for gathering VCLGroup specific statistics if the Varnish server supports vmod-accounting (>=6.0.8r2). It will be automatically activated if an applicable version is in use. It can be turned off by a flag (-accounting=false) to the agent.

Persisted Statistics

Varnish Controller supports persisted aggregated statistics. These are reported as an average over the given aggregation period. The following exists:

  • 1m (1 minute)
  • 10m (10 minutes)
  • 1h (1 hour)
  • 1d (1 day)
  • 1mo (1 month)

There are current reported statistics available which is a snapshot of current values from varnishstat. The current values are updated as often as configured for each agent (-stats-interval).

The statistics are stored in the database as long as configured in brainz. Brainz will perform removal of old statistics based on the following configuration:

  • -keep-stats-1m (default 1 hour)
  • -keep-stats-10m (default 1 day)
  • -keep-stats-1h (default 1 week)
  • -keep-stats-1d (default 1 year)
  • -keep-stats-1mo (default 10 years)

The amount of statistics gathered highly depends on number of agents, VCLGroups and configured counters. The database usage is depending on the amount of statistics gathered and also how long statistics is kept in the database, configured by the flags described above.

There are three counter types that are supported for persistent statistics, they are boolean(q), counter(c) and gauge(g).

Counters are stored in differential way in the persistent database, meaning that each time frame (e.g. 1m slot) will store the number of incoming client requests during that time period (as an example).

For boolean values, the average of the values for a certain time period is calculated. A value of 0.5 for a 10min time period means that half the period 0 (false) was reported and half the period 1 (true) was reported. It will not state which time in this period it was reporting which value.

For gauge values, an average is reported for the given time period.

Counter Configuration

Counters are defined per agent and has a default set configured. It’s possible to change which counters to report per VCLGroup/Accouting/Agent using the following flags to the agent (using a comma separated list of counter names):

  • -agent-stats-filter (Counters such as MAIN.client_req)
  • -vclgroup-stats-filter (Backend counters for VCLGroups)
  • -accouting-stats-filter (VMOD Accounting specific counters)

Examples

Historical statistics can be configured in the UI dashboard or retrieved via API/CLI.

Some CLI examples:

# Fetch last reported values for all agents 
vcli agent stats

# Fetch statistics for agent with id 1 and show aggregated statistics of 1 minute intervals.
vcli agent stats -fagent_id=1 -a 1m 

# Fetch statistics for agent with id 1 and show aggregated statistics of 1 hour intervals.
# Sort by counter name descending order.
vcli agent stats -fagent_id=1 -a 1h -fsort=name:desc 

# Fetch statistics for a VCLGroup for 1 minute intervals.
vcli vg stats -fvcl_group_id=1 -a 1m

Prometheus Output

This is in preview and may be changed in the future!

The statistics endpoints (using API) have support for outputting the statistics in Prometheus format.

API Example:

$ curl -H "Authorization: bearer <access_token>" http://localhost:8002/api/v1/vclgroups/varnishstats?format=prom
# HELP varnish_controller_bereq_bodybytes Request body bytes
# TYPE varnish_controller_bereq_bodybytes untyped
varnish_controller_bereq_bodybytes{agent_id="1",agent_name="server2", vcl_group_id="2", vcl_group_name="test2"} 10
varnish_controller_bereq_bodybytes{agent_id="1",agent_name="server2", vcl_group_id="1", vcl_group_name="test1"} 20
...

Unsupported Counters

  • Counters of the type bitmap is not supported in the persistent statistics.
  • vmod-goto counters are currently not supported.

See agent configuration how to configure statistics gathering per agent.