#!/usr/bin/perl # diald.monthly - generate pretty stats for the last month # Written by Brian Edmonds Feb20/95 require 'getopts.pl'; &Getopts( 'p' ) || die "usage: $0 [-p]\n"; %daysOfWeek = ( 'Mon', 1, 'Tue', 2, 'Wed', 3, 'Thu', 4, 'Fri', 5, 'Sat', 6, 'Sun', 7 ); @monthsOfYear = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ); %monthsOfYear = ( 'Jan', 'January', 'Feb', 'February', 'Mar', 'March', 'Apr', 'April', 'May', 'May', 'Jun', 'June', 'Jul', 'July', 'Aug', 'August', 'Sep', 'September', 'Oct', 'October', 'Nov', 'November', 'Dec', 'December' ); @time = localtime( time - 3600*24 ); $month = $monthsOfYear[$time[4]]; $year = 1900 + $time[5]; $#timeByDayOfMonth = $#boutByDayOfMonth = $#binByDayOfMonth = 31; $#timeByDayOfWeek = $#boutByDayOfWeek = $#binByDayOfWeek = 7; $#timeByHourOfDay = $#boutByHourOfDay = $#binByHourOfDay = 23; $totalBytesOut = $totalBytesIn = $totalTime = 0; while( $log = ) { open( LOG, "<$log" ) || next; while( ) { if( /^(.*): Disconnected. Call duration (\d+) second/ ) { $timestamp = $1; $duration = $2; $timestamp =~ /^(\S+) $month (\d+) (\d+):\d+:\d+ \d+/ || next; ( $dayOfWeek = $daysOfWeek{$1} ) > 0 || next; $dayOfMonth = $2; $hourOfDay = $3; $timeByDayOfMonth[$dayOfMonth] += $duration; $timeByDayOfWeek[$dayOfWeek] += $duration; $timeByHourOfDay[$hourOfDay] += $duration; $totalTime += $duration; } elsif( /IP transmited (\d+) bytes and received (\d+) bytes/ ) { next unless $dayOfMonth > 0; $boutByDayOfMonth[$dayOfMonth] += $1; $boutByDayOfWeek[$dayOfWeek] += $1; $boutByHourOfDay[$hourOfDay] += $1; $totalBytesOut += $1; $binByDayOfMonth[$dayOfMonth] += $2; $binByDayOfWeek[$dayOfWeek] += $2; $binByHourOfDay[$hourOfDay] += $2; $totalBytesIn += $2; } else { $dayOfMonth = 0 } } close LOG; } if( defined $opt_p ) { open( STDOUT, "|/usr/local/bin/injnews" ) || die "Couldn't injnews!\n"; select( STDOUT ); $| = 1; print < $max1 ) { $max1 = $byDayOfMonth[$i] } } for( $max2=0, $i=0 ; $i<24 ; $i++ ) { if( $byHourOfDay[$i] > $max2 ) { $max2 = $byHourOfDay[$i] } } for( $max3=0, $i=1 ; $i<=7 ; $i++ ) { if( $byDayOfWeek[$i] > $max3 ) { $max3 = $byDayOfWeek[$i] } } for( $i=10 ; $i>0 ; $i-- ) { if( ! ( $i&1 ) ) { printf '%17.1f', $max1 * $i / 10 / $divisor; } else { print ' '; } print ' | '; for( $j=1 ; $j<=31 ; $j++ ) { print $max1*$i/10 <= $byDayOfMonth[$j] ? '#' : ' '; } print "\n"; } print <0 ; $i-- ) { if( ! ( $i&1 ) ) { printf '%8.1f', $max2 * $i / 10 / $divisor; } else { print ' '; } print ' | '; for( $j=0 ; $j<24 ; $j++ ) { print $max2*$i/10 <= $byHourOfDay[$j] ? '#' : ' '; } print ' '; if( ! ( $i&1 ) ) { printf '%14.1f', $max3 * $i / 10 / $divisor; } else { print ' '; } print ' | '; for( $j=1 ; $j<=7 ; $j++ ) { print $max3*$i/10 <= $byDayOfWeek[$j] ? '##' : ' '; } print "\n"; } print <