Debian This forum is for the discussion of Debian Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-31-2003, 04:41 PM
|
#1
|
LQ Newbie
Registered: Oct 2003
Posts: 18
Rep:
|
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!
|
|
|
10-31-2003, 06:01 PM
|
#2
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
/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.
|
|
|
10-31-2003, 06:56 PM
|
#3
|
LQ Newbie
Registered: Oct 2003
Posts: 18
Original Poster
Rep:
|
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.
|
|
|
10-31-2003, 09:58 PM
|
#4
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
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";'
|
|
|
11-01-2003, 12:58 AM
|
#5
|
LQ Newbie
Registered: Oct 2003
Posts: 18
Original Poster
Rep:
|
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!
|
|
|
11-01-2003, 05:59 AM
|
#6
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
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.
|
|
|
11-01-2003, 03:10 PM
|
#7
|
LQ Newbie
Registered: Oct 2003
Posts: 18
Original Poster
Rep:
|
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";'
|
|
|
All times are GMT -5. The time now is 09:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|