From: des Date: Wed, 25 Jul 2007 11:52:51 +0000 (+0000) Subject: Allow values to be specified as arithmetic expressions written in Lisp-like X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddb54a4878598a1a6c7a5183c931360cf3196829;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1769 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/munin/varnish_munin_plugin.pl b/varnish-tools/munin/varnish_munin_plugin.pl index 84793a60..1598b027 100755 --- a/varnish-tools/munin/varnish_munin_plugin.pl +++ b/varnish-tools/munin/varnish_munin_plugin.pl @@ -37,24 +37,63 @@ our %ASPECTS = ( '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 value($$) { } } +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 @@ sub config($) { 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'}->{$_};