This file is indexed.

/usr/share/munin/plugins/squid_requests is in munin-node 1.4.6-3ubuntu3.4.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/perl -w
# -*- perl -*-

=head1 NAME

squid_requests - Plugin to monitor squid requests.

=head1 CONFIGURATION

Configuration variables:

 squidhost   - host (default "localhost")
 squidport   - port (default "3128")
 squiduser   - username (default "")
 squidpasswd - password (default "")

=head1 AUTHOR

Copyright (C) 2004 Jimmy Olsen, Audun Ytterdal, Tore Anderson

=head1 LICENSE

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 dated June,
1991.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

my $ret = undef;

if (! eval "require IO::Socket;")
{
	$ret = "IO::Socket not found";
}
if (! eval "require MIME::Base64;")
{
	$ret = "MIME::Base64 not found";
}

$squid_host = $ENV{squidhost} || "localhost";
$squid_port = $ENV{squidport} || 3128;
$user = $ENV{squiduser} || "";
$passwd = $ENV{squidpasswd} || "";
$target = "client_http\.(requests|hits|errors)";

if($ARGV[0] and $ARGV[0] eq "autoconf") {
    &autoconf($squid_host, $squid_port, $user, $passwd);
}

sub autoconf {
    my ($host, $port, $user, $passwd) = @_;

    if ($ret)
    {
	    print "no ($ret)\n";
	    exit 0;
    }

    my $cachemgr = IO::Socket::INET->new(PeerAddr => $host,
					PeerPort => $port,
					Proto    => 'tcp',
					Timeout  => 5);

    if (!$cachemgr)
    {
	print "no (could not connect: $!)\n";
	exit 0;
    }

    my $request = "GET cache_object://$host/counters HTTP/1.0\r\n" .
	"Accept: */*\r\n" .
	&make_auth_header($user, $passwd) .
	"\r\n";
		  
    $cachemgr->syswrite($request, length($request));
    my @lines = $cachemgr->getlines();

    print "yes\n";
    exit 0;
}

sub make_auth_header {
    my ($user, $passwd) = @_;

    if(!defined $passwd || $passwd eq "") {
	return "";
    } else {
	my $auth = MIME::Base64::encode_base64(($user ? $user : "") . ":$passwd", "");
	return "Authorization: Basic $auth\r\n" .
	    "Proxy-Authorization: Basic $auth\r\n";
    }
}


sub query_squid {
    my ($host, $port, $user, $passwd) = @_;

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

    

    my $request = "GET cache_object://$host/counters HTTP/1.0\r\n" .
	"Accept: */*\r\n" .
	&make_auth_header($user, $passwd) .
	"\r\n";
		  
    $cachemgr->syswrite($request, length($request));
    my @lines = $cachemgr->getlines();
    for(my $i = 0; $i <= $#lines; $i++) {
	if($lines[$i] =~ /$target = (\d+)/) {
	    print "$1.value $2\n";
	}
    }
}

if($ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Squid client requests\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_vlabel requests / \${graph_period}\n";
    print "graph_order hits errors requests\n";
    print "graph_total total\n";
    print "graph_scale no\n";
    print "graph_category squid\n";
    print "hits.label hits\n";
    print "hits.type DERIVE\n";
    print "hits.draw AREA\n";
    print "hits.min 0\n";
    print "hits.max 500000\n";
    print "errors.label errors\n";
    print "errors.type DERIVE\n";
    print "errors.draw STACK\n";
    print "errors.min 0\n";
    print "errors.max 500000\n";
    print "requests.label misses\n";
    print "requests.cdef requests,hits,-,errors,-\n";
    print "requests.type DERIVE\n";
    print "requests.draw STACK\n";
    print "requests.min 0\n";
    print "requests.max 500000\n";
    exit 0;
}

&query_squid($squid_host, $squid_port, $user, $passwd, $target);



# vim:syntax=perl