Listing 3: Generate table by line number
#!/usr/local/bin/perl
#
# Listing 3 - Generates table by line number
#
require "ctime.pl";
sub timeconvert {
$hours = int($_[0] / 3600);
$minutes = int(( $_[0] % 3600 ) / 60);
$seconds = $_[0] - ($hours * 3600) - ($minutes * 60);
}
$firstline = "";
$tconnect = 0;
$MAXCON = 0;
$i = 0;
$today = &ctime(time);
open(ULOG, "@ARGV")
|| die "Can't open log file : $!\n";
while ($logrec = <ULOG>) {
( $i1, $i2, $i3, $i4, $i5, $i6 ) = split(/[ ]+/, $logrec);
$username[$i] = "$i1";
$linename[$i] = "$i2";
$month[$i] = $i3;
$day[$i] = $i4;
$connect[$i] = $i6 - $i5;
$tconnect += $connect[$i];
if ( $connect[$i] > $MAXCON ) {
$MAXCON = $connect[$i];
}
$i++;
}
printf "<HEAD><TITLE> RAS Utilization Report - \
'squid'</TITLE></HEAD>\n";
printf "<BODY>\n";
printf "<H1>RAS Utilization Report - Line Detail - 'squid'</H1>\n";
printf "<TABLE BORDER ALIGN=\"CENTER\" CELLSPACING=\"3\" \
CELLPADDING=\"8\">\n";
printf "<TH>Line Name</TH><TH>Connections</TH><TH>Total Connect
Time</TH><TH>Avg. Con. Time</TH><TH>Max. Con. Time</TH>\n";
$firstline = $linename[0];
$linecount = 1;
$LMAXCON = 0;
for ( $j = 0; $j < $i; $j++ ) {
if ("$linename[$j]" eq "$firstline") {
$jc++;
$jrt += $connect[$j];
if ( $connect[$j] > $LMAXCON ) {
$LMAXCON = $connect[$j];
}
}
else {
$linecount++;
&timeconvert($jrt);
if ( $jc < 2 ) {
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"green\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD> \
</FONT>",$firstline,$jc,$hours,$minutes,$seconds;
} else {
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD> \
</FONT>",$firstline,$jc,$hours,$minutes,$seconds;
}
if ( $jc > 1 ) {
&timeconvert($jrt/$jc);
printf "<TD>%03d:%02d:%02d</TD>",$hours, $minutes, $seconds;
&timeconvert($LMAXCON);
printf "<TD>%03d:%02d:%02d</TD>\n",$hours, $minutes, $seconds;
} else {
printf "\n";
}
$jc = 1;
$jrt = $connect[$j];
$firstline = $linename[$j];
$LMAXCON = 0;
if ( $connect[$j] > $LMAXCON ) {
$LMAXCON = $connect[$j];
}
}
}
&timeconvert($jrt);
if ( $jc < 2 ) {
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"green\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD></FONT>
",$firstline,$jc,$hours,$minutes,$seconds;
} else {
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-12s</TH><TD>%4d</TD><TD>%03d:%02d:%02d</TD></FONT>"
,$firstline,$jc,$hours,$minutes,$seconds;
}
if ( $jc > 1 ) {
&timeconvert($jrt/$jc);
printf "<TD>%03d:%02d:%02d</TD>",$hours, $minutes, $seconds;
&timeconvert($LMAXCON);
printf "<TD>%03d:%02d:%02d</TD>\n",$hours, $minutes, $seconds;
} else {
printf "\n";
}
printf "</TABLE>\n";
printf "<p>\n<p>\n";
printf "<TABLE BORDER ALIGN=\"CENTER\" CELLSPACING=\"3\" \
CELLPADDING=\"8\">\n";
printf "<TH>Summary Information</TH><TH><TH></TH>\n";
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%6d</TD></FONT>","Total Connections",$i;
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%6d</TD></FONT>","Number of Unique Lines",$linecount;
&timeconvert($tconnect);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%04d:%02d:%02d</TD></FONT>",
"Total Connect Time",$hours,$minutes,$seconds;
&timeconvert($MAXCON);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%03d:%02d:%02d</TD></FONT>",
"Maximum Connect Time",$hours,$minutes,$seconds;
&timeconvert($tconnect/$i);
printf "<TR ALIGN=\"RIGHT\"><TH><FONT COLOR=\"blue\ \
">%-18s</TH><TD>%02d:%02d:%02d</TD></FONT>",
"Average Connect Time",$hours,$minutes,$seconds;
printf "</TABLE>\n";
printf "<HR>\n";
printf "<P><!-- hhmts start -->Last modified: %s <!-- hhmts end -- \
></P>\n",$today;
printf "</BODY>\n";
# End of File
|