On Fri, Jul 23, 1999 at 10:56:15AM +0100, Patrick Kirk wrote:
> Hi all,
> 
> My ISP is wireless which means a 24/7 service which charges for usage over
> 600 Megs of days in and out in a month.  The connection is via an antenna
> and thence an rj45 cable into a NIC.
> 
> The NIC is eth1.  Is there a term for measuring data throughput on a NIC and
> how would I set about doing it?
> 

/proc/net/dev will give you the raw data in bytes. 
FWIW, I wrote a small program that tells you how
much data your NICs have transferred since your last reboot
I've attached it. It needs the python-base package.
Run it with the -h option to get an argument summary.
-- 
Stephen Pitts
[EMAIL PROTECTED]
webmaster - http://www.mschess.org
#!/usr/bin/env python
"""
NicInfo: display the number of bytes sent/received by your NICs
nicinfo -r PRECISION (-m | -g | -k) (INTERFACE)
        -m      show output in megabytes
        -g      show output in gigabytes
        -k      show output in kilobytes
        -r <int> specify decimal places to round to (default: 0)

If INTERFACE is not specified, shows stats for all devices
"""

from string import split, strip
import getopt
from sys import argv, exit

class NicInfo:
        def __init__(self, data_string):
                phase1 = split(data_string, ":");
                self.name = strip(phase1[0])
                phase2 = split(phase1[1])
                self.recvbytes = float(phase2[0])
                self.sentbytes = float(phase2[8])
try:
        dev_file = open("/proc/net/dev", "r")
except IOError:
        print "Can't open /proc/net/dev"
        exit(0)

dev_file.readline()
dev_file.readline()

real_data = dev_file.read()
nics = {}
for nic in split(real_data, "\n"):
        if nic == "": break
        nic_info = NicInfo(nic)
        nics[nic_info.name] = nic_info

try:
        args, show_nics = getopt.getopt(argv[1:], "gmkhr:")
except getopt.error:
        print "Invalid argument", __doc__
        exit(1)

if not show_nics: show_nics = nics.keys()

divisor = 1
identifier = "bytes"
prec = 0

if len(args) > 0:
        for thearg in args:
                if thearg[0] == "-m":
                        divisor = 1024 * 1024
                        identifier = "megabytes"
                elif thearg[0] == "-k":
                        divisor = 1024
                        identifier = "kilobytes"
                elif thearg[0] ==  "-g":
                        divisor = 1024 * 1024 * 1024
                        identifier = "gigabytes"
                elif thearg[0] == "-r":
                        prec = int(thearg[1])
                elif thearg[0] == "-h":
                        print __doc__
                        exit(0)

for nic in show_nics:
        try:
                nic_info = nics[nic]
        except KeyError:
                print "Can't find nic", nic
                continue
        nic_info.sentbytes = nic_info.sentbytes / divisor
        nic_info.recvbytes = nic_info.recvbytes / divisor
        print ("%s: sent %.*f %s; received %.*f %s" 
                % (     nic_info.name, prec, nic_info.sentbytes, identifier, 
                        prec, nic_info.recvbytes, identifier) )

Reply via email to