Xref: utzoo comp.mail.uucp:6373 comp.lang.perl:4942 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!gatech!prism!mailer.cc.fsu.edu!uflorida!screamer!tscs!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.mail.uucp,comp.lang.perl Subject: Re: Log summaries Message-ID: <280B2BB2.243@tct.com> Date: 16 Apr 91 16:52:01 GMT References: Organization: Teltronics/TCT, Sarasota, FL Lines: 215 According to brendan@cs.widener.edu (Brendan Kehoe): >Has anybody written a program (Perl?) to parse UUCP log files, to >give an idea how much each UUCP connection's being used, and for how >long? Sure. This one, "uuconstat", is for HDB UUCP. Shar and enjoy. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'uuconstat' <<'END_OF_FILE' Xeval 'exec /bin/perl -S $0 ${1+"$@"}' X if 0; X X# $Id: uuconstat,v 1.3 90/10/23 10:29:08 chip Exp Locker: chip $ X# X# Print UUCP connect time statistics. X# X# $Log: uuconstat,v $ X# Revision 1.3 90/10/23 10:29:08 chip X# Don't count "wrong time" as a failure. X# X# Revision 1.2 90/09/28 11:05:53 chip X# Better function names and output format. X# X# Revision 1.1 90/06/01 12:23:36 chip X# Initial revision X# X X$LOGDIR = "/usr/spool/uucp/.Log/uucico"; X X$verbose = 0; X$debug = 0; Xwhile (@ARGV) { X $_ = $ARGV[0]; X last unless s/^-//; X shift; X last if $_ eq "-"; X $verbose = 1 if s/v//g; X $debug = 1 if s/d//g; X} X Xif (@ARGV == 0) { X opendir(LOG, $LOGDIR) || die "$LOGDIR: $!\n"; X @ARGV = grep($_ ne "." && $_ ne "..", sort readdir(LOG)); X closedir(LOG); X} X Xformat top = XUUCP Connect Time Statistics X XSystem Succ Fail Tot Time Avg Time X---------- ---- ---- -------- -------- X. X Xformat STDOUT = X@<<<<<<<<< @>>> @>>> @>>>>> @>>>>> X$system, $success, $failure, $fmt_time, $fmt_avgtime X. X Xformat SUMMARY = X---------- ---- ---- -------- -------- XTotals @>>> @>>> @>>>>> @>>>>> X $t_success, $t_failure, $fmt_time, $fmt_avgtime X. X Xforeach (@ARGV) { X $_ = $LOGDIR."/".$_ unless ($_ eq "-") || m#/#; X} X Xwhile (<>) { X chop; X next unless s/^\S+\s+(\S+)[^(]+\(/$1 \(/; X ($system, $dt, $what) = split(/\s+/, $_, 3); X $_ = $what; X X @DT = &DT($dt); X unless (@DT == 5) { X print STDERR "warning: bad date/time at ", $., X " in ", $system, "\n"; X next; X } X X $now = &CTIME(@DT); X if (!defined($first_time) || $now lt $first_time) { X $first_time = $now; X } X if (!defined($last_time) || $now gt $last_time) { X $last_time = $now; X } X X $SYSTEMS{$system} = 1; X if (/SUCCEEDED.*call to/) { X if (@START && $verbose) { X print STDERR "warning: unterminated call to ", X $start_system, " at ", &CTIME(@START), "\n"; X } X @START = @DT; X $start_system = $system; X } X elsif (/OK.*complete/ X || @START && (/CAUGHT.*sig/ || /INTREXIT/)) { X $call_began = &HMS_SECONDS(@START[2..4]); X $call_ended = &HMS_SECONDS(@DT[2..4]); X if ($call_ended < $call_began) { X $call_ended += &ONE_DAY; X } X X if ($debug) { X print STDERR &CTIME(@START), " to ", X &CTIME(@DT), " makes ", X ($call_ended - $call_began), X " seconds.\n"; X } X X $TIME{$system} += ($call_ended - $call_began); X ++$SUCCESS{$system}; X @START = (); X } X elsif (/WRONG TIME/) { X # do nothing X } X elsif (/CONN FAILED/ || /LOST LINE \(LOGIN\)/) { X ++$FAILURE{$system}; X } X} X Xforeach $system (sort keys(%SYSTEMS)) { X $time = $TIME{$system}; X $success = $SUCCESS{$system}; X $failure = $FAILURE{$system}; X X $fmt_time = &FMT_SECONDS($time); X $fmt_avgtime = $success ? &FMT_SECONDS($time / $success) : ""; X write; X X $t_success += $success; X $t_failure += $failure; X $t_time += $time; X} X Xif ($t_success || $t_failure) { X $fmt_time = &FMT_SECONDS($t_time); X $fmt_avgtime = $t_success ? &FMT_SECONDS($t_time / $t_success) : ""; X $~ = "SUMMARY"; X write; X} X Xif ($first_time && $last_time) { X print "\n"; X print "First attempt: $first_time\n"; X print "Last attempt: $last_time\n"; X} X Xexit; X Xsub DT { X local(@X); X @X = ($_[0] =~ m#^\((\d+)/(\d+)-(\d+):(\d+):(\d+),\d+,\d+\)#); X @X; X} X Xsub HMS_SECONDS { X ($hour, $minute, $second) = @_; X X return ($hour * 3600) + ($minute * 60) + $second; X} X Xsub ONE_DAY { X return 24 * 3600; X} X Xsub FMT_SECONDS { X local($i) = @_; X local($h, $m, $s); X X $s = $i % 60; X $i = int($i / 60); X $m = $i % 60; X $h = int($i / 60); X ++$m if $s >= 30; X return sprintf("%2d:%02d", $h, $m); X} X Xsub CTIME { X ($month, $day, $hour, $minute, $second) = @_; X X ++$minute if ($second >= 30); X sprintf("%02d/%02d %02d:%02d", $month, $day, $hour, $minute); X} END_OF_FILE if test 3648 -ne `wc -c <'uuconstat'`; then echo shar: \"'uuconstat'\" unpacked with wrong size! fi chmod +x 'uuconstat' # end of 'uuconstat' fi echo shar: End of shell archive. exit 0 -- Brand X Industries Custodial, Refurbishing and Containment Service: When You Never, Ever Want To See It Again [tm] Chip Salzenberg ,