varnish container images.
Supported telemetry types
The Varnish integration supports these telemetry types:Known limitations
The Varnish integration collects the statistics counters thatvarnishstat lists. It
doesn’t collect the following:
- Backend health and other state that only
varnishadmreports, such as a backend set sick or healthy by hand. The integration doesn’t connect to the Varnish administration port. - The Varnish version, which no counter carries.
- Logs, including the request records in the shared memory log.
- Counters that Varnish modules and Varnish Enterprise add. Each module defines the names of its counters when it loads.
- Counters for backends that a Varnish module implements by itself, because Varnish
keeps none for them. The default configuration of the
varnishcontainer image uses such backends from version 9.0.
Prerequisites
The Varnish integration has the following prerequisites:-
Run the CXDOT Collector on Linux, on the same machine as Varnish: the same host, or
the same Kubernetes node as the Varnish pod. The Collector reads the counters from
the shared memory files in the working directory of each Varnish server. It doesn’t
run
varnishstator connect to Varnish over the network. - On Kubernetes, the node Collector must run as root, with access to every pod volume on its node. The Collector reads the counters of each Varnish pod from the pod’s volume, through the kubelet pod directory on the node, which only root can read. The Configure on Kubernetes section describes the access that the Helm chart grants.
-
Find the working directory of each Varnish server, the directory that the
-noption ofvarnishdnames. Without-n, Varnish 7.0 or later uses/var/lib/varnish/varnishd, and earlier versions use a directory under/var/lib/varnishnamed after the machine’s host name. The officialvarnish:6.0container image sets-n /var/lib/varnish. To list the working directories under/var/lib/varnish, run the following command where Varnish runs. Each result is inside a working directory:
Configure
The Varnish integration is disabled by default, because in Kubernetes it requires a node Collector that runs as root. Follow the steps for where the CXDOT Collector runs: on Kubernetes with the CXDOT Collector Helm chart, or directly on each Varnish host.Configure on Kubernetes
To configure the Varnish integration on Kubernetes, follow these steps:-
Enable the integration. For example, add the following to the
values.yamlfor your CXDOT Collector Helm chart:The node Collector on each node collects from the annotated Varnish pods on that node. Leaveinstancesout of the Helm values. Theinstanceslist is for a Collector running on a host, and the Helm chart refuses to render a configuration that sets it. For more information about Collector tiers, see architecture. -
Allow the node Collector to run as root. For example, add the following to the
values.yamlfor your CXDOT Collector Helm chart:The Collector reads the counters of a Varnish pod from the pod’s volume, through the kubelet pod directory on the node, which only root can read. While the Varnish integration is enabled, the Helm chart mounts that directory into the node Collector. The mount gives the Collector read access to every pod volume on the node. The mount also gives the Collector write access to the pod volumes that the kubelet keeps in memory, such as memory-backedemptyDirvolumes, Secrets, and service account tokens. The chart sets the mount read-only, but Kubernetes applies that setting only to the top of the mount and not to the volumes that pods mount beneath it. The Helm chart refuses to render the Varnish integration withoutrunAsRoot. -
Optional: If the kubelet on your nodes uses a root directory other than
/var/lib/kubelet, setnodeCollector.kubeletRootDirto the value of the kubelet--root-dirflag. For example, add the following to thevalues.yamlfor your CXDOT Collector Helm chart:One value applies to every node. While the Varnish integration is enabled, a value that doesn’t match a node keeps the node Collector pod on that node from starting, and the pod’s events name the missing directory. -
To collect from Varnish pods, add a CXDOT integration annotation to the pod template,
and keep the working directory on an
emptyDirvolume. The annotation key must end with the container name. For example, add the following annotation and volume to your Varnish workload:Theendpointis the path of the working directory inside thevarnishcontainer. The Collector finds the working directory in the pod’semptyDirvolume that’s mounted at that path or at its parent directory, such as/var/lib/varnishin the example. The Collector can’t read a working directory in the container’s own file system. A memory-backed volume keeps the shared memory files in memory, where they count toward the pod’s memory usage. For the officialvarnish:6.0image, mount the volume at/var/lib/varnishand setendpointto/var/lib/varnish. For other Varnish versions earlier than 7.0, startvarnishdwith-n, such as-n /var/lib/varnish/varnishd. Without-n, the working directory is named after the pod’s host name, which changes with each pod. Metrics from each annotated pod include that pod’s Kubernetes metadata. For more information, see autodiscovery.
Configure on a host
To configure the Varnish integration on a host, such as a virtual machine, follow these steps:-
Enable the integration and list the working directory of each Varnish server. Run
the Collector in host mode on each Varnish host and add the following to the
Collector configuration file:
On a host, the integration collects only from the instances in
instances. The second entry in the example is a Varnish server started with-n edge. Give each Varnish server on a host its owninstance_name. For more information about running the Collector on a host, see install the CXDOT Collector on Linux. -
Give the Collector read access to each working directory. The
varnishgroup owns the counter files in the packages from Varnish Software, so add the account that runs the Collector to that group. For example:ReplaceCOLLECTOR_USERwith the name of that account, then restart the Collector. The Collector needs no write access to the working directory and doesn’t need to run as root. An account other than root also needscxdot.debug.socket_pathset to a path in a directory that account can write to. The default debug socket directory is under/var/run, and a Collector that can’t create it doesn’t start.
Validate
To validate the Varnish integration, follow these steps:-
In
Live Telemetry Analyzer,
filter for
__name__=cxdot.integration.target.healthandcxdot.integration.name=varnish. Confirm that the metric reports1for each Varnish server. A value of0means that the Collector couldn’t read the working directory, or that the uptime of the Varnish server stopped advancing, as it does when Varnish stops and leaves its files behind. Thecxdot.integration.targetattribute names the working directory. Thek8s.pod.nameattribute in Kubernetes and thehost.nameattribute on a host identify where Varnish runs. -
In
Metrics Explorer,
run the following query while Varnish serves requests:
Confirm that the query returns a time series for each Varnish server that serves requests.
Troubleshooting
cxdot.integration.target.healthreports0for a pod, and the Collector logs that noemptyDirvolume of the pod is mounted at the working directory or at its parent: The pod keeps its working directory outside anemptyDirvolume, or theendpointin the annotation doesn’t name the directory that Varnish uses. Mount anemptyDirvolume at the working directory or its parent, and setendpointto the path of the working directory inside the container.cxdot.integration.target.healthreports0for a pod, and the Collector logs that more than oneemptyDirvolume of the pod holds a working directory: TwoemptyDirvolumes of the pod hold a working directory that matches theendpoint, such as two Varnish containers that each mount their own volume at/var/lib/varnish. The Collector can’t tell which volume holds the working directory that theendpointnames, so it collects from neither. Keep the working directories of a pod on oneemptyDirvolume, and give each Varnish server in the pod its own working directory with-n.cxdot.integration.target.healthreports0on a host, and the Collector logspermission denied: The account that runs the Collector can’t read the working directory. Add the account to the group that owns the working directory, which isvarnishin the packages from Varnish Software, and restart the Collector.- No Varnish pods report metrics, and the Collector logs
CXDOT integration annotation target rejected by annotation restrictions: Thecollection.cxdot.integrations.discovery.kubernetes.annotation_restrictions.custom_pod_hostsetting in the Helm values for your CXDOT Collector isdeny. A Varnish target is a working directory, not the pod’s address, so this setting rejects every Varnish target. The Varnish integration collects from pods only while the setting isallow, its default. cxdot.integration.target.healthreports0, and the Collector logs that itfound the shared memory layout of Varnish before 6.0: The Varnish server runs a version earlier than 6.0, which keeps its counters in a layout that the Collector can’t read. The Varnish integration requires Varnish 6.0 or later, so upgrade the Varnish server.
Varnish counters
Each counter thatvarnishstat lists becomes a metric named after its section, and the
object that a section’s counters describe becomes an attribute. For example, the
VBE.boot.default.req counter is the varnish.backend.req metric with the
varnish.vcl.name attribute set to boot and the varnish.backend.name attribute set
to default. Every metric carries the varnish.instance.name attribute.
The following table lists the metrics and attributes for each counter section:
Counters that split one quantity by category become one metric with an attribute. For
example, the
MAIN.fetch_length and MAIN.fetch_chunked counters are the
varnish.main.fetch metric with the varnish.fetch.type attribute. Which counters
Varnish publishes depends on its version and configuration. For example, the SMF
section exists only with file storage.
The varnish.vcl.name attribute of a backend metric names the Varnish Configuration
Language (VCL) configuration that defines the backend. Each VCL load therefore adds a
time series for every counter of every backend in the new configuration. Varnish keeps
the backends of an old configuration published until the configuration goes cold, 600
seconds after another configuration becomes active by default. A Varnish server whose
configuration reloads often, such as one that an ingress controller reloads on every
change, can report several copies of the time series of each backend at once. To bound
them, lower the vcl_cooldown parameter or discard old configurations with
vcl.discard. To follow a backend across reloads, aggregate its metrics by
varnish.backend.name without varnish.vcl.name.
Configuration reference
Configure one Varnish integration instance with the following settings. In Helm values, place these settings undercollection.cxdot.integrations.varnish. In a Collector configuration file,
place them under cxdot.integrations.varnish.
Optional settings
-
enabledType:boolean. Optional. Default:true. Whether to run the Varnish integration. If true, the Collector collects Varnish metrics. If false, the Collector doesn’t run this integration. -
instancesType:array of object. Optional. Default:[]. Varnish instances to collect from when the Collector runs on a host, one for each working directory of a Varnish server on that host. When this list isn’t empty, the integration collects from exactly these instances and discovers no Varnish pods. In Kubernetes, the Collector discovers Varnish pods instead, and the CXDOT Collector Helm chart refuses to render a configuration that sets this list. The Collector reads each instance’s counters from the shared memory files in its working directory, so it needs read access to that directory. Membership of thevarnishgroup grants that access on most installations. -
instances[].endpointType:string. Required. The working directory of the Varnish server, as the absolute path that Varnish uses: the directory that the-noption ofvarnishdnames. A-nname that isn’t an absolute path is a directory under/var/lib/varnishin the packages and official container images. Without-n, Varnish 7.0 or later uses/var/lib/varnish/varnishd, and earlier versions use a directory under/var/lib/varnishnamed after the machine’s host name. The Collector reads the instance’s counters from this directory. -
instances[].instance_nameType:string. Optional. Default:default. Minimum length:1. The instance name reported asvarnish.instance.name: the value of the-noption ofvarnishd, ordefault. Give each instance on a host its own name. -
collection_intervalType:duration. Optional. Default:15s. Time between metric collections from each Varnish instance. -
timeoutType:duration. Optional. Default:15s. Maximum time to wait for each Varnish metric collection.