LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 10-31-2003, 04:41 PM   #1
doorbits
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Rep: Reputation: 0
one-liner to see current internet bandwidth usage


Hi, I'm looking for a one-liner (that is, please don't point me to a GUI monitoring utility like Gkrellm2 or Karamba) that prints out my current internet bandwidth usage.

I'm pretty sure this is possible. Using "cat" and that command line calculator and the /proc filesystem, somehow. I googled for a long time last night trying to find what file in /proc gievs me the current network usage, but I can't find it. I did a manual opening of most of the files, and I can't anything. This number is a combination of the upload speed and download speed, ie current internet bandwidth usage.

I know this is possible because I saw a site which had it's uptime and current internet bandwidth usage at the bottom of the page. I have read up on how /proc works also. I hope debian supports this.

I hope someone knows how to do this.

Thanks in advance!
 
Old 10-31-2003, 06:01 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
/proc/net/dev gives you cumulative statistics of how many packets transmitted and recieved.

If you want something more information, you have to watch the changes by yourself or use a toolbox like netdiag which does the things you probably want.
 
Old 10-31-2003, 06:56 PM   #3
doorbits
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by ToniT
/proc/net/dev gives you cumulative statistics of how many packets transmitted and recieved.

If you want something more information, you have to watch the changes by yourself or use a toolbox like netdiag which does the things you probably want.
I never said anything about packets, I said I was looking for current traffic speed.

Installed netdiag, none of the programs in it output to stdout, and a quick overview showed none that showed speed.
 
Old 10-31-2003, 09:58 PM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
toni@mario:~$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:489169465  742356    0    0    0     0          0         0 489169465  742356    0    0    0     0       0          0
  eth0:418515467 10567421    0    0    0     0          0         0 1610157716 8974064    0    0    0     0       0          0
There is also the byte count, you know.

except trafshow and statnet; both show the speed also.

If you want a oneliner:
Code:
perl -we 'sub getpkt { open DEV,"/proc/net/dev"; while(<DEV>) { if(/eth0/) { @line=split(/:|\s+/); close DEV; return $line[2]; }} close DEV; } my $pkts=getpkt(); sleep 5; print "Recieve rate is " .(getpkt()-$pkts)/5 . "\n";'
 
Old 11-01-2003, 12:58 AM   #5
doorbits
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by ToniT
[code]
except trafshow and statnet; both show the speed also.

If you want a oneliner:
Code:
perl -we 'sub getpkt { open DEV,"/proc/net/dev"; while(<DEV>) { if(/eth0/) { @line=split(/:|\s+/); close DEV; return $line[2]; }} close DEV; } my $pkts=getpkt(); sleep 5; print "Recieve rate is " .(getpkt()-$pkts)/5 . "\n";'
Yes, but at a quick glance I couldn't get either to output the total speed to stdout.

Thanks for this one liner, could you please update it so that it include the upload rate also, and thus shows the total speed? I wish I knew perl so I wouldn't have to ask.

Thanks! This one-liner is very complex!
 
Old 11-01-2003, 05:59 AM   #6
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
I had in mind to leave that as an exercise

But all right then:
  • Replace the word "$line[2];" with "$line[10]" to get the upload rate.
  • Replace the word "$line[2];" with "$line[2]+$line[10];" to get the whole throuhput
  • You might also want to change the printout to say something else than "Recieve rate is".
The numers here (2 and 10) refer to the fields in the contents of /proc/net/dev.
 
Old 11-01-2003, 03:10 PM   #7
doorbits
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by ToniT
I had in mind to leave that as an exercise

But all right then:
  • Replace the word "$line[2];" with "$line[10]" to get the upload rate.
  • Replace the word "$line[2];" with "$line[2]+$line[10];" to get the whole throuhput
  • You might also want to change the printout to say something else than "Recieve rate is".
The numers here (2 and 10) refer to the fields in the contents of /proc/net/dev.
Then add the /1024 to get it in k/sec....sweet! it works!

Thanks so much ToniT! I would have never figured this out by myself. I understand some parts of this line, thanks for pointing me to make the changes myself.
Code:
perl -we 'sub getpkt { open DEV,"/proc/net/dev"; while(<DEV> ) { if(/eth0/) { @line=split(/:|\s+/); close DEV; return $line[2]+$line[10]; }} close DEV; } my $pkts=getpkt(); sleep 5; print "Network usage " .((getpkt()-$pkts)/5)/1024 ; print " K/sec". "\n";'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding Bandwidth Usage RemusX2 General 2 07-16-2005 05:04 AM
How To Check Traffic Usage/Bandwidth pjbeal Linux - Newbie 4 12-14-2004 07:29 PM
total bandwidth usage chongluo Linux - General 9 09-26-2004 09:32 PM
bandwidth usage logger eltongeoff Linux - Software 6 09-09-2003 12:47 PM
How to find bandwidth available ... not usage? russell Linux - Networking 3 09-15-2001 01:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration