Debian Codegraph @

contrib/rumb-stat/gethttpstats

raw
1 #!/usr/bin/perl
2
3 #######################################################
4 # Get Web stats from Apache 1.1.1 and better
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) = "/status/?auto"; # Request to send
15 my($host) = "enterprise.ce.com.au"; # Host to send it to
16 my($p) = 80; # Port no
17
18 my ($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 while (<S>)
47 {
48 $bytes=$1 if (m|^Total\ Bytes:\ (\S+)|);
49 $uptime=$1 if (m|^Uptime:\ (\S+)|);
50 }
51 close(S);
52
53 print "0\n$bytes\n$uptime\nenterprise\n";