19
votes

Is there a way to list the contents of the varnish cache storage? Also, it would be nice to somehow list the most frequent cache hits.

I found a way to see the most frequent cache misses by listing what is being sent to the backend with:

varnishtop -b -i TxURL

It would be very useful to see what are my top cache hits URLs.

Edit: I am using version: varnish-3.0.3 revision 9e6a70f

2
What version of varnish do you have?mrege
varnishd (varnish-3.0.3 revision 9e6a70f)Martin Taleski

2 Answers

21
votes

I think this you can help:

You can use the parameter "Varnish:hitmiss" of varnishncsa.

First capture a sample of logs with:

varnishncsa -F '%U%q %{Varnish:hitmiss}x' -n NAME -w /path/requests.logs

and then:

sort -k 1 /path/requests.logs | uniq -c | sort -k 1 -n -r | head -25

3
votes

This feature is not included in Varnish, but you can easily add some scripting to do so.

  • First thing you need, is to launch varnishncsa as a service and write output in a daily file.
  • Then add to the default output format at least %{Varnish:hitmiss}x and %U (see varnishncsa doc)
  • Finally, write some scripts to compute your top URL for example something as below :
# we admit %{Varnish:hitmiss}x is the first column and %U the second
awk '$0 ~ / hit / { arr[$8]=arr[$8]+1 }END{ for(k in arr) { print arr[k]";"k } }' varnishncsa.log|sort -k 1 -nr |head

And feel free to update for your specific needs..