r1583 - in trunk/varnish-tools: . munin

cecilihf at projects.linpro.no cecilihf at projects.linpro.no
Wed Jun 27 14:21:59 CEST 2007


Author: cecilihf
Date: 2007-06-27 14:21:58 +0200 (Wed, 27 Jun 2007)
New Revision: 1583

Added:
   trunk/varnish-tools/munin/
   trunk/varnish-tools/munin/README
   trunk/varnish-tools/munin/varnish_cachehitratio
   trunk/varnish-tools/munin/varnish_hitrate
   trunk/varnish-tools/munin/varnish_varnishstat_
Log:
Added munin plugins.


Added: trunk/varnish-tools/munin/README
===================================================================
--- trunk/varnish-tools/munin/README	                        (rev 0)
+++ trunk/varnish-tools/munin/README	2007-06-27 12:21:58 UTC (rev 1583)
@@ -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.)

Added: trunk/varnish-tools/munin/varnish_cachehitratio
===================================================================
--- trunk/varnish-tools/munin/varnish_cachehitratio	                        (rev 0)
+++ trunk/varnish-tools/munin/varnish_cachehitratio	2007-06-27 12:21:58 UTC (rev 1583)
@@ -0,0 +1,124 @@
+#! /usr/bin/perl
+# Varnish cache hit ratio logger/plugin
+# anders at 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 at _@g;
+			$key =~ tr at 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;
+}

Added: trunk/varnish-tools/munin/varnish_hitrate
===================================================================
--- trunk/varnish-tools/munin/varnish_hitrate	                        (rev 0)
+++ trunk/varnish-tools/munin/varnish_hitrate	2007-06-27 12:21:58 UTC (rev 1583)
@@ -0,0 +1,29 @@
+#! /bin/sh
+# anders at 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

Added: trunk/varnish-tools/munin/varnish_varnishstat_
===================================================================
--- trunk/varnish-tools/munin/varnish_varnishstat_	                        (rev 0)
+++ trunk/varnish-tools/munin/varnish_varnishstat_	2007-06-27 12:21:58 UTC (rev 1583)
@@ -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;
+




More information about the varnish-commit mailing list