Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / mogilefsd_queries @ e908d2d2

Historique | Voir | Annoter | Télécharger (3,42 ko)

1
#!/usr/bin/perl -w
2
#
3
# Copyright (C) 2007 Guillaume Blairon
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; version 2 dated June,
8
# 1991.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
#
19
#
20
#
21
# Script to monitor MogileFS tracker queries.
22
# Mostly an adaptation of Jimmy Olsen's squid_cache script.
23
#
24
# Usage:
25
#    ln -s /usr/share/munin/plugins/mogilefsd_activity \
26
#       /etc/munin/plugins/
27
# 
28
# Configuration variables:
29
#
30
#    host (default: '127.0.0.1')
31
#    port (default: '6001')
32
#
33
# Parameters:
34
#
35
#    config    (required)
36
#    autoconf  (optional - only used by munin-config)
37
#
38
#%# family=auto
39
#%# capabilities=autoconf
40

    
41
my $ret = undef;
42

    
43
my $DEBUG = 0;
44
my @known_states=qw(queries);
45

    
46
if (! eval "require IO::Socket;")
47
{
48
        $ret = "IO::Socket not found";
49
}
50

    
51
$mogilefsd_host = $ENV{host} || "127.0.0.1";
52
$mogilefsd_port = $ENV{port} || 6001;
53

    
54
if($ARGV[0] and $ARGV[0] eq "autoconf") {
55
    &autoconf($mogilefsd_host, $mogilefsd_port);
56
}
57

    
58
sub autoconf {
59
    my ($host, $port) = @_;
60

    
61
    if ($ret)
62
    {
63
        print "no ($ret)\n";
64
        exit 1;
65
    }
66

    
67
    my $conn = IO::Socket::INET->new(PeerAddr => $host,
68
                                        PeerPort => $port,
69
                                        Proto    => 'tcp',
70
                                        Timeout  => 5) or die($!);
71

    
72
    if (!$conn)
73
    {
74
        print "no (could not connect: $!)\n";
75
        exit 1;
76
    }
77

    
78
    my $request = "!stats\n";
79

    
80
    $conn->syswrite($request, length($request));
81

    
82
    my @lines = qw();
83
    while (my $line = $conn->getline) {
84
        if ($line =~ /^\./) {
85
            last;
86
        }
87
        push(@lines, $line);
88
    }
89
    close($conn);
90

    
91
    print "yes\n";
92
    exit 0;
93
}
94

    
95

    
96
sub query_mogilefsd {
97
    my ($host, $port) = @_;
98

    
99
    my $conn = IO::Socket::INET->new(PeerAddr => $host,
100
                                        PeerPort => $port,
101
                                        Proto    => 'tcp') or die($!);
102

    
103
    my $request = "!stats\n";
104

    
105
    $conn->syswrite("$request", length("$request"));
106

    
107
    my @lines = qw();
108
    while (my $line = $conn->getline) {
109
        if ($line =~ /^\./) {
110
            last;
111
        }
112
        push(@lines, $line);
113
    }
114
    close($conn);
115

    
116
    for(my $i = 0; $i <= $#lines; $i++) {
117
        if($lines[$i] =~ /^([^\s]*)\s(\d+)/) {
118
            $states{"$1"} = "$2";
119
        }
120
    }
121
    keys %states;
122
}
123

    
124
if($ARGV[0] and $ARGV[0] eq "config") {
125

    
126
    print "graph_title MogileFS tracker queries\n";
127
    print "graph_vlabel queries/sec\n";
128
    print "graph_args -l 0\n";
129
    print "graph_category MogileFS\n";
130
    print "queries.label queries\n";
131
    print "queries.type DERIVE\n";
132
    print "queries.draw AREA\n";
133
    print "queries.min 0\n";
134

    
135
    exit 0;
136
}   
137
    
138
print %states;
139
        
140
&query_mogilefsd($mogilefsd_host, $mogilefsd_port);
141

    
142
foreach $key (@known_states) {
143
        print "$key.value ";
144
        if (exists $states{$key}) {
145
            print $states{$key}, "\n";
146
        } else {
147
            print "0\n";
148
        }
149
}