]> err.no Git - varnish/commitdiff
Added munin plugins.
authorcecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 27 Jun 2007 12:21:58 +0000 (12:21 +0000)
committercecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 27 Jun 2007 12:21:58 +0000 (12:21 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1583 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/munin/README [new file with mode: 0644]
varnish-tools/munin/varnish_cachehitratio [new file with mode: 0644]
varnish-tools/munin/varnish_hitrate [new file with mode: 0644]
varnish-tools/munin/varnish_varnishstat_ [new file with mode: 0644]

diff --git a/varnish-tools/munin/README b/varnish-tools/munin/README
new file mode 100644 (file)
index 0000000..461f592
--- /dev/null
@@ -0,0 +1,23 @@
+The scripts in this directory are munin plugins for monitoring varnish.
+varnish_cachehitratio and varnish_hitrate are written by Anders
+Nordby, while varnish_varnishstat_ is written by Bjørn
+Ruberg. All three scripts uses varnishstat to acquire information.
+
+* varnish_cachehitratio shows the cache hit/miss ratio.
+* varnish_hitrate shows the rate of requests.
+* varnish_varnishstat_ shows the cache usage.
+
+To work with named varnish instances, these scripts will have to be modified
+so they can call varnishstat with the appropriate parameter. As of today,
+the scripts only call 'varnishstat -1', and thus, will only work if varnishd
+was started without the -n parameter. A solution to this problem could be to
+let the scripts read a filename from an environment variable (this must then
+be set in the munin-plugin configuration), and have this file contain the
+name (or names?) to the varnish server(s) to monitor. If the environment
+variable is not set, varnishstat will be called without the -n parameter,
+and work with the default name.
+
+Dependencies:
+* varnish_cachehitration needs the CPAN module Date::Format
+* varnish_varnishstart_ needs the CPAN module Net::Telnet
+(but does it really? It doesn't seem to use it for anything.)
diff --git a/varnish-tools/munin/varnish_cachehitratio b/varnish-tools/munin/varnish_cachehitratio
new file mode 100644 (file)
index 0000000..c3d259e
--- /dev/null
@@ -0,0 +1,124 @@
+#! /usr/bin/perl
+# Varnish cache hit ratio logger/plugin
+# anders@aftenposten.no, 2007-05-07
+
+# Log/data file
+# These must be created with write permission to the user the plugin runs as
+# On FreeBSD, that is nobody
+# Comment $mylog out to skip logging
+
+$mydat = "/var/tmp/varnish_cachehitratio.dat";
+#$mylog = "/var/log/varnish_cachehitratio.log";
+
+%stat = ();
+$ENV{PATH} = "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin";
+
+use Date::Format;
+
+sub popstat {
+       foreach $line (`varnishstat -1`) {
+       chomp($line);
+               if ($line =~ /^\s+(\d+)\s+(.*)$/) {
+                       $val = $1;
+                       $key = $2;
+                       $key =~ s@\s@_@g;
+                       $key =~ tr@A-Z@a-z@;
+
+                       $stat{"$key"} = $val;
+               }
+       }
+}
+
+sub printconfig {
+       print "graph_title Cache hit/miss ratio\n";
+       print "graph_args --upper-limit 100 -l 0\n";
+       print "graph_vlabel % of requests\n";
+       print "graph_category varnish\n";
+       print "graph_info This graph shows the ratio of requests found in the cache and not\n";
+       print "graph_order hitratio missratio unknownratio\n";
+       print "graph_scale no\n";
+
+       print "hitratio.label hits\n";
+       print "hitratio.type GAUGE\n";
+       print "hitratio.graph yes\n";
+       print "hitratio.min 0\n";
+       print "hitratio.max 100\n";
+       print "hitratio.draw AREA\n";
+
+       print "missratio.label misses\n";
+       print "missratio.type GAUGE\n";
+       print "missratio.graph yes\n";
+       print "missratio.min 0\n";
+       print "missratio.max 100\n";
+       print "missratio.draw STACK\n";
+
+       print "unknownratio.label unknown\n";
+       print "unknownratio.type GAUGE\n";
+       print "unknownratio.graph yes\n";
+       print "unknownratio.min 0\n";
+       print "unknownratio.max 100\n";
+       print "unknownratio.draw STACK\n";
+}
+
+sub findvalues {
+       $nrequests = $stat{"client_requests_received"};
+       $nhits = $stat{"cache_hits"};
+       $nmisses = $stat{"cache_misses"};
+
+       open(OVAL, $mydat);
+       $tmpstr = <OVAL>;
+       close(OVAL);
+       chomp($tmpstr);
+
+       ($orequests,$ohits,$omisses) = split(/ /, $tmpstr, 3);
+
+       $hits = $nhits - $ohits;
+       $requests = $nrequests - $orequests;
+       $misses = $nmisses - $omisses;
+}
+
+sub printvalues {
+       if ($requests > 0) {
+               $hitratio = sprintf("%.2f", $hits / $requests * 100);
+               $missratio = sprintf("%.2f", $misses / $requests * 100);
+       } else {
+               # Assume cache hit ratio = 100% if requests < 0
+               $hitratio = sprintf("%.2f", 100);
+               $missratio = sprintf("%.2f", 0);
+       }
+
+       if (($hitratio + $missratio) > 100) {
+               # Rounding foo, hit+miss ratio is higher than 100
+               $missratio = sprintf("%.2f", 100 - $hitratio);
+               $unknownratio = sprintf("%.2f", 0);
+       } else {
+               # Unknown = rest, hit+miss ratio is upto or 100
+               $unknownratio = sprintf("%.2f", 100 - ($hitratio + $missratio));
+       }
+
+       print "hitratio.value $hitratio\n";
+       print "missratio.value $missratio\n";
+       print "unknownratio.value $unknownratio\n";
+       if ($mylog ne "") {
+               open(LOG, ">>$mylog");
+               print LOG "hitratio=$hitratio missratio=$missratio unknown=$unknownratio hits=$hits misses=$misses requests=$requests [" . time2str("%Y-%m-%d %H:%M:%S", time) . "]\n";
+               close(LOG);
+       }
+}
+
+sub writevalues {
+       open(OVAL, ">$mydat");
+       print OVAL "$nrequests $nhits $nmisses\n";
+       close(OVAL);
+}
+
+if ($ARGV[0] eq "autoconf") {
+       print "yes\n";
+} elsif ($ARGV[0] eq "config") {
+       printconfig;
+} else {
+       popstat;
+       findvalues;
+       printvalues;
+       writevalues;
+}
diff --git a/varnish-tools/munin/varnish_hitrate b/varnish-tools/munin/varnish_hitrate
new file mode 100644 (file)
index 0000000..3f64b43
--- /dev/null
@@ -0,0 +1,29 @@
+#! /bin/sh
+# anders@aftenposten.no, 2007-05-07
+# Shows the rate of requests (per second) for Varnish
+
+PATH="$PATH:/usr/local/bin"
+export PATH
+
+pvstat() {
+       # $1: vname $2: grabstat
+       printf "$1.value "
+       varnishstat -1 | egrep "$2" | awk '{print $1}'
+}
+
+case $1 in
+autoconf) echo yes;;
+config)
+       echo 'graph_title Hitrate'
+       echo 'graph_vlabel hits per second'
+       echo 'graph_category varnish'
+       echo 'graph_info This graph shows the rate of requests, hits per second'
+
+       echo 'requests.label requests'
+       echo 'requests.type COUNTER'
+       echo 'requests.graph yes'
+       ;;
+*)
+       pvstat requests 'Client requests received$'
+       ;;
+esac
diff --git a/varnish-tools/munin/varnish_varnishstat_ b/varnish-tools/munin/varnish_varnishstat_
new file mode 100644 (file)
index 0000000..a3c2792
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+use Net::Telnet ();
+use Data::Dumper;
+
+$arg = shift @ARGV;
+
+%aspects = (
+            'cache' => 'Cache',
+            'backend' => 'Backend',
+           'shm' => 'SHM'
+            );
+
+(my $whut = $0) =~ s/^.*\_//;
+
+# Hvis $whut IKKE fins, men $arg fins OG er noe annet enn blabla
+# så skal den trigge
+
+if (!$whut && $arg && $arg !~ /^(suggest|autoconf)$/) {
+    print "Only 'suggest' and 'autoconf' may be used w/o symlinked name\n";
+    exit 2;
+} elsif (!$whut && !$arg) {
+    print "Uh. Bugger.\n";
+    exit 2;
+}
+
+if ($arg eq 'autoconf') {
+    print "Autoconf starting...\n";
+    exit 0;
+} elsif ($arg eq 'suggest') {
+    print "Suggest starting...\n";
+    exit 0;
+} elsif ($arg eq 'config') {
+    $config = 1;
+}
+
+$grepfor = $aspects{$whut};
+# print "Looking for $grepfor\n";
+
+if ($config) {
+    print "graph_title Varnish $grepfor usage\n";
+    print "graph_args --base 1000\n";
+    print "graph_vlabel Activity / \${graph_period}\n";
+    print "graph_category Varnish\n";
+}
+
+$i = 0;
+foreach $line (`varnishstat -1`) {
+    chomp $line;
+    if ($line =~ /^\s+(\d+)\s+($grepfor.*)$/) {
+        $val = $1;
+        $key = $2;
+        ($printkey = lc ($key)) =~ s/\s/_/g;
+        if ($config) {
+            print "$printkey\.label $key\n";
+            print "$printkey\.type DERIVE\n";
+            print "$printkey\.min 0\n";
+               print "$printkey\.draw ";
+           if ($i == 0) {
+               print "AREA\n";
+            } else {
+               print "STACK\n";
+           }
+            $i++;
+        } else {
+            print "$printkey\.value $val\n";
+        }
+    }
+}
+    
+exit;
+