Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List contents of varnish cache?

Tags:

varnish

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

like image 521
Martin Taleski Avatar asked Jan 08 '13 11:01

Martin Taleski


People also ask

What does Varnish cache do?

Varnish Cache is a powerful, open source HTTP engine/reverse HTTP proxy that can speed up a website by up to 1000 percent by doing exactly what its name implies: caching (or storing) a copy of a webpage the first time a user visits.

Where does Varnish store cache?

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

Does Varnish cache files?

Varnish Cache is a popular tool due to how quickly it delivers content from the cache and how flexible it can be. Using Varnish Cache's domain-specific language, Varnish Cache Configuration Language (VCL), users can cache both static and so-called “dynamic” content, also known as the HTML document.


2 Answers

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

like image 111
mrege Avatar answered Oct 07 '22 10:10

mrege


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..

like image 3
Doomsday Avatar answered Oct 07 '22 11:10

Doomsday