varnishlog
Analyze and monitor Varnish Cache traffic
TLDR
Display logs in real time
Only display requests to a specific domain
Only display POST requests
Only display requests to a specific path
Only display requests to paths matching a regular expression
SYNOPSIS
varnishlog [options]
PARAMETERS
-a
Display all Varnish instance names in shared memory.
-b
Follow only backend transactions. Reduces output clutter by only following backend-related activity.
-c
Follow only client transactions.
-d
Daemon mode. Runs in the background.
-D
Stay in foreground (Don't daemonize).
-i
Include only transactions that match the specified fields. Use with -I for exact matches, otherwise substrings are allowed.
-I
Include only transactions that match the specified fields. Use with -i for substring matches, otherwise exact matches are required.
-N
Specify the VCL name file. (See varnishd(1)).
-n
Varnish instance name. If omitted, the hostname is used.
-q
Query the log based on the provided query string. VSL query language (VSLQ) is used.
-t
Sets the maximum runtime in seconds. Defaults to unlimited.
-V
Display the varnishlog version and exit.
-x
Display raw VSL records instead of the standard format.
DESCRIPTION
varnishlog is a powerful command-line tool used to inspect and analyze the logs generated by Varnish Cache. It allows you to monitor requests flowing through Varnish, examine header information, track caching behavior (hits, misses, pass), and debug issues related to caching and request handling.
Essentially, varnishlog captures the real-time flow of transactions within Varnish. You can filter the output based on various criteria like client IP, request method, or specific header values, making it invaluable for troubleshooting and performance tuning. The output streams varnish's shared memory log to standard output. The log contains everything from the client request to varnish's backend decisions. This can be invaluable information when debugging cache configurations and other performance related issues. Because the log is in shared memory, this command is efficient to use and has minimal impact to varnish operations.
CAVEATS
varnishlog requires appropriate permissions to access the shared memory segments used by Varnish. Typically, it should be run as the same user as the Varnish process, or as root. Using `-q` with complex regular expressions can impact performance.
VSLQ (VARNISH SHARED LOG QUERY LANGUAGE)
The `-q` option uses VSLQ. This language provides a flexible way to filter and query Varnish logs. You can use logical operators, regular expressions, and field comparisons to pinpoint specific events and transactions.
Example:
`varnishlog -q 'ReqMethod eq "GET" and RespStatus >= 500'`
This query shows only GET requests that resulted in a 500 or greater HTTP status code.
UNDERSTANDING LOG FIELDS
Varnish logs contain various fields that provide detailed information about each request and transaction. Key fields include `ReqMethod`, `ReqURL`, `RespStatus`, `Hit`, `Miss`, `Pass`, `Backend`, `ClientIP`, and custom header values. Understanding these fields is crucial for effective analysis and troubleshooting.
HISTORY
varnishlog was developed alongside Varnish Cache as a crucial component for monitoring and debugging its behavior. Its evolution has closely tracked Varnish's development, adding features and capabilities to effectively analyze the increasing complexity of modern web caching scenarios.
Early versions provided basic logging functionality, but as Varnish matured, varnishlog gained advanced filtering, query capabilities, and improved output formats.
SEE ALSO
varnishd(1), varnishadm(1), varnishstat(1), varnishtop(1)