1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mrtg/webstat.pl Sat Apr 04 22:28:28 2009 +0200 1.3 @@ -0,0 +1,58 @@ 1.4 +#!@l_prefix@/bin/perl 1.5 +## 1.6 +## webstats.pl: return HTTP server hits and bytes 1.7 +## 1.8 +## Configure Apache HTTP server like so: 1.9 +## <Location /server-status> 1.10 +## SetHandler server-status 1.11 +## Order allow,deny 1.12 +## Allow from localhost 1.13 +## </Location> 1.14 +## ExtendedStatus On 1.15 +## 1.16 + 1.17 +@res = `@l_prefix@/bin/lynx -dump http://localhost/server-status`; 1.18 + 1.19 +foreach $res (@res) { 1.20 + if ($res =~ /Server uptime: (.*)$/) { 1.21 + $up = $1;last 1.22 + } 1.23 + else 1.24 + next 1.25 + 1.26 + if ($res =~ /Server at/) { 1.27 + $server = $res; 1.28 + last 1.29 + } 1.30 + else 1.31 + next 1.32 +} 1.33 + 1.34 +@res = `@l_prefix@/bin/lynx -dump http://localhost/server-status?auto`; 1.35 + 1.36 +foreach $res (@res) { 1.37 + if ($res =~ /Total Accesses: (\d+)/) { 1.38 + $d1 = $1; 1.39 + next 1.40 + } 1.41 + 1.42 + if ($res =~ /Total kBytes: (\d+)/) { 1.43 + $d2 = $1 * 1024; 1.44 + next 1.45 + } 1.46 +} 1.47 + 1.48 +$d1 = int($d1); 1.49 +$d2 = int($d2); 1.50 + 1.51 +if ($ARGV[0] eq "hits") { 1.52 + print "$d1\n"; 1.53 + print "$d1\n"; 1.54 +} elsif ($ARGV[0] eq "bytes") { 1.55 + print "$d2\n"; 1.56 + print "$d2\n"; 1.57 +} 1.58 + 1.59 +print "$up\n"; 1.60 +print "$server"; 1.61 +