Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Varnish logging?

I want to get Varnish to log requests. I found the command varnishlog -a -w /var/log/varnish.log, but it does not log anything.

Then I found that Varnish does not write to log by default. However I am unable to find configuration options for logging.

like image 961
Muneeb Nasir Avatar asked Oct 03 '12 09:10

Muneeb Nasir


People also ask

How do you check Varnish logs?

This option is required when running in daemon mode. For reading the log file, we could run sudo varnishlog -r <filename> . Read log in binary file format from this file. The file can be created with varnishlog -w filename .

Where is Varnish cache stored?

Varnish Cache stores content in pluggable modules called storage backends. It does this via its internal stevedore interface.


2 Answers

If you want to log HTTP requests in NCSA Common Log Format you need to use varnishncsa. On CentOS/RedHat, the Varnish RPM package includes a varnishncsa init script that you can use to start logging. By default it logs to logfile="/var/log/varnish/varnishncsa.log".

Additionally if you wish to serve several different hosts through a single Varnish install, you'll want to include the host name in the log as well. This can be accomplished with the following setting in /etc/sysconfig/varnishncsa

DAEMON_OPTS="$DAEMON_OPTS -F '%{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"'"

Please note that the method described in the link by Anshu only logs the requests that are passed through by Varnish to the backend servers. Cache hit requests will never be recorded (before Varnish 5.0 - see below). Therefore the HTTPD logs gathered this way cannot be used for statistical analysis.

Update: As @VikrantPogula mentioned, as of Varnish 5.0 all client requests are logged - including cache hits. This is the default behavior, and can be switched on explicitly using the -c switch.

like image 78
Ketola Avatar answered Sep 28 '22 00:09

Ketola


Metrics in Varnish are a common area that people struggle with.

It's relatively easy to get some one off request metrics but overall tracking over time generally involves using varnishncsa. Here is a guide on Varnish installation that includes metric setup

like image 23
mattnthat Avatar answered Sep 28 '22 00:09

mattnthat