Log summaries

Vince Skahan vince at bcsaic.UUCP
Sat Apr 20 06:55:46 AEST 1991


I've had a couple of requests for perl-versions of the HDB report
generator I posted the other day...

(there was a typo in the original awk one...there's an extra 
	"{" in there at the beginning of the awk...
	sorry 'bout that)

I've also included a sample data file to test on...

1. unshar this puppy
2. invoke by "sort < hdb-summ.dat | hdb-summ.pl"
3. let me know if you improve or drastically simplify this
4. enjoy...

					Vince

#!/bin/sh
# to extract, remove the header and type "sh filename"
if `test ! -s ./hdb_summ.pl`
then
cat > ./hdb_summ.pl << '\End\Of\Shar\'
#!/usr/local/bin/perl
#
# hdb_summ.pl
#
# this generates a report totalled on a system!user basis for HDB uucp
# (basically an edited a2p output of an old-awk original program)
#
# invoke by "sort < hdb-data-file | this_program.pl"
#
# ------------ sample data for incoming information ------------
#
#dsinc!uucp M (11/9-7:37:59) (C,701,1) [sio1] <- 475 / 5.933 secs, 80 bytes/sec
#
# ----------- sample data for outgoing information --------------
#
#dsinc!bcs212 M (11/9-8:02:16) (C,828,1) [sio1] -> 341 / 0.450 secs, 757 bytes/sec
#
#-------------------------------------------------------------------

# initialize NAME to nothing
$NAME = ' ';

# step through the data file
# outcoming data indicated by ->
# ingoing data indicated by <-
# find which system by /systemname/

# incoming

while (<>) {

    ($user,$Fld2,$start,$Fld4,$interface,$in_out,$bytes,$Fld8,$time) = split(' ', $_, 9999);

    #incoming
    if (/<-/) {
	$time_in = $time_in + $time;
	$bytes_in = $bytes_in + $bytes;
	$total_intime = $total_intime + $time;
	$total_inbytes = $total_inbytes + $bytes;
    }

    #outgoing
    if (/->/) {
	$time_out = $time_out + $time;
	$bytes_out = $bytes_out + $bytes;
	$total_outtime = $total_outtime + $time;
	$total_outbytes = $total_outbytes + $bytes;
    }

    if ($user ne $NAME) {
	if ($NAME ne ' ') {
		write;
	}
	$NAME = $user;
	$host_intime = 0;
	$host_inbytes = 0;
	$host_outtime = 0;
	$host_outbytes = 0;
	$host_time = 0;
	$host_bytes = 0;
	$host_inrate = 0;
	$host_outrate = 0;
	$host_pct_out = 0;
    }

    if ((($user eq $NAME) || ($user eq ' '))) {	
	if ($in_out eq '<-') {
	    $host_intime = $host_intime + $time;
	    $host_inbytes = $host_inbytes + $bytes;
	}
	else {
	    $host_outtime = $host_outtime + $time;
	    $host_outbytes = $host_outbytes + $bytes;
	}

	$host_time = $host_intime + $host_outtime;
	$host_bytes = $host_inbytes + $host_outbytes;

	if ($host_time > 0) {
	    $host_rate = $host_bytes / $host_time;
	}
	if ($host_intime > 0) {
	    $host_inrate = $host_inbytes / $host_intime;
	}
	if ($host_outtime > 0) {
	    $host_outrate = $host_outbytes / $host_outtime;
	}
	if ($host_bytes > 0) {
	    $host_pct_out = $host_outbytes * 100 / $host_bytes;
	}
    }
}

# summarize, print the last guy, and print the totals pretty

write;

$total_bytes = $total_inbytes + $total_outbytes;
$total_time = $total_intime + $total_outtime;

if ($total_time > 0) {
    $total_rate = $total_bytes / $total_time;
}
if ($total_intime > 0) {
    $total_inrate = $total_inbytes / $total_intime;
}
if ($total_outtime > 0) {
    $total_outrate = $total_outbytes / $total_outtime;
}

if ((($total_inbytes > 0) || ($total_outbytes > 0))) {
    $total_bytes = $total_inbytes + $total_outbytes;
    $total_time = $total_intime + $total_outtime;
    $total_pct_out = $total_outbytes * 100 / $total_bytes;

    $~ = "TOTALS";
    write;
}

format top =
                                  Summary of UUCP Statistics
                          Total              Incoming           Outgoing       Percent
                      Bytes  Bytes/sec   Bytes  Bytes/sec   Bytes  Bytes/sec   Outgoing
                      -----  ----------  ----   ---------   ----   ---------   --------
.

format =
@<<<<<<<<<<<        @>>>>>>>    @>>     @>>>>>>>   @>>   @>>>>>>>     @>>        @>>>
$NAME,           $host_bytes, $host_rate, $host_inbytes, $host_inrate, $host_outbytes, $host_outrate, $host_pct_out
.

format TOTALS =

                    @>>>>>>>    @>>     @>>>>>>>   @>>   @>>>>>>>     @>>        @>>>
                $total_bytes,$total_rate, $host_inbytes, $total_inrate, $total_outbytes,$total_outrate, $total_pct_out

.

\End\Of\Shar\
fi
if `test ! -s ./hdb_summ.dat`
then
cat > ./hdb_summ.dat << '\End\Of\Shar\'
system1!username M (12/5-17:06:02) (C,991,1) [tty000] <- 101292 / 462.083 secs, 219 bytes/sec
system1!username M (1/4-7:55:19) (C,1623,1) [tty000] -> 179 / 0.600 secs, 298 bytes/sec
system1!username M (1/4-8:24:53) (C,1670,1) [tty000] <- 21514 / 98.616 secs, 218 bytes/sec
system1!username M (1/4-8:29:42) (C,1679,1) [tty000] <- 18821 / 86.400 secs, 217 bytes/sec
system1!username M (1/4-8:32:38) (C,1689,1) [tty000] -> 189 / 0.650 secs, 290 bytes/sec
system1!username M (1/4-8:43:53) (C,1707,1) [tty000] <- 2341 / 11.066 secs, 211 bytes/sec
system3!username M (1/5-14:57:46) (C,2345,1) [tty000] <- 49824 / 247.333 secs, 201 bytes/sec
system1!username M (3/1-13:24:41) (C,526,1) [tty000] <- 112050 / 510.983 secs, 219 bytes/sec
system1!username M (3/2-1:05:48) (C,913,1) [tty000] <- 21514 / 22.800 secs, 943 bytes/sec
system2!username M (3/31-4:24:13) (C,2683,1) [tty000] <- 10343 / 47.683 secs, 216 bytes/sec
system2!username M (4/13-5:30:16) (C,7613,1) [tty000] <- 705099 / 3215.050 secs, 219 bytes/sec
\End\Of\Shar\
fi
exit
-- 
                         Vince Skahan   
 vince at atc.boeing.com                  ...uw-beaver!bcsaic!vince

(ensure your child's future... fire and prosecute striking teachers !)



More information about the Alt.sources mailing list