getsquidstats
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:1k
- #!/usr/bin/perl
- #######################################################
- # Get Web stats from Squid version 1.1.1 or higher
- #######################################################
- # Author: Anthony Rumble <anthony@rumble.waratah.id.au>
- #
- # Revision: $Revision: 1.1.1.1 $
- #######################################################
- use strict;
- use Socket;
- my ($request) = "cache_object://localhost/stats/utilization HTTP/1.0n";# Request
- my ($host) = "localhost"; # Host
- my ($p) = 8080; # Port number
- my ($j, $good, $junk, $sin, $port, $iaddr, $paddr, $proto, $line, $uptime, $bytes);
- $proto = getprotobyname('tcp');
- if (!$proto)
- {
- die("getsockbyname");
- }
- socket(S, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
- $port = shift || $p;
- $iaddr = gethostbyname($host);
- if (!$iaddr)
- {
- die("gethostbyname");
- }
- $sin = sockaddr_in($port, $iaddr);
- if (!$sin)
- {
- die("sockaddr_in");
- }
- connect(S, $sin) || die "connect: $!";
- select(S);
- $| = 1;
- select(STDOUT);
- print S "GET $requestn";
- while (<S>)
- {
- ($junk, $b, $junk, $junk, $junk, $junk, $junk, $junk, $junk, $j) = split(' ');
- if ($b eq "TOTAL")
- {
- ($good) = split('}', $j);
- printf ("0n%un1nsquidn", $good*1000);
- exit(0);
- }
- }
- close(S);