Posts Tagged ‘varnish’

Collectd and Varnish user ? We need your feedback

July 15th, 2010

If you use collectd and would like to monitor your Varnish instance(s), this blog post is for you. The new Varnish plugin for collectd is ready, however we would love to get feedback from you. The plugin has already been pushed on production on Camp To Camp and the feedback is really positive so far. However it is always good to get more feedback from different people using collectd and Varnish in different contexts.

How can you help ? Simply run the Varnish plugin on one of your production (or test) server(s) and provide feedback, and ideally some graphs :)

Installing the Varnish plugin for Collectd is really trivial :

1. run git clone http://github.com/octo/collectd.git

2. compile collectd as you would normally do, do not forget the –enable-varnish flag

3. configure the Varnish plugin in collectd.conf, as explained in the configuration synopsis

4. start collectd

For more information, feel free to read and/or comment the dedicated wiki page .

Feedback can be provided as you wish, either by sending an email to the mailing-list or directly to me <jerome.renard @ gmail.com>

Thanks in advance for your feedback.

:)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Getting varnish statistics in XML format

May 27th, 2010

I was searching something in the Varnish source code when I found a non documented (at least there is nothing in man varnishstat, for Varnish 2.1.2) feature.

Varnishstat can return statistics in XML. How to get this format ? That’s pretty simple, just add the -x argument to varnishstat, for example using :

varnishstat -x

will return something like :

<?xml version="1.0"?>
<varnishstat timestamp="2010-05-27T17:03:26">
 <stat>
 <name>client_conn</name>
 <value>33036</value>
 <description>Client connections accepted</description>
 </stat>
 <stat>
 <name>client_drop</name>
 <value>0</value>
 <description>Connection dropped, no sess/wrk</description>
 </stat>
 <stat>
 <name>client_req</name>
 <value>34740</value>
 <description>Client requests received</description>
 </stat>
 <stat>
 <name>cache_hit</name>
 <value>33580</value>
 <description>Cache hits</description>
 </stat>
[....]
</varnishstat>

So now, if you only want to get cache hits and cache_misses in XML so you can parse them easily on you can do :

varnishstat -f cache_hit,cache_miss -x

And you get something like

<?xml version="1.0"?>
<varnishstat timestamp="2010-05-27T17:05:41">
 <stat>
 <name>cache_hit</name>
 <value>33580</value>
 <description>Cache hits</description>
 </stat>
 <stat>
 <name>cache_miss</name>
 <value>1160</value>
 <description>Cache misses</description>
 </stat>
</varnishstat>

If you want to know more about that, have a look at the do_xml function in varnishstat.c

‘Hope that helps :)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Some notes about Varnish

January 13th, 2010

A quick memo about useful informations I found on Varnish this afternoon after digging in the VCL system. I prefer writing them somewhere before forgetting…

The list of variables available in VCL for each context is available in libvcl/vcc_obj.c which seems to be generated by lib/libvcl/vcc_gen_fixed_token.tcl.

In vcc_gen_fixed_token.vcl the following code :

{ client.ip                IP
 RO
 all
 "const struct sess *"
}

Results in the following C code:

{ "client.ip", IP, 9,
 "VRT_r_client_ip(sp)",
 NULL,
 V_RO,        0,
 VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
 | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 | VCL_MET_ERROR
 },

“client.ip” is the directive available in a VCL file, “RO” means Read Only – “RW” (Read Write is available as well) – ‘all’ means it is available in all contexts in the VCL file :

VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR

The list of functions one can use directly (between C{ … }C tags) in VCL seems is available in include/vrt_obj.h VRT_SetHdr and VRT_GetHdr are available in include/vrt.h (for the declaration) and in bin/varnishd/cache_vrt.c.

It is possible to change the TTL of an item directly by using a few lines of C code, like for example :

if (obj.http.My-Header)
{
 C{
   char *ttl;
   ttl = VRT_GetHdr(sp, HDR_OBJ, "\012My-Header:");
   VRT_l_obj_ttl(sp, atoi(ttl));
 }C
   remove obj.http.My-Header;
 }
}

The “\012″ prepended to “My-Header” is the octal version of the length of the “My-Header” string.

The “sp” variable is the variable describing the current session.

HDR_OBJ is a constant available in in include/vrt.h :

enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };

It is possible to define custom HTTP headers by using the VRT_SetHdr function available in bin/varnishd/cache_vrt.c.

For example :

C{
 const char *contentMD5 = "12345";
 VRT_SetHdr(sp, HDR_RESP, "\014Content-MD5:", contentMD5, vrt_magic_string_end);
 }C

Reading the VCC code generated from a VCL file is available by running :

varnishd -d -f path/to/file.vcl -C

Useful links:

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)