LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to calculate bandwidth on linux (https://www.linuxquestions.org/questions/linux-software-2/how-to-calculate-bandwidth-on-linux-344585/)

epsharma 07-19-2005 05:55 AM

How to calculate bandwidth on linux
 
I have installed cbq to throttle bandwidth . I didnt know how to gauze/calculate the bandwidth on linux

I could not trace the log of cbq and at the same time no idea how to account bandwidth for different ruleset of cbq

Any help in this regard will be appreciated,

Thanks,
epsharma

crep 07-20-2005 03:06 PM

OK check this out.

Everything in linux is logged, though usually we have no idea where. I'm sure somewhere in /proc/net there is a way to tell how many bits have gone in and out. But here's how I do it.

I assume here that you have snmpd installed and running, as well as net-snmp-tools. Type "ps -A|grep snmp" and "snmpwalk --help" to test this.

Start by typing this:

snmpwalk -v1 -cpublic <host> system

This should start spewing system info down your console. Each value is in the form:

sytem.thing1.thing2.thing3.etc = <whatever>

Look for something that looks like ifInOctets and ifOutOctets. Those are how many bytes have been passed in and out by the interface since last reboot (or last counter reset, but we don't need to get into that here.) Look at the path (ie the system.thing1.thing2 etc) for those values: I can't remember them offhand. Then, when you type:

snmpwalk -v1 -cpublic <host> system.path.to.those.values |grep Octets

You should see those two values.

NOW: if you want to know bandwidth at a particular interval, you obviously must take two snapshots of those values and divide the difference by the time between them: I'm not going to write how to script this here, but I've done it, it's not too hard.

OR: If you want to do this the easy way, there's a great tool called "IPTraf". You can install it by rpm or however you wish. Just become root, and type iptraf. It's got a pretty nice interface that tells you all about bandwidth stats and such.

Have fun.

mikedeatworld 07-20-2005 03:31 PM

www.nagios.com

denver1980 10-02-2005 05:51 PM

I maid a small bash script to use bwm-ng
Code:

Fic_Tmp="/tmp/Fic_Tmp_VerifRatio.tmp"
NbrSec=20
/usr/local/Bwm/bin/bwm-ng -I eth0 -o csv -T avg -C " " -c ${NbrSec} | awk '
BEGIN{
  BytesS=0
  NbrLecture=0}
/eth0/&&NR>2{
  BytesS+=$5/1024
  NbrLecture+=1}
END{
  Ratio=BytesS/NbrLecture
}
      printf ("%4.0f", Ratio)}' > ${Fic_Tmp}

Ratio=$(cat ${Fic_Tmp})
rm ${Fic_Tmp}

if [ "${Ratio}" -lt 110 ];then
  echo "BW OK - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
  exit 0
else
  echo "BW Surchargé - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
  exit 2
fi
exit $?

It checks my bw on local machine for 20 secs ...

paulchin 07-02-2006 10:45 AM

Quote:

Originally Posted by denver1980
I maid a small bash script to use bwm-ng
Code:

Fic_Tmp="/tmp/Fic_Tmp_VerifRatio.tmp"
NbrSec=20
/usr/local/Bwm/bin/bwm-ng -I eth0 -o csv -T avg -C " " -c ${NbrSec} | awk '
BEGIN{
  BytesS=0
  NbrLecture=0}
/eth0/&&NR>2{
  BytesS+=$5/1024
  NbrLecture+=1}
END{
  Ratio=BytesS/NbrLecture
}
      printf ("%4.0f", Ratio)}' > ${Fic_Tmp}

Ratio=$(cat ${Fic_Tmp})
rm ${Fic_Tmp}

if [ "${Ratio}" -lt 110 ];then
  echo "BW OK - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
  exit 0
else
  echo "BW Surchargé - Moyenne de ${Ratio} de Kb/sec pendant ${NbrSec} secondes"
  exit 2
fi
exit $?

It checks my bw on local machine for 20 secs ...

Hi, I get the following error:

awk: cmd. line:11: printf ("%4.0f", Ratio)}
awk: cmd. line:11: ^ syntax error
awk: cmd. line:11: printf ("%4.0f", Ratio)}
awk: cmd. line:11: ^ syntax error

Regards,
Paul


All times are GMT -5. The time now is 05:38 AM.