I'm in process of implementing Varnish as a reverse proxy for a Ruby on Rails app and I'm using Google Analytics (JS/client side script to record visitor data) but it's several hours delayed so its useless for knowing what's going on now. I need at a glance live data that includes referring traffic and what current req/sec is. Right now I am using a simple Rack middleware application to do the live stats (gist.github.com/235745) but if the majority of traffic hits Varnish, Rack will never be hit so this won't work.

The closest solution I've found so far is http://www.reinvigorate.net/ but it's in beta (there are also no implementation details on their front page).

Does Varnish have traffic logs that I can custom format to match my Apache logs so I can combine them, or will I have to roll my own JS implementation like GA that shows the data in real time?


Varnish doesn't log for performance reasons. They do allow you to access shm using varnishncsa, however, you do have a few options.

If most of your surfers support javascript (which is how Analytics is doing it's work), you could put a small webbug somewhere on your page that updated a process. Alternatively, you could define a particular image as pass, and then analyze your backend logs since every request would send that request to the backend.

 if (req.url == "^tracker.jpg$") {

tracker.jpg could easily be a script of some sort to insert data into a local log or you could run log analysis against the backend http webserver's weblogs. If you're using apache:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined
CustomLog /var/log/apache2/domain.com-access.log varnishcombined

Will use the X-Forwarded-For header in the column where most log analysis programs are expecting to see the client IP.


Have a look at varnishncsa, in particular the -c option. It's probably what you want.


If you want real time info, you should look at the varnishtop and varnishstat commands. Both of these update every second. If you can bear being a few minutes behind you could think about using a charting tool like Monit or Cacti.

See this blog post for an intro to using varnishstat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.