#!/usr/bin/perl -sw ## ## ppp-time-analysis -- looks at pppd messages in /var/log/messages ## and computes total connectivity time, ## number of connection attempts, number of ## successful sessions and telco cost (calculated ## on a per minute basis.) ## ## syntax: $0 [-month=month] ## ## Copyright (c) 1999, Vipul Ved Prakash. All rights reserved. ## This code is free software; you can redistribute it and/or modify ## it under the same terms as Perl itself. ## ## $Id$ $MESSAGES = '/var/log/messages' unless $MESSAGES; $MONTH = "" unless $MONTH; $COSTPERMIN = "0.40" unless $COSTPERMIN; @x = grep { /(Connect time|started by)/i } `cat $MESSAGES`; @x = grep { /$MONTH/i } @x; for ( @x ) { push @total, $1 if /Connect time\s([\d\.]+)\s/; $ATTEMPTS++ if /started by/; } for ( @total ) { $MINUTES += $_ } $SESSIONS = $#total; $HOURS = $MINUTES/60; $COST = $MINUTES * $COSTPERMIN; $MONTH = "All months." unless $MONTH; $~ = 'REPORT'; write(); format REPORT = ---------------------------------------------------------------------------- PPP/SLIP connectivity analysis ---------------------------------------------------------------------------- Raw message log file @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $MESSAGES Month @<<<<<<<<<< $MONTH Attempts @<<<<<< $ATTEMPTS Sessions @<<<<<< $SESSIONS Connectivity time in minutes @<<<<<< $MINUTES in hours @<<<<<< $HOURS Telco Cost @<<<<<<<< $COST ---------------------------------------------------------------------------- .