Skip to end of metadata
Go to start of metadata

netrate

Credit to the unknown original author of this script.

Labels:
  1. Aug 18, 2011

    Anonymous

    Nice script but i got an error wiht the \ at the end of some lines (121)..

    Therefor this is the script with those lines joined:

    cat bin/netrate.pl
    #!/usr/bin/python

    1. netrate - a program to "graphically" show on a linux console
    2. the transfer rate on each interface
    3. also tested on rxvt
    1. it will display the transfer rate for the last second (coming soon),
    2. and the transfer rate for the last SECONDS seconds.

    NUM_SAMPLES=5 # number of samples per second
    NUM_SECONDS=5 # number of seconds
    MIN_RATE=1024.0 # max_rate does not go below this value

    1. terminal settings
      TERM_HOME='\x1b[H'
      TERM_CLR_EOL='\x1b[K'
      TERM_CLR_SCREEN='\x1b[J'
      TERM_IN_COLOR='\x1b[41m' # red
      TERM_OUT_COLOR='\x1b[42m' # green
      TERM_NORMAL_COLOR='\x1b[m' # no attributes

    TERM_WIDTH=80

    from string import split
    from time import time,sleep
    from sys import stdin,stdout,argv,exit
    from getopt import getopt

    1. help
      def help():
      print "Usage:\n\t%s -h\n"%argv0
      print "\t%s -w width -s seconds -n num_samples\n"%argv0
      exit()
    1. main
      options,junk=getopt(argv1,"hw:s:n:")
      del junk
      for i in options:
      if(i0=='-h'):
      help()
      if(i0=='-w'):
      try:
      TERM_WIDTH=int(i1)
      except:
      help()
      if(i0=='-s'):
      try:
      NUM_SECONDS=int(i1)
      except:
      help()
      if(i0=='-n'):
      try:
      NUM_SAMPLES=int(i1)
      except:
      help()
      del options

    delay=1.0/NUM_SAMPLES

    statfile=open('/proc/net/dev','r')

    1. first get the current status...
      tmp=statfile.readlines()
      statfile.close()
      del statfile
      tmp=tmp2
      num_interfaces=len(tmp)
      interfaces=0,*num_interfaces
      initial_in=[]
      initial_out=[]
      max_rate=MIN_RATE

    for i in range(num_interfaces):
    interfacesi=split(tmpi6)0
    initial_in.append(float(tokens0))
    initial_out.append(float(tokens8))

    total=NUM_SAMPLES*NUM_SECONDS
    times=time()-1.0*total
    in_values=[]
    out_values=[]

    for i in range(total):
    in_values.append(initial_inNetRate*num_interfaces)
    out_values.append(initial_outNetRate*num_interfaces)

    del initial_in,initial_out

    current=0
    last=1

    1. print samples0101
    2. print interfaces
    1. I keep a circular buffer, so samplescurrent is the current sample, and
    2. sampleslast is the earliest sample, which will be overwritten next time

    stdout.write(TERM_HOME+TERM_CLR_SCREEN)

    while 1:
    statfile=open('/proc/net/dev')
    tmp=statfile.readlines()
    tmp=tmp2
    statfile.close()

    timescurrent=time()
    for i in range(num_interfaces):
    tokens=split(tmpi7)
    in_valuescurrenti=float(tokens0)
    out_valuescurrenti=float(tokens8)

    sleep(delay)
    stdout.write(TERM_HOME)

    stdout.write('Max Rate: %10.2f\n'%max_rate)
    for i in range(num_interfaces):
    time_diff=(timescurrent-timeslast) * 1024.0
    stdout.write('%-10s: in:%10.2f kb/sec out:%10.2f kb/sec' %(interfacesi, (in_valuescurrenti-in_valueslasti)/time_diff, (out_valuescurrenti-out_valueslasti)/time_diff))
    stdout.write(TERM_CLR_EOL+'\n')
    in_rate=(in_valuescurrenti-in_valueslasti)/time_diff
    out_rate=(out_valuescurrenti-out_valueslasti)/time_diff
    max_rate=max(in_rate,out_rate,max_rate)
    stdout.write(TERM_IN_COLOR+(' '*int(TERM_WIDTH*in_rate/max_rate)) TERM_NORMAL_COLOR+TERM_CLR_EOL'\n')
    stdout.write(TERM_OUT_COLOR+(' '*int(TERM_WIDTH*out_rate/max_rate)) TERM_NORMAL_COLOR+TERM_CLR_EOL'\n')
    stdout.flush()
    current=current+1
    last=last+1
    if(current==total):
    current=0
    max_rate=max(max_rate*0.90,MIN_RATE)
    else:
    if(last==total):
    last=0

  2. Sep 23, 2011

    Anonymous

  3. Sep 30, 2011

    Anonymous

    vvPLBt , [url=http://lohancezjgad.com/]lohancezjgad[/url], [link=http://obzaabulljha.com/]obzaabulljha[/link], http://cqnweoglxlxn.com/