r1769 - trunk/varnish-tools/munin

des at projects.linpro.no des at projects.linpro.no
Wed Jul 25 13:52:51 CEST 2007


Author: des
Date: 2007-07-25 13:52:51 +0200 (Wed, 25 Jul 2007)
New Revision: 1769

Modified:
   trunk/varnish-tools/munin/varnish_munin_plugin.pl
Log:
Allow values to be specified as arithmetic expressions written in Lisp-like
prefix notation.  Use this to compute the cache hit ratio in the same
manner as the Nagios plugin does, and to compute cache file usage.


Modified: trunk/varnish-tools/munin/varnish_munin_plugin.pl
===================================================================
--- trunk/varnish-tools/munin/varnish_munin_plugin.pl	2007-07-25 11:16:42 UTC (rev 1768)
+++ trunk/varnish-tools/munin/varnish_munin_plugin.pl	2007-07-25 11:52:51 UTC (rev 1769)
@@ -37,24 +37,63 @@
     'ratio' => {
 	'title' => 'Hit / miss ratio',
 	'type' => 'percent',
+	'order' => [ 'hit', 'miss' ],
 	'values' => {
 	    'hit' => {
 		'label' => 'hits',
 		'numerator' => 'cache_hit',
-		'denominator' => 'client_req',
+		'denominator' => [ '+', 'cache_hit', 'cache_miss' ],
 	    },
 	    'miss' => {
 		'label' => 'misses',
 		'numerator' => 'cache_miss',
-		'denominator' => 'client_req',
+		'denominator' => [ '+', 'cache_hit', 'cache_miss' ],
 	    },
 	},
     },
+    'usage' => {
+	'title' => 'Cache file usage',
+	'type' => 'percent',
+	'order' => [ 'used', 'free' ],
+	'values' => {
+	    'used' => {
+		'label' => 'used',
+		'numerator' => 'sm_balloc',
+		'denominator' => [ '+', 'sm_balloc', 'sm_bfree' ],
+	    },
+	    'free' => {
+		'label' => 'free',
+		'numerator' => 'sm_bfree',
+		'denominator' => [ '+', 'sm_balloc', 'sm_bfree' ],
+	    },
+	},
+    },
 );
 
+sub varnishstat($);
 sub varnishstat($) {
     my $field = shift;
 
+    if (ref($field) eq 'ARRAY') {
+	die "Too few terms in $field"
+	    if @$field < 2;
+	my $acc = varnishstat($$field[1]);
+
+	foreach (@$field[2..$#$field]) {
+	    if ($$field[0] eq '+') {
+		$acc += varnishstat($_);
+	    } elsif ($$field[0] eq '-') {
+		$acc -= varnishstat($_);
+	    } elsif ($$field[0] eq '*') {
+		$acc *= varnishstat($_);
+	    } elsif ($$field[0] eq '/') {
+		$acc /= varnishstat($_);
+	    } else {
+		die "Invalid spec for $field\n";
+	    }
+	}
+	return $acc;
+    }
     die "no such field: $field\n"
 	unless defined($varnishstat{$field});
     return $varnishstat{$field};
@@ -80,11 +119,19 @@
     }
 }
 
+sub order($) {
+    my $aspect = shift;
+
+    return (@{$aspect->{'order'}})
+	if (defined($aspect->{'order'}));
+    return (sort(keys(%{$aspect->{'values'}})));
+}
+
 sub measure($) {
     my $aspect = shift;
 
     defined($aspect) || die "oops";
-    my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}}));
+    my @order = order($aspect);
     foreach (@order) {
 	print "$_.value ",
 	    value($aspect->{'values'}->{$_}, $aspect->{'type'}),
@@ -101,7 +148,7 @@
     if ($aspect->{'type'} eq 'percent') {
 	print "graph_scale no\n";
     }
-    my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}}));
+    my @order = order($aspect);
     print "graph_order ", join(' ', @order), "\n";
     foreach (@order) {
 	my $value = $aspect->{'values'}->{$_};




More information about the varnish-commit mailing list