Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Dec 1995 23:44:30 -0600
From:      Rich Murphey <rich@lamprey.utmb.edu>
To:        joed@engg.ksu.edu
Cc:        hackers@freebsd.org
Subject:   Re: Logging length of PPP connections...
Message-ID:  <199512150544.XAA29950@id.slip.bcm.tmc.edu>
In-Reply-To: <199512132345.RAA07713@gandalf.me.ksu.edu> (message from Joe Diehl on Wed, 13 Dec 1995 17:45:52 -0600 (CST))

next in thread | previous in thread | raw e-mail | index | archive | help
|From: Joe Diehl <joed@engg.ksu.edu>
|Date: Wed, 13 Dec 1995 17:45:52 -0600 (CST)
|
|I'm getting ready to sign up with a new Internet Service Provider, and
|was wondering if there was a way to find out how much my FreeBSD 2.1R
|machine is connected to my current ISP per month?
|
|I am running FreeBSD 2.1.0-Release, and the ppp program in dial-on-demand
|mode (note that I am not using pppd).  
|
|There is no way for me to get connection statistics from my current ISP.
|
|Thank you in advance.  :-)

If you are using 'ppp' (aka ijppp) for dial-on-demand use,
the perl script below produces the following:

- lists connections longer than some arbitrary threshold
- daily usage totals
- monthly averages
- histogram of usage for each hour of the day

Just feed /var/log/ppp.log as standard input to the script.

Rich


================================================================
./report.perl  </var/log/ppp.log

PPP log report

start             stop           hours
09-03 07:45:54 -> 09-03 10:46:28 3
09-03 20:36:19 -> 09-03 21:43:47 1.1
09-03				      total:   6.49 hrs 19 conn.
09-04 02:00:49 -> 09-04 08:24:33 6.4
09-04 14:00:25 -> 09-04 17:18:06 3.3
09-04				      total:  10.82 hrs 12 conn.
...
Statistics for month 09:
727 connections of      33.36 min average duration.
    404.15 hours total at      13.47 hours per day.
     24.23 connections per day for 30 days.
...

Statistics for connections started on a given hour of the day:

Hour	# Conn	min.	min/conn	% of total min.
0	11	188	17		0
1	15	289	19		0
2	58	8683	149		19
3	32	2977	93		6
4	6	35	5		0
5	5	47	9		0
6	3	125	41		0
7	25	5408	216		12
8	32	630	19		1
9	53	2831	53		6
10	34	1786	52		4
11	31	829	26		1
12	26	894	34		2
13	31	1160	37		2
14	32	2438	76		5
15	31	2858	92		6
16	29	2359	81		5
17	33	2646	80		6
18	29	1645	56		3
19	5	79	15		0
20	1	67	67		0
21	5	2131	426		4
22	11	311	28		0
23	44	3075	69		7

During off peak hours 0-7: 295.94 total hours (40%) in 155 conn.
During on peak hours 7-23: 429.11 total hours (59%) in 427 conn.

================================================================

#!/usr/bin/perl
$time_threshold = 60; # connections longer than this (in min.) are listed.

print "PPP log report\n\n";
print "start             stop           hours\n";
$day = "";
$month = "";
$days = 0;
$day_total_time = 0;
$day_connections = 0;
$start = 0;
$month = "";
$month_cnt = 0;
$month_total_time = 0;
$month_days = 1;
$month_connections = 0;
$last_month_days = 1;

sub monthstat
{
  print "\n\n";
  print "Statistics for month $month:\n";
  printf ("$month_connections connections of %10.2f min average duration.\n", 
	  $month_total_time / $month_connections);
  printf ("%10.2f hours total at %10.2f hours per day.\n",
	 $month_total_time / 60., $month_total_time / (60. * $month_days));
  printf ("%10.2f connections per day for $month_days days.\n",
	  $month_connections / $month_days);
  print "\n\n";
}
sub getln
{
  $_ = <>;
  if ($_ =~ / (\d\d):(\d\d):(\d\d) /) {
    $hour = $1;
    $minute = $2;
    $second = $3;
  }
  if ($_ =~ /^(\d\d)-(\d\d) /) {
    if ($day ne $2) {
      if ($day ne "") {
	printf ("$month-$day				      total: %6.2f hrs $day_connections conn.\n", $day_total_time / 60.);
      }
      $day_total_time = 0;
      $day_connections = 0;
      $day = $2;
      $days ++;
      if ($month ne $1) {
	if ($month ne "") {
	  &monthstat;
	}
	$month_total_time = 0;
	$last_month_days = $month_days;
	$month_days = 1;
	$month_connections = 0;
	$month = $1;
	$months ++;
      } else {
	$month_days = $2;
      }
    }
  }
  $_;}
while (!eof (STDIN)) {
  &getln();
  if (m/Phase: Network/) {
    $connections ++;
    $month_connections ++;
    $start = $second + 60 * ($minute + $hour * 60);
    $start_day = $day;
    $start_month = $month;
    $start_hour = $hour;
    $start_minute = $minute;
    $_ =~ / (\d\d:\d\d:\d\d) /;
    $start_time = $1;
    next;
  } elsif (m/(Phase: Dead|PPP Started.)/) {
    if ($start == 0) {
      next;
    }
    $end = $second + 60 * ($minute + $hour * 60);
    $duration = ($end - $start) / 60.; # minutes
    if ($start_day < $day) {
      $duration += ($day - $start_day) * 60 * 24.;
    }
    if ($start_month < $month) {
      $duration += ($day + $last_month_days - $start_day) * 60 * 24.;
    }
    if ($duration < 0) {
      print "bad duration: $duration\n";
      $duration = 0;
    }
    $histogram[$start_hour] += $duration;
    $histogram_cnt[$start_hour] ++;
    $total_time += $duration;
    $day_total_time += $duration;
    $month_total_time += $duration;
    $day_connections ++;
    $month_connections ++;
    if ($duration > $time_threshold ) {
      printf("$start_month-$start_day $start_time -> $month-$day $hour:$minute:$second %.2g\n", $duration / 60.);
    }
    $start = 0;
    next;
  }
}
printf ("$month-$day				      total: %6.2g hrs %4g conn\n", $day_total_time / 60., $day_connections);
$last_month_days = 31.;
&monthstat;

$total_time /= 60.;
print "\nStatistics for connections started on a given hour of the day:\n";
print "\nHour	# Conn	min.	min/conn	% of total min.\n";
foreach $i (0..23) {
  if ($histogram_cnt[$i] > 0) {
    $avg = int ($histogram[$i] / $histogram_cnt[$i]);
  } else {
    $avg = 0;
  }
  $dur = int $histogram[$i];
  $cent = int (100. * ($histogram[$i] / 60) / $total_time);
  print "$i	$histogram_cnt[$i]	$dur	$avg		$cent\n";
}

$off_peak = 0;
$off_peak_cnt = 0;
foreach $i (0..7) {
  $off_peak += ($histogram[$i] / 60.);
  $off_peak_cnt += $histogram_cnt[$i];
}
$on_peak = 0;
$on_peak_cnt = 0;
foreach $i (8..23) {
  $on_peak += ($histogram[$i] / 60.);
  $on_peak_cnt += $histogram_cnt[$i];
}
print "\n";
printf ("During off peak hours 0-7: %6.2f total hours (%2d%%) in $off_peak_cnt conn.\n",
	$off_peak, 100. * $off_peak / $total_time);
printf ("During on peak hours 7-23: %6.2f total hours (%2d%%) in $on_peak_cnt conn.\n",
	$on_peak, 100. * $on_peak / $total_time);
print "\n";
exit 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512150544.XAA29950>