Server Setup

How to install vmod-xcounter for Varnish 6.0 LTS

by , , revisited on

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

About vmod-xcounter

Varnish 6.0.x branch is officially the LTS version. Many useful Varnish 6 modules (VMODs) are available for installation via our RPM repository.

vmod-xcounter is the new VMOD by Shohei Tanaka. It allows to create and use custom counters.

Install vmod-xcounter in CentOS/RHEL 7 for Varnish 6.0 LTS

The first step is enabling RPM repository with Varnish VMODs. This is a no-brainer with:

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install yum-utils
yum-config-manager --enable getpagespeed-extras-varnish60

If you have not installed Varnish already, do so now:

yum install varnish

And to get the vmod-xcounter installed, run:

yum install vmod-xcounter

Use vmod-xcounter

Load the VMOD by placing the following at the top of your main .vcl file:

import xcounter;

Now you can create counters with:

sub vcl_init {
  new example_com = xcounter.vsc();

You can increment / otherwise adjust and work with counters virtually anywhere in VCL, e.g. to count visits to domain:

sub vcl_recv {
  if(req.http.host == "example.com"){

You can then run varnishstat -f XCNT.* in order to view the counter. More documentation is available on the project’s homepage.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: