3
# When using squid as a "load balancer" (of sorts), who gets the
6
# Configuration variables:
8
# squidhost - host (default "localhost")
9
# squidport - port (default "3128")
10
# squiduser - username (default "")
11
# squidpasswd - password (default "")
16
# autoconf (optional - only used by munin-config)
18
# $Log: squid_icp.in,v $
19
# Revision 1.2 2004/03/14 11:33:13 auduny
20
# Added squidpatch from Jacques Caruso
22
# Revision 1.1 2004/01/02 18:50:00 jimmyo
23
# Renamed occurrances of lrrd -> munin
25
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
26
# Import of LRRD CVS tree after renaming to Munin
28
# Revision 1.6 2003/12/18 17:26:26 jimmyo
31
# Revision 1.5 2003/11/10 18:41:33 jimmyo
32
# Removed Data::Dumper dependency.
34
# Revision 1.4 2003/11/07 21:36:25 jimmyo
35
# Fixed typos and mental typos
37
# Revision 1.3 2003/11/07 17:43:16 jimmyo
38
# Cleanups and log entries
43
#%# capabilities=autoconf
45
# $Id: squid_icp.in,v 1.2 2004/03/14 11:33:13 auduny Exp $
49
if (! eval "require IO::Socket;")
51
$ret = "IO::Socket not found";
53
if (! eval "require MIME::Base64;")
55
$ret = "MIME::Base64 not found";
57
if (! eval "require Net::hostent;")
59
$ret = "Net::hostent not found";
62
$squid_host = $ENV{squidhost} || "localhost";
63
$squid_port = $ENV{squidport} || 3128;
64
$user = $ENV{squiduser} || "";
65
$passwd = $ENV{squidpasswd} || "";
67
if($ARGV[0] and $ARGV[0] eq "autoconf") {
68
&autoconf($squid_host, $squid_port, $user, $passwd);
72
my ($host, $port, $user, $passwd) = @_;
80
my $cachemgr = IO::Socket::INET->new(PeerAddr => $host,
86
print "no (could not connect: $!)\n";
90
my $request = "GET cache_object://$host/counters HTTP/1.0\r\n" .
92
&make_auth_header($user, $passwd) .
95
$cachemgr->syswrite($request, length($request));
96
my @lines = $cachemgr->getlines();
102
sub make_auth_header {
103
my ($user, $passwd) = @_;
105
if(!defined $passwd || $passwd eq "") {
108
my $auth = MIME::Base64::encode_base64(($user ? $user : "") . ":$passwd", "");
109
return "Authorization: Basic $auth\r\n" .
110
"Proxy-Authorization: Basic $auth\r\n";
116
my ($host, $port, $user, $passwd) = @_;
119
my $cachemgr = IO::Socket::INET->new(PeerAddr => $host,
121
Proto => 'tcp') or die($!);
125
my $request = "GET cache_object://$host/server_list HTTP/1.0\r\n" .
127
&make_auth_header($user, $passwd) .
130
$cachemgr->syswrite($request, length($request));
131
my @lines = $cachemgr->getlines();
133
for(my $i = 0; $i <= $#lines; $i++) {
135
if($lines[$i] =~ /Address[^:]+:\s*([\d\.]+)\s*$/) {
141
if ($h = Net::hostent::gethost ($host)) {
142
$ret->{$id}->{host} = lc $h->name;
144
$ret->{$id}->{host} = $host;
147
elsif($lines[$i] =~ /FETCHES\s*:\s*(\d+)/) {
148
$ret->{$id}->{fetches} = $1;
154
my $hosts = &query_squid($squid_host, $squid_port, $user, $passwd);
156
if($ARGV[0] and $ARGV[0] eq "config") {
158
print "graph_title Squid relay statistics\n";
159
print "graph_vlabel requests / min\n";
160
print "graph_args -l 0 --base 1000\n";
161
print "graph_total total\n";
162
foreach my $i (sort keys %{$hosts}) {
163
print "$i.label ", $hosts->{$i}->{host}, "\n";
164
print "$i.cdef $i,60,*\n";
165
print "$i.type DERIVE\n";
168
print "$i.draw AREA\n";
171
print "$i.draw STACK\n";
177
foreach my $i (keys %{$hosts}) {
178
print "$i.value ", $hosts->{$i}->{fetches}, "\n";