6 squid_icp - Plugin to graph traffic to the ICP peers
10 The following configuration variables are used by this plugin:
13 env.squidhost - host (default "localhost")
14 env.squidport - port (default "3128")
15 env.squiduser - username (default "")
16 env.squidpasswd - password (default "")
20 When using squid as a "load balancer" (of sorts), who gets the
25 Copyright (C) 2004 Jimmy Olsen
33 This program is free software; you can redistribute it and/or modify
34 it under the terms of the GNU General Public License as published by
35 the Free Software Foundation; version 2 dated June, 1991.
37 This program is distributed in the hope that it will be useful, but
38 WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 General Public License for more details.
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
52 #%# capabilities=autoconf
58 if (! eval "require IO::Socket;")
60 $ret = "IO::Socket not found";
62 if (! eval "require MIME::Base64;")
64 $ret = "MIME::Base64 not found";
66 if (! eval "require Net::hostent;")
68 $ret = "Net::hostent not found";
71 $squid_host = $ENV{squidhost} || "localhost";
72 $squid_port = $ENV{squidport} || 3128;
73 $user = $ENV{squiduser} || "";
74 $passwd = $ENV{squidpasswd} || "";
76 if($ARGV[0] and $ARGV[0] eq "autoconf") {
77 &autoconf($squid_host, $squid_port, $user, $passwd);
81 my ($host, $port, $user, $passwd) = @_;
89 my $cachemgr = IO::Socket::INET->new(PeerAddr => $host,
96 print "no (could not connect: $!)\n";
100 my $request = "GET cache_object://$host/counters HTTP/1.0\r\n" .
102 &make_auth_header($user, $passwd) .
105 $cachemgr->syswrite($request, length($request));
106 my @lines = $cachemgr->getlines();
112 sub make_auth_header {
113 my ($user, $passwd) = @_;
115 if(!defined $passwd || $passwd eq "") {
118 my $auth = MIME::Base64::encode_base64(($user ? $user : "") . ":$passwd", "");
119 return "Authorization: Basic $auth\r\n" .
120 "Proxy-Authorization: Basic $auth\r\n";
126 my ($host, $port, $user, $passwd) = @_;
129 my $cachemgr = IO::Socket::INET->new(PeerAddr => $host,
131 Proto => 'tcp') or die($!);
135 my $request = "GET cache_object://$host/server_list HTTP/1.0\r\n" .
137 &make_auth_header($user, $passwd) .
140 $cachemgr->syswrite($request, length($request));
141 my @lines = $cachemgr->getlines();
143 for(my $i = 0; $i <= $#lines; $i++) {
145 if($lines[$i] =~ /Host[^:]+:\s*(\S+)\/\d+\/\d+\s*$/) {
150 unless(exists($ret->{$id})) {
151 $ret->{$id}->{host} = $host;
152 $ret->{$id}->{fetches} = 0;
155 elsif($lines[$i] =~ /FETCHES\s*:\s*(\d+)/) {
156 $ret->{$id}->{fetches} += $1;
162 my $hosts = &query_squid($squid_host, $squid_port, $user, $passwd);
164 if($ARGV[0] and $ARGV[0] eq "config") {
166 print "graph_title Squid relay statistics\n";
167 print "graph_vlabel requests / \${graph_period}\n";
168 print "graph_args -l 0 --base 1000\n";
169 print "graph_total total\n";
170 print "graph_category squid\n";
171 foreach my $i (sort keys %{$hosts}) {
172 print "$i.label ", $hosts->{$i}->{host}, "\n";
173 print "$i.type DERIVE\n";
174 print "$i.max 500000\n";
177 print "$i.draw AREA\n";
180 print "$i.draw STACK\n";
186 foreach my $i (keys %{$hosts}) {
187 print "$i.value ", $hosts->{$i}->{fetches}, "\n";