Subject: Re: network byte transfer stats
To: Jim Reid <jim@mpn.cp.philips.com>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: tech-kern
Date: 10/23/1997 08:43:15
Jim Reid wrote:
> 
> 
> >>>>> "Ross" == Ross Harvey <ross@teraflop.com> writes:
> 
>     Ross> Digital Unix keeps track of the byte counts transferred in
>     Ross> each direction on network interfaces. I can't find anyplace
>     Ross> in netbsd or any other system where this info is available.
> 
> The closest thing most (all?) UNIX systems will have to this is the
> per packet counts in the ifnet structure of each network interface.
> Some - like FreeBSD and BSDI - do keep byte counts as well, but I
         ^---  Don't our (NetBSD's) ibytes and obytes values in
	 an ifnet (actually, in the if_data of an ifnet) count?

> suppose you have to fish around in /dev/kmem to get them.
> 
>     Ross> My interest is in seeing the ultimate figure of merit:
>     Ross> bytes-transferred- per-second.  Of course, I'm mainly
>     Ross> interested in this as a percentage of wire speed.
> 
> If you want to do this, you shouldn't to rely on the counts kept by
> the kernel. The numbers may not be reliable - does a packet received
> by an interface and then thrown away because of no mbufs count as a
> packet in? - and you have to consider the quantum physics effect that
> observing something changes that something's behaviour. There is a PD
> benchmarking package - tcpstat? - which you can use to get the sort of
> numbers that interest you.

<Begin shameless plug>

  If you are _not_ interested in exact values, and want a
_graphical_ display of instantaneous and decaying-average (like
``load'') values, you could look at the xosview program
(http://lore.ece.utexas.edu/~bgrayson/xosview.html), which
graphically displays statistics about many aspects of the system
(load, CPU usage, mem, swap, net, and disk usage).  

  For the netmeter, it grovels through the kernel's ifnet
structures, adding up the ibytes and obytes and draws the cute
little netmeter (you'll have to see it to completely
understand).  If you set the network bandwidth to be the actual
max for your interface, then the meterbar will show percent
utilization graphically.  The text value printed next to the
meter is traffic (in+out) normalized to bytes per second, and
the meter can be customized (via X resources) to update as
frequently as 10 times per second.  And if you want the text
value to be percent bandwidth instead of absolute, just use:
xosview -xrm 'xosview*netUsedFormat: percent'

<end shameless plug>

  However, if you are concerned about the above inaccuracies,
xosview won't do the trick.  :(  At least not unless you UTSL
and add those extra checks!  For my uses, simply adding up all
the ins and outs is Good Enough.

  Brian
-- 
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.