Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Varnish check #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions lib/Core/Varnish.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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 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.*/) {
$value =~ s/\.happy/\.happy /g;
($metric_name, $metric_value, $metric_ps_avg, $metric_desc) = split(/ /, $value, 4);

} else {
# Split out metrics
$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;

}

# Counted metrics can get large, but always seem to be
# whole numbers
$metrics{$metric_name} = [ $metric_value, 'L' ] ;


if ($metric_value ne "null") {
# The per second averages can be floats
$metrics{"$metric_name\_per_sec"} = [ $metric_ps_avg, 'n' ] ;
}

}

return \%metrics;

};

1;