-
Notifications
You must be signed in to change notification settings - Fork 1
/
mogilefsd
executable file
·113 lines (84 loc) · 2.87 KB
/
mogilefsd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl
#
# Parameters supported:
#
# config
# autoconf
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use warnings;
use IO::Socket::INET;
use FindBin;
use Munin::Plugin;
=head1 NAME
mogilefsd - A munin plugin that collects stats from your MogileFS tracker
=head1 APPLICABLE SYSTEMS
MogileFS Trackers
=head1 CONFIGURATION
By default the plugin will check localhost, port 7001. If you want to change
the port set the following in your config:
[mogilefsd]
env.mog_port 7001
If you'd like to test a different host, then symlink the script with an
underscored followed by the hostname or IP:
ln -s /usr/share/munin/plugins/mogilefsd /etc/munin/plugins/mogilefsd_tracker1.domain.com
=head1 BUGS
None known so far. If you find any, let me know.
=head1 AUTHOR
Squeeks - c<[email protected]>
=head1 LICENSE
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
=cut
my $host = $FindBin::Script;
clean_fieldname($host =~ s/mogilefsd_?//);
if($ARGV[0] and $ARGV[0] eq 'config')
{
print "graph_title MogileFS $host Tracker status\n";
print "graph_category mogilefs\n";
print "graph_scale no\n";
print "pending.label Pending Queries\n"."pending.type GAUGE\n";
print "processing.label \n"."processing.type GAUGE\n";
print "bored.label Bored Workers\n"."bored.type GAUGE\n";
print "fsckqueue.label \n"."fsckqueue.type GAUGE\n";
print "queries.label Queries\n"."queries.type COUNTER\n";
exit 0;
}
elsif(!$ARGV[0] || $ARGV[0] eq 'autoconf')
{
my $sock = IO::Socket::INET->new(
PeerAddr => $host || '127.0.0.1',
PeerPort => $ENV{MOG_PORT} || '7001',
Proto => 'tcp')
or die("Could not create socket - ".$!);
print $sock "!stats\n";
my @rows;
while(<$sock>)
{
last if($_ eq "\x2E\x0D\x0A");
my ($row) = $_ =~/^(.*)\x0D\x0A$/;
push @rows, $row;
}
close($sock);
my ($pending) = $rows[1] =~/(\d+)$/ if($rows[1] && $rows[1] =~/^pending/);
my ($processing) = $rows[2] =~/(\d+)$/ if($rows[2] && $rows[2] =~/^processing/);
my ($bored) = $rows[3] =~/(\d+)$/ if($rows[3] && $rows[3] =~/^bored/);
my ($fsckqueue) = $rows[4] =~/(\d+)$/ if($rows[4] && $rows[4] =~/^work/);
my $queries = undef;
if($rows[4] && $rows[4] =~/^queries/)
{
($queries) = $rows[4] =~/(\d+)$/;
}
elsif($rows[5] && $rows[5] =~/^queries/)
{
($queries) = $rows[5] =~/(\d+)$/;
}
if($pending) { print "pending.value $pending\n"; } else{ print "pending.value 0\n"; }
if($processing) { print "processing.value $processing\n"; } else{ print "processing.value 0\n"; }
if($bored) { print "bored.value $bored\n"; } else{ print "bored.value 0\n"; }
if($fsckqueue) { print "fsckqueue.value $fsckqueue\n"; } else{ print "fsckqueue.value 0\n"; }
if($queries) { print "queries.value $queries\n"; } else{ print "queries.value 0\n"; }
}
# EOF