2007-06-03 16:55:53 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Guillaume Blairon
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; version 2 dated June,
|
|
|
|
# 1991.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Script to monitor MogileFS tracker queries.
|
|
|
|
# Mostly an adaptation of Jimmy Olsen's squid_cache script.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# ln -s /usr/share/munin/plugins/mogilefsd_activity \
|
|
|
|
# /etc/munin/plugins/
|
2018-08-02 02:03:42 +02:00
|
|
|
#
|
2007-06-03 16:55:53 +02:00
|
|
|
# Configuration variables:
|
|
|
|
#
|
|
|
|
# host (default: '127.0.0.1')
|
|
|
|
# port (default: '6001')
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# config (required)
|
|
|
|
# autoconf (optional - only used by munin-config)
|
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
my $ret = undef;
|
|
|
|
|
|
|
|
my $DEBUG = 0;
|
|
|
|
my @known_states=qw(queries);
|
|
|
|
|
|
|
|
if (! eval "require IO::Socket;")
|
|
|
|
{
|
|
|
|
$ret = "IO::Socket not found";
|
|
|
|
}
|
|
|
|
|
|
|
|
$mogilefsd_host = $ENV{host} || "127.0.0.1";
|
|
|
|
$mogilefsd_port = $ENV{port} || 6001;
|
|
|
|
|
|
|
|
if($ARGV[0] and $ARGV[0] eq "autoconf") {
|
|
|
|
&autoconf($mogilefsd_host, $mogilefsd_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub autoconf {
|
|
|
|
my ($host, $port) = @_;
|
|
|
|
|
|
|
|
if ($ret)
|
|
|
|
{
|
|
|
|
print "no ($ret)\n";
|
2018-09-16 04:01:57 +02:00
|
|
|
exit 0;
|
2007-06-03 16:55:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $conn = IO::Socket::INET->new(PeerAddr => $host,
|
|
|
|
PeerPort => $port,
|
|
|
|
Proto => 'tcp',
|
|
|
|
Timeout => 5) or die($!);
|
|
|
|
|
|
|
|
if (!$conn)
|
|
|
|
{
|
|
|
|
print "no (could not connect: $!)\n";
|
2018-09-16 04:01:57 +02:00
|
|
|
exit 0;
|
2007-06-03 16:55:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $request = "!stats\n";
|
|
|
|
|
|
|
|
$conn->syswrite($request, length($request));
|
|
|
|
|
|
|
|
my @lines = qw();
|
|
|
|
while (my $line = $conn->getline) {
|
|
|
|
if ($line =~ /^\./) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
push(@lines, $line);
|
|
|
|
}
|
|
|
|
close($conn);
|
|
|
|
|
|
|
|
print "yes\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub query_mogilefsd {
|
|
|
|
my ($host, $port) = @_;
|
|
|
|
|
|
|
|
my $conn = IO::Socket::INET->new(PeerAddr => $host,
|
|
|
|
PeerPort => $port,
|
|
|
|
Proto => 'tcp') or die($!);
|
|
|
|
|
|
|
|
my $request = "!stats\n";
|
|
|
|
|
|
|
|
$conn->syswrite("$request", length("$request"));
|
|
|
|
|
|
|
|
my @lines = qw();
|
|
|
|
while (my $line = $conn->getline) {
|
|
|
|
if ($line =~ /^\./) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
push(@lines, $line);
|
|
|
|
}
|
|
|
|
close($conn);
|
|
|
|
|
|
|
|
for(my $i = 0; $i <= $#lines; $i++) {
|
|
|
|
if($lines[$i] =~ /^([^\s]*)\s(\d+)/) {
|
|
|
|
$states{"$1"} = "$2";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys %states;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($ARGV[0] and $ARGV[0] eq "config") {
|
|
|
|
|
|
|
|
print "graph_title MogileFS tracker queries\n";
|
|
|
|
print "graph_vlabel queries/sec\n";
|
|
|
|
print "graph_args -l 0\n";
|
2017-02-23 15:31:40 +01:00
|
|
|
print "graph_category fs\n";
|
2007-06-03 16:55:53 +02:00
|
|
|
print "queries.label queries\n";
|
|
|
|
print "queries.type DERIVE\n";
|
|
|
|
print "queries.draw AREA\n";
|
|
|
|
print "queries.min 0\n";
|
|
|
|
|
|
|
|
exit 0;
|
2018-08-02 02:03:42 +02:00
|
|
|
}
|
|
|
|
|
2007-06-03 16:55:53 +02:00
|
|
|
print %states;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2007-06-03 16:55:53 +02:00
|
|
|
&query_mogilefsd($mogilefsd_host, $mogilefsd_port);
|
|
|
|
|
|
|
|
foreach $key (@known_states) {
|
|
|
|
print "$key.value ";
|
|
|
|
if (exists $states{$key}) {
|
|
|
|
print $states{$key}, "\n";
|
|
|
|
} else {
|
|
|
|
print "0\n";
|
|
|
|
}
|
|
|
|
}
|