|
1 #!@l_prefix@/bin/perl |
|
2 ## |
|
3 ## webstats.pl: return HTTP server hits and bytes |
|
4 ## |
|
5 ## Configure Apache HTTP server like so: |
|
6 ## <Location /server-status> |
|
7 ## SetHandler server-status |
|
8 ## Order allow,deny |
|
9 ## Allow from localhost |
|
10 ## </Location> |
|
11 ## ExtendedStatus On |
|
12 ## |
|
13 |
|
14 @res = `@l_prefix@/bin/lynx -dump http://localhost/server-status`; |
|
15 |
|
16 foreach $res (@res) { |
|
17 if ($res =~ /Server uptime: (.*)$/) { |
|
18 $up = $1;last |
|
19 } |
|
20 else |
|
21 next |
|
22 |
|
23 if ($res =~ /Server at/) { |
|
24 $server = $res; |
|
25 last |
|
26 } |
|
27 else |
|
28 next |
|
29 } |
|
30 |
|
31 @res = `@l_prefix@/bin/lynx -dump http://localhost/server-status?auto`; |
|
32 |
|
33 foreach $res (@res) { |
|
34 if ($res =~ /Total Accesses: (\d+)/) { |
|
35 $d1 = $1; |
|
36 next |
|
37 } |
|
38 |
|
39 if ($res =~ /Total kBytes: (\d+)/) { |
|
40 $d2 = $1 * 1024; |
|
41 next |
|
42 } |
|
43 } |
|
44 |
|
45 $d1 = int($d1); |
|
46 $d2 = int($d2); |
|
47 |
|
48 if ($ARGV[0] eq "hits") { |
|
49 print "$d1\n"; |
|
50 print "$d1\n"; |
|
51 } elsif ($ARGV[0] eq "bytes") { |
|
52 print "$d2\n"; |
|
53 print "$d2\n"; |
|
54 } |
|
55 |
|
56 print "$up\n"; |
|
57 print "$server"; |
|
58 |