Amol1984
作者Amol1984·2019-09-09 16:25
系统工程师·YuSYS

请教一个网卡BOND问题与网络带宽计算问题

字数 5978阅读 1319评论 0赞 1

OS TYPE:SUSE 11 SP4 x86_64
PLATFORM:VMWARE-WORKSTATION 10.0.0 build-1295980
DISCRIPTION:

1.CONFIURE two simulated NETWORK CARDS with different MAC:
![](/home/attachment/201909/09/927883_156801672467726.png)
2.Have the two CARDs bonded:


HERE--Question1:Why the "bond0,eth1,eth3" have the same MAC?Since setted different MAC in STEP1...

3.Does the bonded eths configuration option "BOOTPROTO" must setted "none"?(The other option settings are "static" or "dhcp")Why?
![](/home/attachment/201909/09/927883_156801714228950.png)

4.At last,I share my written “network Card bandwidth usage calculator script”.And having the Question2——What is the traditional “Computational formulas” for the "network Card bandwidth usage"?

#!/bin/bash
#
#Instruction:This script calculate the rates of the network CARD usage(%) order by NETCARD NAME with the calculation internal of 3 seconds.
#Author:Teamol_gu
#Email:28105285@qq.com
#
#Uasage:check_netflow.sh p1 p2 p3
#Parameter instruction:
# p1-Network name,like eth0,eth1...;
# p2-The sleep time(mesured by second) during every mesuring processes;
# p3-Output file name.
#
#output INFO sample:
#system.net.card.bandwidth_pct|value=15%|type=gauge|tags=NetCart:bond1 
#system.net.card.bandwidth_pct|value=26%|type=gauge|tags=NetCart:bond0
#
#Modification recording:
#  20190909-Teamol_gu:Alter the script into "run once"mode by add "exit" in the loop.
#
#define the varibles used in the script
#NAME OF THE PHYTHIC NETWORK CARD-网卡名
#v_netinterface=$1
#CALCULATION INTERNAL TIME(MESUREMENT:SECOND)-采样间隔时间(单位:秒,规则:整数)
#v_sleeptime=$2
#OUTPUT FILENAME-输出文件名
#f_outfile=$3
f_outfile=${0}.log
#---VARIBLES OF TX-网卡输出变量
#TX:上个采样周期网卡字节数
v_tx_lastnetbytes=1
#TX:当前采样周期网卡字节数
v_tx_nownetbytes=1
#TX:周期内传输字节数(单位:Byte)
v_tx_data=1
#TX:网卡速率(单位:Byte/s)
v_tx_netrate=1
#---VARIBLES OF RX-网卡输入变量
#RX:上个采样周期网卡字节数
v_rx_lastnetbytes=1
#RX:当前采样周期网卡字节数
v_rx_nownetbytes=1
#RX:周期内传输字节数(单位:Byte)
v_rx_data=1
#RX:网卡速率(单位:Byte/s)
v_rx_netrate=1

function fun_netflowratecal(){
v_netinterface=$1
v_sleeptime=$2
f_outfile=$3
v_calculator=$4
#remind the Usage of the script
if [[ -z $1 || -z $2 || -z $3 ]];then
echo "#Uasage:check_netflow.sh p1 p2 p3"
echo "#Parameter instruction:"
echo "#  p1-Network name,like eth0,eth1...;"
echo "#  p2-The sleep time(mesured by second) during every mesuring processes;"
echo "#  p3-Output file name."
  echo "#  p4-a 1Gb/10Gb calculator"
  echo "#  p5-NetCard Speed Type"
  echo "Please run the script in the correct way..."
  exit
fi

#判断输入的网卡名是否对
t_tmp1=`/sbin/ifconfig -a|grep ${v_netinterface}|wc -l`
if [[ "${t_tmp1}" -gt "0" ]];then
echo `/sbin/ifconfig -a|grep ${v_netinterface}`
else
echo "Please enter the right Ethernet Card Name..."
exit
fi

#确认$3输入的输出文件名变量是否存在,并进行一次交互
if [ -f ${f_outfile} ];then
echo "${f_outfile}文件存在,任意键继续..."
read xx
else
echo "文件不存在,将创建,任意键继续..."
read xx
fi

#check the OS platform
PLATFORM=`/bin/uname`
case $PLATFORM in
AIX)
echo "The OS platform is AIX"
;;
Linux)
echo "The OS platform is Linux"
;;
SunOS)
echo "The OS platform is SunOS"
;;
HP-UX)
echo "The OS platform is HP-UX"
;;
OS/390|z/OS)
echo "The OS platform is OS/390|Z/OS"
;;
esac
#获取网卡输入输出字节数并计算输出至输出文件
echo "开始计算网卡${v_netinterface}输入输出速率[采样周期${v_sleeptime}秒/次]:"
v_tx_nownetbytes=`/bin/cat /proc/net/dev|grep "${v_netinterface}"|awk {'print $10'}`
v_rx_nownetbytes=`/bin/cat /proc/net/dev|grep "${v_netinterface}"|awk {'print $2'}`
echo "DEBUG20190909($1):v_tx_nownetbytes=$v_tx_nownetbytes,v_tx_lastnetbytes=$v_tx_lastnetbytes,v_rx_nownetbytes=$v_rx_nownetbytes,v_rx_lastnetbytes=$v_rx_lastnetbytes"

while true
do
  #STEPS:sleep interval
  sleep ${v_sleeptime}
  #STEPS:Read the TX data
  v_tx_lastnetbytes=${v_tx_nownetbytes}
  v_tx_nownetbytes=`/bin/cat /proc/net/dev|grep "${v_netinterface}"|awk {'print $10'}`
  v_tx_data=$(( ${v_tx_nownetbytes} - ${v_tx_lastnetbytes} ))
  v_tx_netrate=$(( ${v_tx_data} / ${v_sleeptime} ))
  #STEPS:Read the RX data
  v_rx_lastnetbytes=${v_rx_nownetbytes}
  v_rx_nownetbytes=`/bin/cat /proc/net/dev|grep "${v_netinterface}"|awk {'print $2'}`
  v_rx_data=$(( ${v_rx_nownetbytes} - ${v_rx_lastnetbytes} ))
  v_rx_netrate=$(( ${v_rx_data} / ${v_sleeptime} ))
  echo "DEBUG20190909($1):v_tx_nownetbytes=$v_tx_nownetbytes,v_tx_lastnetbytes=$v_tx_lastnetbytes,v_rx_nownetbytes=$v_rx_nownetbytes,v_rx_lastnetbytes=$v_rx_lastnetbytes"
  #STEPS:Calculate the TX rate
  tmp=`awk 'BEGIN{printf "%.4f%\\n",('$v_tx_netrate'/'$v_calculator')*100}'`
  #echo -e `date "+%Y-%m-%d %H:%M:%S"`":tx_data=${v_tx_nownetbytes}Bytes:""TX speed is:${v_tx_netrate}Bytes/s:TX rate is:${tmp}\\c">>${f_outfile} 

  #echo -e `date "+%Y-%m-%d %H:%M:%S"`"-system.net.card.bandwith_pct|value_TX=${tmp}\\c">>${f_outfile}
  echo -e "system.net.card.bandwith_pct|value_TX=${tmp}\\c">>${f_outfile}
  echo -e ".\\c"
  #STEPS:Calculate the RX rate
  tmp=`awk 'BEGIN{printf "%.4f%\\n",('$v_rx_netrate'/'$v_calculator')*100}'`
  #echo tmp=$tmp
  #echo ":rx_data=${v_rx_nownetbytes}Bytes:""RX speed is:${v_rx_netrate}Bytes/s:RX rate is:${tmp}">>${f_outfile}
  echo "|value_RX=${tmp}|type=$5|tags=NetCart:${v_netinterface}">>${f_outfile}
  #STEPS:do it once then exit
  exit
done
}

/sbin/ifconfig -a|grep -E "eth|bond"|awk {'print $1'}|while read a
do
  echo "============$a"
  tmp=`ethtool $a|grep "Speed"|awk {'print $2'}`
  if [ "${tmp}" == "1000Mb/s" ]
  then
  echo "INFO:netcard speed 1000Mb/s"
  #1 Gb=1024*1024*1024/8=134217728 Bytes
  fun_netflowratecal $a 3 ${0}.$a.log 134217728 1Gb &
  elif [ "${tmp}" == "10000Mb/s" ]
  then
  echo "INFO:netcard speed 10000Mb/s"
  #10 Gb=10*1024*1024*1024/8=1342177280 Bytes
  fun_netflowratecal $a 3 ${0}.$a.log 1342177280 10Gb &
  fi
done
#echo "Hello man,The main shell process is terminaled and exited now!!!You can kill the processes by CMD-kill -9 'ps -ef|grep cal_netrate20190906.sh|awk {'print $2'}',in order to terminaled the scripts running backgroup."

echo "INFO:This script will run once to calculate the netflow ration of every network card(Physical or Virtual)."

exit
exit

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关资料

X社区推广