<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>TomsBlog</title>
    <link>http://www.toms-blog.com/tags/varnish/index.xml</link>
    <description>Recent content on TomsBlog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-uk</language>
    <atom:link href="http://www.toms-blog.com/tags/varnish/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Nagios Varnish performance plugin</title>
      <link>http://www.toms-blog.com/post/nagios-varnish-performance-plugin/</link>
      <pubDate>Thu, 18 Jul 2013 21:38:03 +0000</pubDate>
      
      <guid>http://www.toms-blog.com/post/nagios-varnish-performance-plugin/</guid>
      <description>

&lt;p&gt;Varnish is a web application accelerator and sits in front of your web server. It speeds up your application by caching some, if not all of the content meaning it reduces the load on your web server and can reduce the load on you backend as less lookups will be needed by the frontend.&lt;/p&gt;

&lt;p&gt;As varnish is the first thing users hit it is imperative it is working properly and you have statistics on how it is performing. This plugin can give you a better insight into how affectively varnish is running and tell you if its having problems.&lt;/p&gt;

&lt;a target=&#34;_blank&#34; href=&#34;https://github.com/thomasweaver/check_varnish&#34;&gt;https://github.com/thomasweaver/check_varnish &lt;/a&gt;

&lt;h2 id=&#34;install&#34;&gt;Install&lt;/h2&gt;

&lt;p&gt;To use this plugin you need to have varnishstat installed which is installed by default when you install varnish.&lt;/p&gt;

&lt;p&gt;Perl is also required for this plugin. If you don’t have Perl installed you can install in by running the command below&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;sudo apt-get install perl
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;or&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;sudo yum install perl
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you can clone the repo above&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;git clone https://github.com/thomasweaver/check_varnish.git
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now you should have a file “check_varnish.pl” make sure that it has execute permissions:&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;chmod u+x check_varnish.pl
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You now need to copy this file to your nagios plugins folder. You should consult your nagios config to find out where this is. Mine was ‘/usr/lib/nagios/plugin’&lt;/p&gt;

&lt;div class=&#34;highlight&#34; style=&#34;background: #f0f3f3&#34;&gt;&lt;pre style=&#34;line-height: 125%&#34;&gt;&lt;span&gt;&lt;/span&gt;mv check_varnish.pl /usr/lib/nagios/plugins/.
&lt;/pre&gt;&lt;/div&gt;


&lt;h2 id=&#34;how-to&#34;&gt;How To&lt;/h2&gt;

&lt;div class=&#34;box&#34;&gt;
&lt;p&gt;check_varnish.pl – Monitor and report on varnish usage&lt;/p&gt;

&lt;p&gt;check_varnish.pl [-c|–cache] [-b|–bin &lt;varnishstatbinary&gt;] [-d|–backend &lt;total|ratio&gt;] [-s|–stats &lt;varnish statfield&gt;]  [-t|–technique &lt;lt|gt&gt;] [-w|–warning &lt;number&gt;] [-c|–critical &lt;number&gt;] [-h|–help]&lt;/p&gt;

&lt;p&gt;DESCRIPTION&lt;/p&gt;

&lt;p&gt;This script will report on various varnish stats including: varnish cache hit ratio backend error count (Total or Ratio) Any other counter in varnishstat If no counters are required the script will ensure the varnish binary is running&lt;/p&gt;

&lt;p&gt;OPTIONS&lt;/p&gt;

&lt;p&gt;-a –cache – this will make the script output cache_hit ratio perfdata&lt;/p&gt;

&lt;p&gt;-b –bin &lt;varnishstat&gt; – to specify a different location of the default varnishstat binary location. Default is ‘/usr/bin/varnishstat’&lt;/p&gt;

&lt;p&gt;-d –backend &lt;all|success|unhealthy|busy|fail|reuse|toolate|recycle|retry&gt; – specify script to output backend data you can output ratio, total or both&lt;/p&gt;

&lt;p&gt;-h –help – output this message&lt;/p&gt;

&lt;p&gt;-w –warning &lt;number&gt; – specify the warning threshold. Required for cache and backend checks&lt;/p&gt;

&lt;p&gt;-c –critical &lt;number&gt; – specify the critical threshold. Required for cache and backend checks&lt;/p&gt;

&lt;p&gt;-s –stats &lt;varnishstat field&gt; – specify a comma separated list of all the stats you wish to check Critical and Warning can be specified and all values will be compared to these values.&lt;/p&gt;

&lt;p&gt;-t –technique &lt;lt|gt&gt; – when specifying stats you can also specify what technique you wish to use to compare the values to the thresholds. specify lt for less than and gt for greater than. Default is gt&lt;/p&gt;

&lt;p&gt;EXAMPLES&lt;/p&gt;

&lt;p&gt;Check varnish is running&lt;/p&gt;

&lt;p&gt;./check_varnish.pl&lt;/p&gt;

&lt;p&gt;Check varnish Cache Hit Ratio and warn if ratio is below 0.8&lt;/p&gt;

&lt;p&gt;./check_varnish.pl -a -w 0.8 -c 0.6&lt;/p&gt;

&lt;p&gt;Check varnish Backends&lt;/p&gt;

&lt;p&gt;./check_varnish.pl -d all&lt;/p&gt;

&lt;p&gt;Check varnish client requests and drops&lt;/p&gt;

&lt;p&gt;./check_varnish.pl -s client_drop,client_req&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;nagios-set-up&#34;&gt;Nagios Set Up&lt;/h2&gt;

&lt;p&gt;Once you have run the command in the CLI and all is working you can add the command:&lt;/p&gt;

&lt;div class=&#34;box&#34;&gt;
&lt;p&gt;define command {&lt;/p&gt;

&lt;p&gt;command_name                    check_varnish&lt;/p&gt;

&lt;p&gt;command_line                    $USER1$/check_varnish.pl $ARG1$&lt;/p&gt;

&lt;p&gt;register                        1&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;$USER1$ is your variable pointing to your nagios plugins folder and $ARG1$ are any command line arguments you specify in the service.&lt;/p&gt;

&lt;div class=&#34;box&#34;&gt;
&lt;p&gt;define service {&lt;/p&gt;

&lt;p&gt;host_name                       localhost&lt;/p&gt;

&lt;p&gt;service_description             Varnish&lt;/p&gt;

&lt;p&gt;check_command                   check_varnish!&amp;ndash;cache -w 0.6 -c 0.4&lt;/p&gt;

&lt;p&gt;register                        1&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;The service above will give a warning if the hit ratio goes below 0.6 and critical if the ratio goes below 0.4&lt;/p&gt;

&lt;h2 id=&#34;nrpe&#34;&gt;NRPE&lt;/h2&gt;

&lt;p&gt;The below is a line that can be used in the NRPE configuration for remote monitoring:&lt;/p&gt;

&lt;div class=&#34;box&#34;&gt;
&lt;p&gt;command[check_varnish_cache_hit]=/usr/lib/nagios/plugins/check_varnish.pl &amp;ndash;cache -w 0.6 -c 0.4&lt;/p&gt;

&lt;/div&gt;

&lt;p&gt;The NRPE service could look like this:&lt;/p&gt;

&lt;div class=&#34;box&#34;&gt;
&lt;p&gt;define service {&lt;/p&gt;

&lt;p&gt;host_name                  varnishserver&lt;/p&gt;

&lt;p&gt;service_description             Varnish Cache Hit Ratio&lt;/p&gt;

&lt;p&gt;check_command                   check_nrpe!check_varnish_cache_hit&lt;/p&gt;

&lt;p&gt;register                        1&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;performance-data&#34;&gt;Performance Data&lt;/h2&gt;

&lt;p&gt;For certain stats the plugin outputs performance data which can be truned into graphs. The graphs below were produced by nagios and nagiosgrapher:
This graph show the performance data when varnish was restarted. As you can see the cache suddenly drops off and then slowly builds back up as more users access the site&lt;/p&gt;

&lt;img src=&#34;http://www.toms-blog.com/images/posts/check_varnish/varnish-perf-data-start.png&#34; alt=&#34;Graph of Varnish cache hit ratio on restart&#34; class=&#34;pure-img&#34;&gt;

&lt;p&gt;The graph below shows the cache hit ratio slowly increasing over a week. This means most of the cache has been populated and so most of the request are coming from the cache.&lt;/p&gt;

&lt;img src=&#34;http://www.toms-blog.com/images/posts/check_varnish/varnish-perf-data-weekly.png&#34; alt=&#34;Graph of Varnish cache hit ratio slowly increasing over a week&#34; class=&#34;pure-img&#34;&gt;
</description>
    </item>
    
  </channel>
</rss>