From 41f5c9d6417e80c8e6403f3d8c8150b162415285 Mon Sep 17 00:00:00 2001 From: David Crosby <dcrosby@sourcefire.com> Date: Tue, 30 Apr 2013 11:04:52 -0600 Subject: [PATCH] Module for Membase --- lib/Core/Membase.pm | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 lib/Core/Membase.pm diff --git a/lib/Core/Membase.pm b/lib/Core/Membase.pm new file mode 100644 index 0000000..891fac8 --- /dev/null +++ b/lib/Core/Membase.pm @@ -0,0 +1,101 @@ +package Core::Membase; + +use strict; +use warnings; + +use base 'Resmon::Module'; + +use Resmon::ExtComm qw(run_command); + +=pod + +=head1 NAME + +Core::Membase - A resmon module for gathering Membase statistics + +=head1 SYNOPSIS + + Core::Membase { + 127.0.0.1: user => foo, pass => bar + } + +=head1 DESCRIPTION + +This module gathers Membase statistics + +=head1 CONFIGURATION + +=over + +=item check_name + +The IP or FQDN of the Membase server. + +=item mbstats + +The location of the mbstats command. Defaults to /opt/membase/bin/mbstats. + +=item port + +The port that the target service listens on. This defaults to 11210. + +=item user + +The username to connect with. + +=item pass + +The password to connect with. + +=back + +=head1 METRICS + +This check returns a significant number of metrics. See the following for +explanations: + + https://github.com/membase/ep-engine/blob/master/docs/stats.org + +=cut + +sub handler { + my $self = shift; + my $config = $self->{'config'}; + my $host = $self->{'check_name'}; + my $port = $config->{'port'} || "11210"; + my $user = $config->{'user'} || ""; + my $pass = $config->{'pass'} || ""; + my $mbstats = $config->{'mbstats'} || "/opt/membase/bin/mbstats"; + my $mbstats_path = "$mbstats -a $host:$port all $user $pass"; + + my $output = run_command($mbstats_path); + chomp $output; + my @arr = split("\n", $output); + + my $line; + my $bucket = ""; + my $get_name = 0; + my %metrics; + foreach $line (@arr) { + if ($line =~ /\*/) { + $get_name = 1; + next; + } + if ($get_name == 1) { + $line =~ s/\s+// ; + $bucket = $line; + $get_name = 0; + next; + } + if ($line ne "") { + $line =~ s/\s+//g; + my ($key, $val) = split(":", $line); + $metrics{"$bucket|$key"} = $val; + } + } + + return \%metrics + +}; + +1; -- GitLab