Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

By default, varnishncsa logs both hits and misses. As I'm already logging misses in my back-end server logs, I'm looking to only log hits in varnishncsa to remove duplication and keep logfile size down. Has anyone managed to do this?

I'm running Varnish 3.0.2 on Ubuntu 12.04 Server x64.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

On my varnish instances I include an 'X-Cache' header that says HIT or MISS as appropriate. With that you can just look for that in 'TxHeader':

varnishncsa -c -m "TxHeader:X-Cache: HIT"

To add this header you can add something like this in your .vcl file:

sub vcl_deliver {
      if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
      } else {
        set resp.http.X-Cache = "MISS";
      }
}
share|improve this answer
    
Nice. That works. I'd been using Varnish:hitmiss to add 'hit' and 'miss' to the logs, but varnishncsa wouldn't allow me to reference it in it the '-m' parameter. Using resp.http.X-Cache, the value of X-Cache gets echoed back to the client. Is there a way of achieving this without using visible HTTP headers? –  jetboy Jun 25 '12 at 9:41
    
You could potentially remove the header in vcl_deliver. Not sure if it would still be available to varnishcsa or not, but it might be. I strip a load of X-* headers in vcl_deliver except for my own IPs (useful for debugging purposes). –  chmac Jun 5 '13 at 11:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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