diff options
-rwxr-xr-x | awstatstotal | 111 |
1 files changed, 78 insertions, 33 deletions
diff --git a/awstatstotal b/awstatstotal index 0de9160..3474623 100755 --- a/awstatstotal +++ b/awstatstotal @@ -19,6 +19,7 @@ use File::Find; use LWP::Simple; use Net::Domain; use Number::Format; +use List::Util qw(max); use vars qw/ $PROGRESS_BAR_WIDTH @@ -26,12 +27,14 @@ use vars qw/ $max_count $max_bytes @sites + $hostfqdn /; -$PROGRESS_BAR_WIDTH = 300; +$PROGRESS_BAR_WIDTH = 200; $FORMAT = new Number::Format(); $max_count = 0; $max_bytes = 0; +$hostfqdn = $ENV{"FQDN"} || Net::Domain::hostfqdn; sub get_conf_string { my ($lines, $name) = @_; @@ -73,10 +76,10 @@ sub parse_site { close(DB); } - $max_count = $total_pages if $total_pages > $max_count; - $max_count = $total_hits if $total_hits > $max_count; - $max_bytes = $total_bandwidth if $total_bandwidth > $max_bytes; - push @sites, [Net::Domain::hostfqdn, $domain, $total_pages, $total_hits, $total_bandwidth]; + $max_count = max($max_count, $total_pages); + $max_count = max($max_count, $total_hits); + $max_bytes = max($max_bytes, $total_bandwidth); + push @sites, [$hostfqdn, $domain, $total_pages, $total_hits, $total_bandwidth]; } if (@ARGV < 2) { @@ -100,8 +103,8 @@ if ($cmd =~ /dump/i) { foreach my $dump (@ARGV) { my @dump; if ($dump =~ /^(http|ftp)/) { - @dump = LWP::Simple::get($dump); - } else { + @dump = split(/\n/, LWP::Simple::get($dump)); + } else { open(DUMP, $dump); @dump = <DUMP>; } @@ -117,44 +120,86 @@ foreach my $dump (@ARGV) { } print <<EOF; -<table width="80%" cellspacing="2" cellpadding="2" border="0"> - <tbody> +<head> + <title>Sugar Labs Servers Statistics</title> + <style type="text/css"> + * { + font-family: sans-serif; + font-size: 13px; + } + .hbar { + font-family: sans-serif; + font-size: 13px; + margin-top: 0px; + padding-top: 1px !important; + height: 22px; + padding-left: 2px; + } + .hr { border-top: 1px solid #c9f1d7; margin-bottom: 1em; } + hr { color: #c9f1d7; background-color: #c9f1d7; border-width: 1px; } + </style> +</head> +<body topmargin="3" marginheight="3"> + <div class="hbar"><nobr> + <a href="http://www.sugarlabs.org/"> Web</a> · + <a href="http://wiki.sugarlabs.org/"> Wiki</a> · + <a href="http://activities.sugarlabs.org/"> Activities</a> · + <a href="http://planet.sugarlabs.org/"> Blog</a> · + <a href="http://lists.sugarlabs.org/"> Lists</a> · + <a href="http://chat.sugarlabs.org/"> Chat</a> · + <a href="http://meeting.sugarlabs.org/"> Meeting</a> · + <a href="http://bugs.sugarlabs.org/"> Bugs</a> · + <a href="http://git.sugarlabs.org/"> Git</a> · + <a href="http://translate.sugarlabs.org/"> Translate</a> · + <a href="http://download.sugarlabs.org/"> Archive</a> · + <a href="http://people.sugarlabs.org/"> People</a> · + <a href="http://sugarlabs.org/go/Sugar_Labs/Donate"><b>Donate</b></a> + </nobr></div> + <div class="hr"></div> + <a href="http://sugarlabs.org"><img src="/icon/other/logo.png" border="0" /></a> + <table cellspacing="2" cellpadding="2" border="0" style="margin-left: auto; margin-right: auto;"> + <tbody> + <tr> + <th style="min-width: 200px"> </th> + <th style="font-weight: normal;" bgcolor="#4477DD" width="80">Pages</th> + <th style="font-weight: normal;" bgcolor="#66EEFF" width="80">Hits</th> + <th style="font-weight: normal;" bgcolor="#2EA495" width="80">Bandwidth</th> + <th> </th> + </tr> EOF -foreach (sort { $b->[4] <=> $a->[4] } @sites) { +foreach (sort { $b->[2] <=> $a->[2] } @sites) { my ($fqdn, $domain, $pages, $hits, $bandwidth) = @$_; - $pages_bar = int($PROGRESS_BAR_WIDTH * $pages / $max_count); - $hits_bar = int($PROGRESS_BAR_WIDTH * $hits / $max_count); - $bandwidth_bar = int($PROGRESS_BAR_WIDTH * $bandwidth / $max_bytes); + $pages_bar = max(2, int($PROGRESS_BAR_WIDTH * $pages / $max_count)); + $hits_bar = max(2, int($PROGRESS_BAR_WIDTH * $hits / $max_count)); + $bandwidth_bar = max(2, int($PROGRESS_BAR_WIDTH * $bandwidth / $max_bytes)); $pages = $FORMAT->format_number($pages); $hits = $FORMAT->format_number($hits); $bandwidth = $FORMAT->format_bytes($bandwidth); print <<EOF; - <tr> - <th> </th> - <th bgcolor="#4477DD" width="80">Pages</th> - <th bgcolor="#66EEFF" width="80">Hits</th> - <th bgcolor="#2EA495" width="80">Bandwidth</th> - <th> </th> - </tr> - <tr> - <td><a href="http://$fqdn/$domain">$domain</a></td> - <td>$pages</td> - <td>$hits</td> - <td>$bandwidth</td> - <td> - <img src="/icon/other/hp.png" alt="" title="" height="5" width="$pages_bar"><br> - <img src="/icon/other/hh.png" alt="" title="" height="5" width="$hits_bar"><br> - <img src="/icon/other/hk.png" alt="" title="" height="5" width="$bandwidth_bar"> - </td> - </tr> + <tr> + <td><a href="http://$fqdn/$domain">$domain</a></td> + <td style="text-align: right">$pages</td> + <td style="text-align: right">$hits</td> + <td style="text-align: right">$bandwidth</td> + <td> + <img src="/icon/other/hp.png" alt="" title="" height="5" width="$pages_bar"><br> + <img src="/icon/other/hh.png" alt="" title="" height="5" width="$hits_bar"><br> + <img src="/icon/other/hk.png" alt="" title="" height="5" width="$bandwidth_bar"> + </td> + </tr> EOF } print <<EOF; - </tbody> -</table> + </tbody> + </table> + <div style="float: right; padding: 10px;"> + <span>Powered by</span> + <a href="http://www.awstats.org/">AWStats</a> + </div> +</body> EOF |