Article 171 of meer.list.mrtg:
Path: matra.meer.net!gateway
From: anthonyr@ce.com.au (Anthony Rumble)
Newsgroups: meer.list.mrtg
Subject: Some handy scripts
Date: 24 Feb 1997 00:38:45 -0000
Organization: meer.net
Lines: 128
Distribution: meer
Message-ID: <m0vyo6q-0002VtC@enterprise.ce.com.au>
NNTP-Posting-Host: matra.meer.net
Content-Type: text
Xref: matra.meer.net meer.list.mrtg:171


Heres some handy scripts to get byte stats from apache (web server) 1.1.1 
and better and squid (proxy server) 1.1.1 and better.

There may be a better way of doing it.. but it works

-- gethttpstats --
#!/usr/bin/perl

#######################################################
# Get Web stats from Apache 1.1.1 and better
#######################################################
# Author: Anthony Rumble <anthony@rumble.waratah.id.au>
#
# Revision: $Revision: 1.2 $
#######################################################

use strict;
use Socket;

my($request) = "/status/?auto";     # Request to send
my($host) = "enterprise.ce.com.au"; # Host to send it to
my($p) = 80;			    # Port no

my ($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 $request\n";
while (<S>) 
{
	$bytes=$1 if (m|^Total\ Bytes:\ (\S+)|);
	$uptime=$1 if (m|^Uptime:\ (\S+)|);
}
close(S);

print "0\n$bytes\n$uptime\nenterprise\n";
-- --

-- getsquidstats --
#!/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.3 $
#######################################################

use strict;
use Socket;

my ($request) = "cache_object://localhost/stats/utilization HTTP/1.0\n";# 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 $request\n";

while (<S>) 
{
	($junk, $b, $junk, $junk, $junk, $junk, $junk, $junk, $junk, $j)  = split(' ');
	if ($b eq "TOTAL")
	{
		($good) = split('}', $j);
		printf ("0\n%u\n1\nsquid\n", $good*1000);
		exit(0);
	}
}

close(S);
-- --

-- 
Anthony Rumble - Online Ordering Systems
Corporate Express Australia Limited
Phone 02-9335-0669 Fax 02-9335-0753 Mobile 015-955-042 Pager 016-634-997



