Is it possible to monitor Varnish running inside a Docker container?

  • Which version of Windows or which distribution of Linux are you using?
    Ubuntu 16.04
  • What version of the Infrastructure agent are you using?
    1.7.6
  • What is your Infrastructure Subscription level? Essentials or PRO?
    Pro

I have the infrastructure agent running on a host VM which is also running Docker. Varnish is running inside a container. It seems like the varnish integration added to the host can’t monitor varnish running inside the container. Is there a way to make this work?

I thought about installing the infrastructure agent inside the varnish container but I don’t want the container to show up as another host. Plus the container doesn’t use a varnish.params file because the options are passed directly to the container via environment variables.

Are there any other options for sending varnish data to New Relic in this setup?

Thanks!

Hello!

You should be able to monitor varnish from outside the docker environment on a host running infra and the integration. As long as the integration is able to access varnish, it should be able to pull data.

Thanks for your help.

I guess that’s where I’m stuck. I have varnish running inside the container so I’m not sure how to get the integration on the host to use it. Here is what I’m getting from the service logs.

newrelic-infra-service[13444]: time=“2019-12-04T17:48:57Z” level=error msg=“Integration command failed” error=“exit status 1” instance=varnish_all integration=com.newrelic.varnish prefix=config/varnish stderr="[ERR] Error parsing params file : varnish.params file could not be found\n[ERR] Error collecting metrics: exec: “varnishstat”: executable file not found in $PATH\n" working-dir=/var/db/newrelic-infra/newrelic-integrations

So it seems like I need to overcome two problems.

  1. It can’t find varnish.params. I’m not using this in the container because I’m configuring varnish using environment variables that get interpreted into the container entrypoint. So the configuration is defined as command parameters. instead of in a varnish.params file.
  2. It can’t use varnishstat, which is inside the container. Do I need to volume mount this to the host?

Hello @dbarbarisi,

The integration will definitely need to locate the varnish params file here. If the file location can be mounted so that the integration has access to it, then that should help.

We are a bit limited in our support here as this isn’t a supported implementation.

Hi, I get it working on my server. You just need a wrapper for varnishstat on the host :
vim /usr/bin/varnishstat

#!/bin/bash
docker exec `docker ps --filter name=varnish -q` varnishstat ${*}

chmod +x /usr/bin/varnishstat

Just customize the docker ps filter to match your varnish container name.

I also have an error for the varnish.params not found but it doesn’t seems mandatory as I receive datas on New Relic dashboard.

1 Like

Great to hear! Thank you for sharing this

Thank you! I’ll give that a try.

@cyril, @dbarbarisi,

varnish.params file is only used to populate Inventory information. It does not affect metrics collection.

There are 2 ways to get rid of that error:

  1. Create a shared volume between the container and the host to allow access to the varnish.params file from the host. Add to your container deployment command something like -v /varnish_data:/etc/default/varnish.
    Then change the params_config_file setting on your integration config file (varnish-config.yml) to params_config_file: /varnish_data/varnish.params.
    The integration will capture the information from your params file and report it under the Inventory tab as config/varnish
    Note the /etc/default/varnish is one of the default locations Varnish uses but your setup may be different and you will need to adjust it to the location where your params file really is. Also do not forget to create the varnish_data folder on the host and make sure the docker user has access to the folder.

  2. If you don’t need/want to collect Inventory information from Varnish you can disable it on the config file (varnish-config.yml) by adding a metrics and inventory boolean arguments. Your config file should look like:

integration_name: com.newrelic.varnish

instances:
  - name: varnish_all
    command: all_data
    arguments:
      params_config_file: 
      instance_name: <your_instance_name>
      metrics: true
      inventory: false
    labels:
      env: production
      role: varnish

This will disable inventory collection and avoid polluting your log file with all those error messages when trying to parse the params file.

Hope this helps

1 Like