Debian Codegraph @

contrib/rumb-stat/getsquidstats

raw
1 #!/usr/bin/perl
2
3 #######################################################
4 # Get Web stats from Squid version 1.1.1 or higher
5 #######################################################
6 # Author: Anthony Rumble <[email protected]>
7 #
8 # Revision: $Revision: 1.1.1.1 $
9 #######################################################
10
11 use strict;
12 use Socket;
13
14 my ($request) = "cache_object://localhost/stats/utilization HTTP/1.0\n";# Request
15 my ($host) = "localhost"; # Host
16 my ($p) = 8080; # Port number
17
18 my ($j, $good, $junk, $sin, $port, $iaddr, $paddr, $proto, $line, $uptime, $bytes);
19
20 $proto = getprotobyname('tcp');
21 if (!$proto)
22 {
23 die("getsockbyname");
24 }
25 socket(S, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
26
27 $port = shift || $p;
28
29 $iaddr = gethostbyname($host);
30 if (!$iaddr)
31 {
32 die("gethostbyname");
33 }
34 $sin = sockaddr_in($port, $iaddr);
35 if (!$sin)
36 {
37 die("sockaddr_in");
38 }
39 connect(S, $sin) || die "connect: $!";
40
41 select(S);
42 $| = 1;
43 select(STDOUT);
44
45 print S "GET $request\n";
46
47 while (<S>)
48 {
49 ($junk, $b, $junk, $junk, $junk, $junk, $junk, $junk, $junk, $j) = split(' ');
50 if ($b eq "TOTAL")
51 {
52 ($good) = split('}', $j);
53 printf ("0\n%u\n1\nsquid\n", $good*1000);
54 exit(0);
55 }
56 }
57
58 close(S);