~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to node/node.d.linux/cps_.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
ImportĀ upstreamĀ versionĀ 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@@PERL@@
 
2
#
 
3
# Plugin to monitor connections per second, for LVS loadbalancers.
 
4
#
 
5
# Magic name:
 
6
#
 
7
#       cps_<port>
 
8
#       cps_<vip>_<port>
 
9
#
 
10
# Examples:
 
11
#
 
12
#       cps_smtp
 
13
#       cps_mail.foo.boo_smtp
 
14
#       cps_pop3
 
15
#       cps_www.foo.boo_www
 
16
#       cps_vvv.foo.boo_www
 
17
#
 
18
# Parameters understood:
 
19
#
 
20
#       config   (required)
 
21
#       autoconf (optional - used by munin-config)
 
22
#       suggest  (optional - used by munin-config)
 
23
#
 
24
# $Log: cps_.in,v $
 
25
# Revision 1.1  2004/01/02 18:50:01  jimmyo
 
26
# Renamed occurrances of lrrd -> munin
 
27
#
 
28
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
 
29
# Import of LRRD CVS tree after renaming to Munin
 
30
#
 
31
# Revision 1.4  2003/11/07 17:43:16  jimmyo
 
32
# Cleanups and log entries
 
33
#
 
34
#
 
35
#
 
36
# Magic markers - optional - used by installation scripts and munin-config:
 
37
#
 
38
#%# family=manual
 
39
#%# capabilities=autoconf suggest
 
40
#
 
41
 
 
42
use strict;
 
43
 
 
44
my $HOSTNAME="aibo.runbox.com";
 
45
 
 
46
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
 
47
{
 
48
        &autoconf ();
 
49
}
 
50
if ( defined $ARGV[0] and $ARGV[0] eq "suggest" )
 
51
{
 
52
        my $sipvs;
 
53
        $sipvs = &ipvs (".", ".", $sipvs);
 
54
        exit 0 if $sipvs == undef;
 
55
        &suggest ($sipvs);
 
56
}
 
57
 
 
58
unless ($0 =~ /cps(?:_([^_]+)|)_(.+)\s*$/)
 
59
{
 
60
        die "Could not parse name $0.\n";
 
61
}
 
62
my $vip  = $1;
 
63
my $port = $2;
 
64
my $ipvs;
 
65
 
 
66
#print "Name: $0\nPort: $port\nVip : $vip\n";
 
67
 
 
68
# Read ipvsadm-output
 
69
 
 
70
$ipvs = &ipvs ($vip, $port, $ipvs);
 
71
 
 
72
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
 
73
{
 
74
        &config ($vip, $port, $ipvs);
 
75
}
 
76
 
 
77
$vip = $vip || "";
 
78
if (exists ($ipvs->{$vip}) and exists ($ipvs->{$vip}->{$port}))
 
79
{
 
80
        foreach my $host (sort keys %{$ipvs->{$vip}->{$port}})
 
81
        {
 
82
                (my $fname = $host) =~ s/[.-]/_/g;
 
83
                print "$fname.value ", $ipvs->{$vip}->{$port}->{$host}, "\n";;
 
84
        }
 
85
}
 
86
 
 
87
sub autoconf
 
88
{
 
89
        system ("/sbin/ipvsadm -L --stats >/dev/null 2>/dev/null");
 
90
 
 
91
        if ($? == 0)
 
92
        {
 
93
                print "yes\n";
 
94
                exit 0;
 
95
        }
 
96
        elsif (($?>>8) == 2)
 
97
        {
 
98
                print "no (permission denied)\n";
 
99
                exit 1;
 
100
        }
 
101
        elsif ($? == 127)
 
102
        {
 
103
                print "no (ipvsadm not found)\n";
 
104
                exit 1;
 
105
        }
 
106
        else
 
107
        {
 
108
                print "no\n";
 
109
                exit 1;
 
110
        }
 
111
}
 
112
sub suggest
 
113
{
 
114
        my $ipvs = shift;
 
115
        exit 0 unless $ipvs;
 
116
 
 
117
        foreach my $vip (sort keys %{$ipvs})
 
118
        {
 
119
                foreach my $port (sort keys %{$ipvs->{$vip}})
 
120
                {
 
121
                        print "cps_${vip}_$port\n";
 
122
                }
 
123
        }
 
124
        exit 0;
 
125
}
 
126
 
 
127
sub config
 
128
{
 
129
        my $vip  = shift;
 
130
        my $port = shift;
 
131
        my $ipvs = shift;
 
132
 
 
133
        print "host_name $HOSTNAME\n";
 
134
        print "graph_title Loadbalanced ",($vip?$vip:"*"),"->",$port," connections\n";
 
135
        print "graph_args -l 0\n";
 
136
        print "graph_total total\n";
 
137
        print "graph_vlabel connections / second\n";
 
138
        my $first=1;
 
139
        $vip = $vip || "";
 
140
        if (exists ($ipvs->{$vip}) and exists ($ipvs->{$vip}->{$port}))
 
141
        {
 
142
                foreach my $host (sort keys %{$ipvs->{$vip}->{$port}})
 
143
                {
 
144
                        (my $fname = $host) =~ s/[.-]/_/g;
 
145
                        if ( $first == 1 )
 
146
                        {
 
147
                                print "$fname.draw AREA\n";
 
148
                                $first=0
 
149
                        }
 
150
                        else
 
151
                        {
 
152
                                print "$fname.draw STACK\n";
 
153
                        }
 
154
                        print "$fname.type COUNTER\n";
 
155
                        $host =~ s/-bak//;
 
156
                        print "$fname.label $host\n";
 
157
                        print "$fname.max 1000\n";
 
158
                }
 
159
        }
 
160
        exit 0;
 
161
}
 
162
 
 
163
sub ipvs
 
164
{
 
165
        my $vip  = shift;
 
166
        my $port = shift;
 
167
        my $ipvs = shift;
 
168
        open (IPVS, "/sbin/ipvsadm -L --stats 2>/dev/null|") or return undef;
 
169
        my $cvip  = "";
 
170
        my $cport = "";
 
171
        while (<IPVS>)
 
172
        {
 
173
                next if /^IP Virtual Server/;
 
174
                next if /^Prot\s+LocalAddress/;
 
175
                if (/^(\w+)\s+([\w\.-]+):([\w\d]+)\s+(\d+)\s+/)
 
176
                {
 
177
                        $cvip  = ($vip?$2:"");
 
178
                        $cport = $3;
 
179
                }
 
180
                elsif (/^\s+->\s+([^:]+):(\S+)\s+(\d+)\s+/)
 
181
                {
 
182
                        $ipvs->{$cvip}->{$cport}->{$1} += $3;
 
183
                }
 
184
        }
 
185
        close (IPVS) or return undef;
 
186
        return $ipvs;
 
187
}
 
188
# vim:syntax=perl