Skip to content

Instantly share code, notes, and snippets.

@ogrrd
Last active October 20, 2022 07:12
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ogrrd/5907585 to your computer and use it in GitHub Desktop.
Save ogrrd/5907585 to your computer and use it in GitHub Desktop.
Handy Varnish commands

Handy Varnish commands

See what Varnish is currently processing

$ varnishlog

Show the referer (sic) header for requests

$ varnishtop -i RxHeader -I \^Referer

Show requests made to the backend (-b) where the line matches (-i) the transmit URL (TxURL)

$ varnishtop -b -i TxURL

Basically, shows you what is being passed to the backend and isn’t being cached. It will list all requests going to a backend, grouped by URL and sorted by a decaying average of frequency. Basically the number on the left should be single-digit and preferably all 1s or less (a higher number means the backend request is taking place frequently). [Technically, you don't even need the "-b" as the TxURL is only set when making requests to the backend anyway]

Show a histogram chart of the last 1,000 requests

$ varnishhist

Shows a histogram chart of the last 1,000 requests (by default) to the Varnish proxy showing “|” as a “hit” on the cache and “#” as a miss. The more “|” to the left of the chart, the better. The scale on the bottom is in seconds with 1e0 being “1″ second and 1e-6 being 0.000001seconds (1e-1 being 0.1seconds). The vertical scale is shown in the top left hand corner.

Show various information about varnish

$ varnishstat

Use varnishreload

If you have Ubuntu, issue sudo service varnish reload instead.

From http://kristian.blog.linpro.no/2009/02/18/easy-reloading-of-varnish-vcl/, this is a very handy script you can use to reload varnish’s configuration without having to restart the proxy server:

#!/bin/bash
# Reload a varnish config
# Author: Kristian Lyngstol
FILE="/etc/varnish/default.vcl"
# Hostname and management port
# (defined in /etc/default/varnish or on startup)
HOSTPORT="localhost:6082"
NOW=`date +%s`
error()
{
echo 1>&2 "Failed to reload $FILE."
exit 1
}
varnishadm -T $HOSTPORT vcl.load reload$NOW $FILE || error
varnishadm -T $HOSTPORT vcl.use reload$NOW || error
echo Current configs:
varnishadm -T $HOSTPORT vcl.list

Show what caused recent 503 errors

$ varnishlog -d -c -o TxStatus 503

Clear stale cache by host name

$ purge req.http.host ~ example.com

See what status codes are being commonly hit by your users (ideally lots of 200 and few 5xxx)

$ varnishtop -i TxStatus

See also: http://www.slideshare.net/schoefmax/caching-with-varnish-1642989, http://blogs.osuosl.org/gchaix/2009/10/12/pressflow-varnish-and-caching/ and http://letsgetdugg.com/2009/12/04/random-varnish-tips-n-tricks/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment