Commnad for getting bandwidth usage


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Commnad for getting bandwidth usage
# 1  
Old 01-13-2003
Commnad for getting bandwidth usage

Hi all
Wanted to know if there is a command that gives me the bandwidth used at any point of time (in mbps). I pay for the bandwidth I have used and need to be alerted everytime I corss over a certain limit.

Regards

KS
# 2  
Old 01-13-2003
the command ifconfig gives the amount of data passed through the interface in kb.
# 3  
Old 01-13-2003
Some other options (since you do not post what OS you are using)

netstat -i (should work with HP-UX, AIX, and Solaris)

Tools for Linux
# 4  
Old 01-13-2003
Here is a perl script that I wrote for crunching bandwidth via netstat. The script can be embedded in a infinite loop and easily modified to alert you when you go over xyz bandwidth.

This was coded under FreeBSD 4.5.

Code:
#!/usr/bin/perl

open(NETSTAT, "/usr/bin/netstat -I vr0 1|") || die "$!";

for ($lineCount = 1; $lineCount <= 3; $lineCount++) {
  $inputLine = <NETSTAT>;
  chomp($inputLine);
  if ($lineCount == 3) {
    $inputLine =~ s/\s+/-/g;
    my @column = split(/-/, $inputLine);
    $throughPut = ($column[6]*8)/1024;
    print "$throughPut\n";
  };
};

close(NETSTAT);

Testing ther perl script.

Code:
FreeBSD:auswipe:/home/auswipe $ /usr/local/netperf/netperf -H 10.0.0.1 -l 20 -P0 &
[1] 8255
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
62338.296875
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
86973.65625
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
89893.75
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
89491.59375
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
90169.5625
 16384  32768  32768    20.00      82.07
[1]+  Done                    /usr/local/netperf/netperf -H 10.0.0.1 -l 20 -P0
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
0
FreeBSD:auswipe:/home/auswipe $

# 5  
Old 01-15-2003
Try iptraf, is very good Smilie

Regards!
# 6  
Old 01-16-2003
Hello,

Can I use the same method to get the bandwidth usage in Solaris.

The netstat ( netstat -I interface seconds ) gives the packets traffic.

So, say if the packet at one point of time is 25,

to get traffic in terms of bytes,

( 1500 [ ie mtu ] * 25 ) / 8

I hope MTU is in units of bits.


Is this correct ?..


Thanks in advance...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

zsh and watch commnad

Hi Guys i have set the watch command on my shell watch=all but this will report when i open and close a shell, is there a way so that it will ignore me user but only when i am on my machine i can set it to watch=notme but that will not detect if someone su -<my... (0 Replies)
Discussion started by: ab52
0 Replies

2. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

3. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

4. Shell Programming and Scripting

how can we perform calculation on the ouput of the commnad

Hello I am very new to unix scripting. The below is the ouput of my one command, now i want to use the two below values 611 and 572 from the output of the command . in the ouput i want 39 which would be come by subtracting 572 to 611. please suggest how can we perform subtraction of... (6 Replies)
Discussion started by: singhald
6 Replies

5. Shell Programming and Scripting

how do i get current bandwidth usage via shell script?

hello unix-people. can u please tell me how i can get the current bandwidth usage of my machine on shell into variables? thanks a lot (2 Replies)
Discussion started by: scarfake
2 Replies

6. UNIX for Dummies Questions & Answers

User History and commnad log

Dear All I had a UNIX ( Sun solaris ) os. There are many user on that server. Now i want to find during last week who had log in to the sever and which commnad are executed by them? I also want to from which IP they had log in to the server. Is there any log file generated for user in... (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

7. UNIX for Dummies Questions & Answers

How to apply the awk commnad ?

Hi, I have a file and the contents of the file is say World World World Now i need to append some more words in each of the line and the the output of the file should like the one below Will India win the World Cup? Will India win the World Cup? Will India win the... (3 Replies)
Discussion started by: preethgideon
3 Replies

8. Shell Programming and Scripting

sorting file and unique commnad..

hello everyone.. I was wondering is there a effective way to sort file that contains colomns and numeric one. file 218900012192 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012979 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012992 8938929 8B8DF3664... (2 Replies)
Discussion started by: amon
2 Replies

9. Shell Programming and Scripting

grep commnad

echo "Enter a,: \c" read answer echo case "$answer" in a|A) echo "Enter a file :\c" read $answer echo " Enter a string to be searched :\c" read $answer2 if then echo " file doesn't exist" ... (5 Replies)
Discussion started by: props
5 Replies

10. Programming

How does commnad tail implement

How does commnad tail implement ? Thank you . (1 Reply)
Discussion started by: chenhao_no1
1 Replies
Login or Register to Ask a Question