0

I am trying to write in BASH my own tracking such as shown in the attachment.

enter image description here

Specially i need to track the Network History Recieving and Sending data. Where i can get those Network send/receive values, is it in a file or is that comes out from some commands in Linux?

Using BASH i am trying to implement something similar as below:

ex:

/* My 10 seconds timer */ 
t = new javax.swing.Timer(10000, new ActionListener() 
{
    public void actionPerformed(ActionEvent ae) 
    {
    }
}); 

Follow up: (good site: http://www.debianhelp.co.uk/networktools1.htm)

$ sudo apt-get install bwm-ng; 
yum -y install bwm; 

# Show me only plain mode 
$ bwm-ng -o plain

 bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 |         iface                    Rx                   Tx               Total
 ==============================================================================
              lo:       88803.53 KB/s        88803.53 KB/s        88803.53 KB/s
            eth0:           0.13 KB/s            0.13 KB/s            0.13 KB/s
 ------------------------------------------------------------------------------
           total:       88803.66 KB/s        88803.66 KB/s        88803.66 KB/s

# Show only the interface that i need to see
$ bwm-ng -o plain -I eth0

bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 |         iface                    Rx                   Tx               Total
 ==============================================================================
            eth0:           0.13 KB/s            0.13 KB/s            0.13 KB/s
 ------------------------------------------------------------------------------
           total:           0.13 KB/s            0.13 KB/s            0.13 KB/s

# Show only in MB format or KB format
# by skiping -d will default show as KB
$ bwm-ng -o plain -d

bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
 /proc/net/dev
 /         iface                    Rx                   Tx               Total
 ==============================================================================
              lo:          85.79 MB/s           85.79 MB/s           85.79 MB/s
            eth0:         246.58  B/s          246.58  B/s          246.58  B/s
 ------------------------------------------------------------------------------
           total:          85.79 MB/s           85.79 MB/s           85.79 MB/s

 $ bwm-ng -o plain -N -d | grep total:
      total:           0.00  B/s            0.00  B/s            0.00  B/s
      total:           1.28 MB/s            1.28 MB/s            1.28 MB/s
      total:           1.19 MB/s            1.19 MB/s            1.19 MB/s
      total:           1.19 MB/s            1.19 MB/s            1.19 MB/s


 # another tool i used apt-get install vnstat
 # bwm-ng was doing wrong strange on other interfaces but this one 
 # now showing correct
 $ vnstat -u -i lo 
 $ vnstat -u -i eth0
 $ vnstat 
 $ iftop -i eth0

2 Answers2

0

Yon can write your own script to parse :

  • top -b -n1 output for the CPU
  • free for the memory/swap
  • ifconfig eth0 for the network # replace eth0 by your device
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • ifconfig wlan0 never shows TX/RX as 0 bytes where i see here it shows 0 bytes whom do i trust system task manager or ifconfig? Am i then always sending and recieving bytes? e.g: See here: http://i.imgur.com/TY7hK.png –  Nov 09 '11 at 14:13
0

EDIT: the easy way: you could always use mrtg or cacti instead of doing it yourself.

otherwise... getting the bytes in and the bytes out, each 2 seconds (hit ctrl+c to make it stop):

default_device=$(awk ' { if ($2 == '00000000') print $1 ; } ' < /proc/net/route)
while true
do
    bytesin=$(grep $default_device /proc/net/dev | cut -d':' -f2 | awk ' { print $1; } ')
    bytesout=$(grep $default_device /proc/net/dev | cut -d':' -f2 | awk ' { print $9; } ')
    echo bytesin=$bytesin bytesout=$bytesout
    sleep 2
done

you'll get output like this:

bytesin=622734605 bytesout=1249429296
bytesin=622735091 bytesout=1249429620
bytesin=622735523 bytesout=1249430120
bytesin=622736268 bytesout=1249430481
bytesin=622736874 bytesout=1249430535

the values are obtained for the device where the default route is installed.

l0b0
  • 55,365
  • 30
  • 138
  • 223
user237419
  • 8,829
  • 4
  • 31
  • 38
  • You script is never showing 0 bytes. Where my System task manager as shown in screen shot. Shows sometimes 0 bytes. Who is true getting confused now? :) –  Nov 09 '11 at 14:07
  • 1
    those are counters, always incrementing; to get the transfer per second you need to compute it using adjacent values and the time window the values are read within – user237419 Nov 09 '11 at 14:13
  • Update my follow up above. bwm was also very helpfull. –  Nov 09 '11 at 20:57