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
   | #!/usr/bin/perl
use strict; use warnings;
use LWP::Simple;
 
# depends on availability of status and extended status info from your
# Apache webserver -- your httpd.conf needs to include something like the
# following: (uncommented)
#<Location /server-status>
#    SetHandler server-status
#    Order allow,deny
#    Allow from localhost
#</Location>
#ExtendedStatus On
 
# can return hits or bytes (counters)
my $output = shift;
 
my @status = split/\n/, get('http://localhost:80/server-status');
 
 
my ($uptime, $server);
 
STATUSLOOP :
for my $line (@status) {
  if ($line =~ m/Server uptime: (.*)$/) { $uptime = $1; last STATUSLOOP }
  elsif ($line =~ m/Server at/) { $server = $line; last STATUSLOOP }
}
 
@status = split /\n/, get('http://localhost:80/server-status?auto');
 
my ($access_count, $bytes_sent);
 
for my $line (@status) {
  if ($line =~ m/Total Accesses: (\d+)/) { $access_count = $1 }
  elsif ($line =~ m/Total kBytes: (\d+)/) { $bytes_sent = $1 * 1024 }
}
 
 
if ($output eq "hits") {
  print "$access_count\n" for (1..2);
}
elsif ($output eq "bytes") {
  print "$bytes_sent\n" for (1..2);
}
 
print "$uptime\n";
print "$server";
 
__END__ |