From 2993eea59c9f072235c5c6099ca5a6245b348204 Mon Sep 17 00:00:00 2001 From: Gavin Sandie Date: Tue, 28 Aug 2012 15:28:19 +0100 Subject: [PATCH 1/5] Add varnish stats module Process the output of varnishstat, attempt to match all of the metrics and report them. If possible report the per second averages. Take the names straight from what varnish reports. Only tested on varnish 3.0.2 on Linux. --- lib/Core/Varnish.pm | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 lib/Core/Varnish.pm diff --git a/lib/Core/Varnish.pm b/lib/Core/Varnish.pm new file mode 100644 index 0000000..2509295 --- /dev/null +++ b/lib/Core/Varnish.pm @@ -0,0 +1,97 @@ +package Core::Varnish; + +use strict; +use warnings; + +use base 'Resmon::Module'; + +use Resmon::ExtComm qw(run_command cache_command); + +=pod + +=head1 NAME + +Core::Varnish - a varnish stats module + +=head1 SYNOPSIS + + Core::Varnish { + local : noop + } + +=head1 CONFIGURATION + +=over + +=item check_name + +The check name is descriptive only in this check. It is not used for anything. + +=back + +=head1 METRICS + +Processes all metrics from the output of the varnishstat command. Returns both +the current metric value, and the average per second if there is one. + +=over + +=back + +=cut + +sub handler { + + my %metrics; + my $self = shift; + my $config = $self->{config}; + my $check_name = $self->{check_name}; + + my $stat_cmd = 'varnishstat -1'; + + my $varnish_stats = run_command($stat_cmd); + my @varnish_stats = split("\n", $varnish_stats); + my $metric_name; + my $metric_value; + my $metric_ps_avg; + my $metric_desc; + + foreach my $value (@varnish_stats) { + + $value =~ s/\s+/ /g; + # If there is no per second average we get a period. Report this as + # null + $value =~ s/\s\.\s/ null /g; + + # VBE metrics have a crazy name, treat them special. + if ($value =~ /^VBE.*/) { + + ($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); + + } else { + # Split out metrics, some thought towards maybe doing + # something with the metric description. + $value =~ /^([A-Z\.a-z_0-9]+)\s([0-9\.]+)\s([0-9\.]+|null)\s(.*)/; + $metric_name = $1; + $metric_value = $2; + $metric_ps_avg = $3; + $metric_desc = $4; + + } + + # The counted metrics always seem to be whole numbers + $metrics{$metric_name} = [ $metric_value, 'i' ] ; + + + if ($metric_value ne "null") { + # The per second averages can be floats + $metrics{"$metric_name\_per_sec"} = [ $metric_ps_avg, 'n' ] ; + } + + } + + return \%metrics; + +}; + +1; From 399681ee680ed830f5a6d33ac1f823573632f49a Mon Sep 17 00:00:00 2001 From: Gavin Sandie Date: Tue, 4 Sep 2012 14:55:43 +0100 Subject: [PATCH 2/5] Skip VBE metrics. --- lib/Core/Varnish.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Core/Varnish.pm b/lib/Core/Varnish.pm index 2509295..c5436c7 100644 --- a/lib/Core/Varnish.pm +++ b/lib/Core/Varnish.pm @@ -63,10 +63,10 @@ sub handler { # null $value =~ s/\s\.\s/ null /g; - # VBE metrics have a crazy name, treat them special. + # VBE happy probes can merge with the metric name. Skip all VBE metrics. if ($value =~ /^VBE.*/) { - - ($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); + next; + #($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); } else { # Split out metrics, some thought towards maybe doing From 91d4b4858a7168c537c2aa7960c7f633e789d504 Mon Sep 17 00:00:00 2001 From: Gavin Sandie Date: Mon, 11 Mar 2013 17:14:22 +0000 Subject: [PATCH 3/5] Update metric type for varnish counters --- lib/Core/Varnish.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Core/Varnish.pm b/lib/Core/Varnish.pm index c5436c7..c409cd9 100644 --- a/lib/Core/Varnish.pm +++ b/lib/Core/Varnish.pm @@ -79,8 +79,9 @@ sub handler { } - # The counted metrics always seem to be whole numbers - $metrics{$metric_name} = [ $metric_value, 'i' ] ; + # Counted metrics can get large, but always seem to be + # whole numbers + $metrics{$metric_name} = [ $metric_value, 'L' ] ; if ($metric_value ne "null") { From 8eb026d120813caa3a86e99188dd1785107f9f17 Mon Sep 17 00:00:00 2001 From: Gavin Sandie Date: Tue, 12 Mar 2013 22:35:45 +0000 Subject: [PATCH 4/5] Handle VBE metrics --- lib/Core/Varnish.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Core/Varnish.pm b/lib/Core/Varnish.pm index c409cd9..08f30d6 100644 --- a/lib/Core/Varnish.pm +++ b/lib/Core/Varnish.pm @@ -63,10 +63,11 @@ sub handler { # null $value =~ s/\s\.\s/ null /g; - # VBE happy probes can merge with the metric name. Skip all VBE metrics. + # VBE happy probes can merge with the metric name. Add an extra space after + # the happy probe to get a space to split on. if ($value =~ /^VBE.*/) { - next; - #($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); + $value =~ s/\.happy/\.happy /g; + ($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); } else { # Split out metrics, some thought towards maybe doing From eda7dcdc155ba941637a4254350f32e167e9653a Mon Sep 17 00:00:00 2001 From: Gavin Sandie Date: Tue, 12 Mar 2013 22:36:00 +0000 Subject: [PATCH 5/5] Clean up comment --- lib/Core/Varnish.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Core/Varnish.pm b/lib/Core/Varnish.pm index 08f30d6..0e13a21 100644 --- a/lib/Core/Varnish.pm +++ b/lib/Core/Varnish.pm @@ -70,8 +70,7 @@ sub handler { ($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4); } else { - # Split out metrics, some thought towards maybe doing - # something with the metric description. + # Split out metrics $value =~ /^([A-Z\.a-z_0-9]+)\s([0-9\.]+)\s([0-9\.]+|null)\s(.*)/; $metric_name = $1; $metric_value = $2;