On Wed, Mar 01, 2017 at 04:33:57PM -0600, Richard Owlett wrote:
> Is there a tool which can be
>  "turned on"  at time t0
>  "turned off" at time t1
> which will report the number of
>   "uploaded"   bytes
>   "downloaded" bytes
> in that interval?

For your purposes, perhaps you pipe a standard interface
reporting tool into a text file that you can edit into
.cvs format for a spreadsheet. 

However, sometimes the easiest way to do stuff is to learn
a scripting language and automate a task.  The good thing
about scripting languages is that you can always look at
the program to remind yourself how it works.

A decade ago, I wrote a cheesy perl hack to wrap around
"ifconfig" to look at total bandwidth used, then modified
it a year ago to look at specific interface usage.  It is
very dependent on the behavior of /sbin/ifconfig for an
old distro, but it is easy to modify.  It would be even
easier if "standard" tool maintainers were more
intelligent and responsible and less "creative".

Keith


--------------------------------------------------
#!/usr/bin/perl
#  ifbr60 - average traffic rate for 60 seconds
#  depends on specific behavior of /sbin/ifconfig
#  V0.1.1  Keith Lofstrom   KLIC   2016 Jan 30

my $delay = 60 ;

use bigint ;  # the byte counts can be very large
my $ifc    ;  # interface name
my $encap  ;  # type of encapsulation
my $mac    ;  # mac (hardware) address
my $updn   ;  # interface up or down?
my $inet   ;  # ipv4 internet address
my $txrx   ;  # sum of transmit and receive bytes
my $err    ;  # sum of transmit and receive errors

my $ifcNum = scalar(@ARGV);
my @r, @t;

for my $pass (0..1) {
  my $ifcnt = -1 ;
  foreach my $port (@ARGV) {
    $ifcnt  += 1 ;  # start at 0
    open (IFOUT, "/sbin/ifconfig |" );
      while (<IFOUT>) {
        if( /(\w+)\s+Link encap:(\w+)/ ) {
           $ifc   = $1 ;
        } elsif( /inet addr:([\d\.]+)/ ) {
           $inet = $1 ;
        } elsif( /RX bytes:(\d+).+TX bytes:(\d+)/ ) {
           if( $port eq $ifc ) {
              printf "%4s%14s%16s.r%16s.t\n", $ifc,$inet,$1,$2 ;
              if( $pass == 0 ) {
                 $r[$ifcnt] = $1 ;
                 $t[$ifcnt] = $2 ;
              } else {
                 my $rd = ( $1 - $r[$ifcnt] ) / $delay ;
                 my $td = ( $2 - $t[$ifcnt] ) / $delay ;
                 printf "%4s%14s%15.3f/s %15.3f/s\n\n", $ifc,$inet,$rd,$td ;
              }
           }
        }
      } 
   }
   if( $pass == 0 ) {
      printf("\n");
      sleep $delay;
   }
} 
close IFOUT;


-- 
Keith Lofstrom          kei...@keithl.com
_______________________________________________
PLUG mailing list
PLUG@lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to