Monty
05-31-2005, 12:37 PM
it doesn't work correctly over the million hit per day point. It sure is handy, and a fix would be appreciated.
http://2coolfishing.com/screenshot4.jpg
#!/usr/local/bin/perl
# bandwidth.cgi
print <<HEADER;
Content-type: text/html
<HTML>
<HEAD><TITLE>Bandwidth usage</TITLE></HEAD>
<BODY>
<PRE>
HEADER
print "Bandwidth used:\n";
$directory = $ENV{"DOCUMENT_ROOT"};
open (BW, "$directory/stats/www-stats.hist");
while (<BW>) {
chomp;
if (substr($_,0,3) eq "DAY") {
@fields = split(/[ ]+/);
printf "Day: %6s %4.4f MB / %4.4f GB\n", $fields[1], $fields[7]/1048576, $fields[7]/1073741824;
$monthly_total += $fields[7];
}
if (substr($_,0,3) eq "MON") {
@fields = split(/\s+/); #RICH'S MOD HERE
#@fields = split(/[ ]+/);
printf "Month: %10s %4.4f GB\n", $fields[1], $fields[7]/1073741824;
}
}
printf "Used so far this month: %4.4f GB\n", $monthly_total/1073741824;
print <<FOOTER;
</PRE>
</BODY>
</HTML>
FOOTER
http://2coolfishing.com/screenshot4.jpg
#!/usr/local/bin/perl
# bandwidth.cgi
print <<HEADER;
Content-type: text/html
<HTML>
<HEAD><TITLE>Bandwidth usage</TITLE></HEAD>
<BODY>
<PRE>
HEADER
print "Bandwidth used:\n";
$directory = $ENV{"DOCUMENT_ROOT"};
open (BW, "$directory/stats/www-stats.hist");
while (<BW>) {
chomp;
if (substr($_,0,3) eq "DAY") {
@fields = split(/[ ]+/);
printf "Day: %6s %4.4f MB / %4.4f GB\n", $fields[1], $fields[7]/1048576, $fields[7]/1073741824;
$monthly_total += $fields[7];
}
if (substr($_,0,3) eq "MON") {
@fields = split(/\s+/); #RICH'S MOD HERE
#@fields = split(/[ ]+/);
printf "Month: %10s %4.4f GB\n", $fields[1], $fields[7]/1073741824;
}
}
printf "Used so far this month: %4.4f GB\n", $monthly_total/1073741824;
print <<FOOTER;
</PRE>
</BODY>
</HTML>
FOOTER