【1】测量两点之间的带宽 iperf
测试是否千兆:
服务端:iperf -s -u -p 22345 -i 1
客户端:iperf -c 10.10.2.58 -p 22345 -i 1 -t 60 -b 1000M -u
【2】net_stat.sh
#!/bin/bash
deviation=0
if_name=$1
rx_bit=
tx_bit=
[[ -z "$if_name" ]] && {
echo "usage: $0 [if_name]"
exit -1
}
function deviation_calc() {
local sum=0
local dev_value
for i in {1..20}; do
dev_value=0.000000001
curr_time=$(date +%s.%N)
dev_value=$(awk 'BEGIN{print "'$curr_time'"+1-"'$(date +%s.%N)'"-"'$dev_value'"}')
cost_time=$(date +%s.%N)
cost_time=$(awk 'BEGIN{print "'$cost_time'"-"'$curr_time'"}')
sum=$(awk 'BEGIN{print "'$sum'"+"'$cost_time'"}')
done
dev_value=$(awk 'BEGIN{print "'$sum'"/20}')
echo $dev_value
}
function net_usage_total() {
local dev=$1
local rx_tx
[[ -z "$dev" ]] && exit -1
rx_tx=($(awk '/^\s*'$dev':/{print $2,$10}' <<< "$(cat /proc/net/dev)"))
prev_rx_bit=$rx_bit
rx_bit=${rx_tx[0]}
prev_tx_bit=$tx_bit
tx_bit=${rx_tx[1]}
[[ -z "$prev_rx_bit" || -z "$prev_tx_bit" ]] && {
return
}
delta_rx=$(bc <<< "($rx_bit-$prev_rx_bit)*8/1024/1024")
delta_tx=$(bc <<< "($tx_bit-$prev_tx_bit)*8/1024/1024")
echo "dev=$dev RX: ${delta_rx}Mb TX: ${delta_tx}Mb"
}
deviation=$(deviation_calc)
echo "deviation: $deviation"
# 网络带宽统计
while true; do
curr_time=$(date +%s.%N)
net_usage_total $if_name
sleep $(awk 'BEGIN{print "'$curr_time'"+1-"'$(date +%s.%N)'"-"'$deviation'"}')
done
标签:网络工具,常用命令,value,cost,awk,dev,time,print,随笔
From: https://www.cnblogs.com/stellar-liyanbin/p/17768177.html