Projet

Général

Profil

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

root / plugins / ultramonkey / ultramonkey-l7 @ e5ce7492

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

1
#!/usr/bin/env perl
2

    
3
use strict;
4
use warnings;
5

    
6
# must be run as root
7
my $L7VSADM = q{ /usr/sbin/l7vsadm };
8

    
9
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
10
        get_autoconf();
11
}
12
elsif ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
13
        get_config();
14
}
15
else {
16
        get_value();
17
}
18
exit 0;
19

    
20
# -------------------------------------------------------------------------- #
21

    
22
sub get_autoconf
23
{
24
    `$L7VSADM`;
25
    if ( $? ) {
26
        print qq{no ($L7VSADM something wrong ...)\n};
27
        exit 1;
28
    }
29

    
30
    print qq{yes\n};
31
}
32

    
33

    
34
sub get_config
35
{
36
    my %l7vsadm = get_l7vsadm();
37

    
38
    # print graph config
39
    my $graph_order = join q{ }, keys %l7vsadm;
40
    print << "END_graph_";
41
graph_title Connections
42
graph_args --base 1000 -l 0
43
graph_vlabel connections / sec
44
graph_info UltraMonkey-L7 Connections
45
graph_category Ultramonkey-L7
46
graph_order $graph_order
47
END_graph_
48

    
49
    # print graph config detail each hosts
50
    foreach my $host ( sort keys %l7vsadm ) {
51
        print << "END_hosts_";
52
$host.label $host
53
$host.type COUNTER
54
$host.draw AREASTACK
55
END_hosts_
56
    }
57
}
58

    
59

    
60
sub get_value
61
{
62
    my %l7vsadm = get_l7vsadm();
63

    
64
    foreach my $host ( sort keys %l7vsadm ) {
65
        my $value = $l7vsadm{$host}->{InactConn};
66
        print qq{$host.value $value\n};
67
    }
68
}
69

    
70

    
71
sub get_l7vsadm
72
{
73
    my @l7vsadm_output = `$L7VSADM`;
74
    if ( $? ) {
75
        exit 1;
76
    }
77

    
78
    my @lines = map { s{ \s* -> \s* }{}xms; $_ } grep /->/, @l7vsadm_output;
79
    my $header = shift @lines;
80
    my @header_columns = split /\s+/, $header;
81
    shift @header_columns;
82

    
83
    my %l7vsadm = ();
84
    foreach ( @lines ) {
85
        my ( $host, @values ) = split /\s+/, $_;
86
        my %value_hash = ();
87
        @value_hash{ @header_columns } = @values;
88
        $l7vsadm{$host} = \%value_hash;
89
    }
90

    
91
    %l7vsadm;
92
}
93

    
94

    
95
__END__
96
# -------------------------------------------------------------------------- #
97
This program must be run as root.
98
add settings like below.
99

    
100
--- /etc/munin/plugin-conf.d/munin-node ---
101
[ultramonkeyl7]
102
user root
103
--- /etc/munin/plugin-conf.d/munin-node ---
104

    
105
# -------------------------------------------------------------------------- #
106
get_l7vsadm : l7vsadm output to hash
107

    
108
--- l7vsadm output ---
109
Layer-7 Virtual Server version 3.0.1
110
Prot LocalAddress:Port ProtoMod Scheduler
111
  -> RemoteAddress:Port           Forward Weight ActiveConn InactConn
112
TCP ldb001:mysql sessionless lc
113
  -> db002:mysql                  Masq    1      0          2796
114
  -> db003:mysql                  Masq    1      0          259
115
  -> db004:mysql                  Masq    1      0          6
116
--- l7vsadm output ---
117

    
118
--- hash ---
119
$VAR1 = {
120
          'db002:mysql' => {
121
                             'ActiveConn' => '0',
122
                             'Forward' => 'Masq',
123
                             'InactConn' => '2796',
124
                             'Weight' => '1'
125
                           },
126
          'db003:mysql' => {
127
                              'ActiveConn' => '0',
128
                              'Forward' => 'Masq',
129
                              'InactConn' => '259',
130
                              'Weight' => '1'
131
                            },
132
          'db004:mysql' => {
133
                             'ActiveConn' => '0',
134
                             'Forward' => 'Masq',
135
                             'InactConn' => '6',
136
                             'Weight' => '1'
137
                           },
138
--- hash ---
139