linux iperf 自动启动,linux iperf3 一键自动化测试脚本

jerpf iperf3 一键自动化测试脚本:

更新日期:2015年09月06日

联系邮箱:linux_lcl@163.com

个人博客首页:http://990487026.blog.51cto.com

================================================================

iperf3强大的带宽测试功能,其两个网络节点上安装iperf3即可完成测试,可以看到两个节点的上行速度,上行有效带宽,下行速度,下行有效带宽,带宽抖动,UDP丢包。配合使用ping,可以测试出延时,ping的丢包值。

speedtest不满足测试需求,放弃这种测试方式。

jprerf不满足画图需求,放弃这个画图工具。

准备:

1,已经安装iperf3 http://990487026.blog.51cto.com/10133282/1690460

2,已获取root权限  没有root权限的话请在命令行键入:sudo su 或 sudo -s

功能:

1,自动测试ping的数据: ping延时 与ping 丢包,30次

2,iperf3 自动测试TCP 上行带宽吞吐量,单位Kbits/sec

3,iperf3 自动测试TCP 下行带宽吞吐量,单位Kbits/sec

4,iperf3 自动测试UDP的丢包与抖动

5,自动判断iperf3 是否处于僵死状态,如果是,那么就杀了它,每隔600秒检查一次

6,自动判断是否得到了想到的数据值,如果没有得到,就会重试,直到得到数据为止

7,参数指定:

# $1 目标IP地址

# $2  脚本运行时长, 单位:秒

# $3 iperf3 -t 的参数

# $4 sleep 脚本每次运行,休息时长 单位: 秒

使用方法,如: 运行脚本测试baidu 执行时间999999秒 -t 参数为5  sleep 10秒

./iperf14.sh baidu.com 99999 5 10

8,运行脚本会生成.csv数据报表,可以用office软件中的excel直接查看数据,可以对采集到的数据画图。

0818b9ca8b590ca3270a3433284dd417.png

iperf3 一键自动化测试脚本 2015-0910更新

======   脚本开始 ============================================================

root@Debian:/home# cat iperf3_V16.sh

#!/bin/bash

# modify 2015.09.06 12:38

# up ,down Bandwidth unit is Kbits/sec

# $1 for ip address

# $2 .sh run time

# $3 iperf3 -t time

# $4 sleep seconds

# add ping_lost

# retry fun

# kill iperf sleep 5

# fix nan error

# add Supervision iperf3

# add judgement root

# fix File_Modify ==

# add Internet_IP

# sleep -t ==> ping -c

# default -p 12345

#### judgement root ######################################################################

root_id=`id -u`

if [ $root_id -ne 0 ] ; then

{

clear

echo -e "\033[40;37mWarning: you are not root user ! \n\n[Please use Command line ]$ sudo su \n\n \033[0m"

exit 10

}

fi

####### Get localhost IP & Initialization for iperf.csv############################3

clear

time4=`date +'%s'`

time5=$[time4+$2]

mkdir -p files

time1=`date "+%F-%H-%M"`

iperf="iperf3 -c $1 -t $3 -f k -p 12345"

ifconfig eth0 > files/tmp1

localIP=`sed -n "2p" files/tmp1|awk '{print $2}'|cut -d: -f2`

wget http://members.3322.org/dyndns/getip

Internet_IP=`cat getip`

rm -rf getip

echo "Localhost,Ethernet_IP,$localIP" >>  ./files/${time1}_iperf.csv

echo "Localhost,Internet_IP,$Internet_IP" >>  ./files/${time1}_iperf.csv

echo "Remote,$1" >> ./files/${time1}_iperf.csv

echo "Bandwidth Kbits/sec" >>  ./files/${time1}_iperf.csv

echo "" >>  ./files/${time1}_iperf.csv

echo "Date,Start_Time,End_time,Up_Sender,Up_Receiver,Down_Sender,Down_Receiver,Jitter/ms,Lost/Total,Ping_Latency/ms,Ping_Lost" >> ./files/${time1}_iperf.csv

##### Supervision iperf3 #############################################

while [ $time4 -le $time5 ]

do

sleep1=600

File_Modify1=`stat ./files/tmp1 | tail -n 2| head -n 1| awk '{print $3}'`

sleep $sleep1

File_Modify2=`stat ./files/tmp1 | tail -n 2| head -n 1| awk '{print $3}'`

if [ $File_Modify1 == $File_Modify2 ]

then

killall iperf3 >> /dev/null 2>&1

sleep 1

killall iperf3 >> /dev/null 2>&1

echo -e "`date`"

echo -e "\n\n\n\033[41;37m kill zombie iperf3 ..............\033[0m"

sleep 1

else

echo -e "\033[42;37m iperf3 Runing,Has not become zombie ,Every $sleep1 Seconds Check Once  .........\033[0m"

fi

time4=`date +'%s'`

done &

# Begin ##############################################

while [ $time4 -le $time5 ]

do

time2=`date "+%F"`            # Get current time

time3=`date "+%H:%M:%S"`

echo "##########################################################################"

echo -e "`date`"

echo "Get ping information .....ping -c 30 $1"

ping -c $4 $1 | tee ./files/tmp1

tail -2 files/tmp1 > ./files/tmp2

ping_Latency=`sed -n "2p" ./files/tmp2 | cut -d/ -f5`

ping_lost=`sed -n "1p" ./files/tmp2 | awk '{print $6}'`

echo -e "`date`"

echo -e "\033[43;31mping_delay:$ping_Latency ms \033[0m"

echo -e "\033[43;31mping_lost:$ping_lost \033[0m"

echo "##########################################################################"

echo -e "\n\n`date`"

echo "Get upload information........ $iperf "

$iperf | tee ./files/tmp1

grep "sender" files/tmp1

stat=`echo $?`

grep "iperf Done" files/tmp1

stat_done=`echo $?`

while ( [ $stat != 0 ] || [ $stat_done != 0 ] )

do

killall iperf3 >> /dev/null 2>&1

sleep 2

killall iperf3 >> /dev/null 2>&1

echo -e "`date`"

echo "Retry Get upload information........ $iperf  "

sleep 5

$iperf  | tee ./files/tmp1

grep "sender" files/tmp1

stat=`echo $?`

grep "iperf Done" files/tmp1

stat_done=`echo $?`

done

tail -4 ./files/tmp1 > ./files/tmp2

up_sender=`sed -n "1p" ./files/tmp2 | awk '{print $7}'`

up_receiver=`sed -n "2p" ./files/tmp2 | awk '{print $7}'`

echo -e "\033[43;31mup_sender: $up_sender Kbits/sec\033[0m"

echo -e "\033[43;31mup_receiver:$up_receiver Kbits/sec\033[0m"

echo "##########################################################################"

echo "Get download information........ $iperf -R  "

$iperf -R | tee ./files/tmp1

grep "sender" files/tmp1

stat=`echo $?`

grep "iperf Done" files/tmp1

stat_done=`echo $?`

while ( [ $stat != 0 ] || [ $stat_done != 0 ] )

do

killall iperf3 >> /dev/null 2>&1

sleep 2

killall iperf3 >> /dev/null 2>&1

echo -e "`date`"

echo "Retry Get download information........ $iperf -R  "

sleep 5

$iperf -R | tee ./files/tmp1

grep "sender" files/tmp1

stat=`echo $?`

grep "iperf Done" files/tmp1

stat_done=`echo $?`

done

tail -4 ./files/tmp1 > ./files/tmp2

down_sender=`sed -n "1p" ./files/tmp2 | awk '{print $7}'`

down_receiver=`sed -n "2p" ./files/tmp2 | awk '{print $7}'`

echo -e "\033[43;31mdown_sender:$down_sender Kbits/sec\033[0m"

echo -e "\033[43;31mdown_receiver:$down_receiver Kbits/sec\033[0m"

echo "##########################################################################"

echo -e "Get UDP information...... $iperf -u -l 1400 "

$iperf -u -l 1400  | tee ./files/tmp1

grep "Sent" ./files/tmp1

stat=`echo $?`

grep "nan" files/tmp1

stat2=`echo $?`

grep "iperf Done" files/tmp1

stat3=`echo $?`

if [ $stat -eq 0 ]

then

if [ $stat2 -eq 0 -o $stat3 -ne 0 ]

then

stat=1

fi

fi

while [[ $stat != 0 ]]

do

killall iperf3 >> /dev/null 2>&1

sleep 1

killall iperf3 >> /dev/null 2>&1

echo -e "`date`"

echo "Retry Get UDP information........  $iperf -u -l 1450 "

sleep 1

$iperf -u -l 1400  | tee ./files/tmp1

grep "Sent" ./files/tmp1

stat=`echo $?`

grep "nan" files/tmp1

stat2=`echo $?`

grep "iperf Done" files/tmp1

stat3=`echo $?`

if [ $stat -eq 0 ]

then

if [ $stat2 -eq 0 -o $stat3 -ne 0 ]

then

stat=1

fi

fi

done

tail -4 ./files/tmp1 > ./files/tmp2

Jitter=`sed -n "1p" ./files/tmp2 | awk '{print $9}'`

sed -n "1p" ./files/tmp2  |awk '{print $12}'>./files/tmp1

sed -i "s#(##g" ./files/tmp1

sed -i "s#)##g" ./files/tmp1

Lost=`cat ./files/tmp1`

echo -e "\033[43;31mJitter : $Jitter\033[0m"

echo -e "\033[43;31mLost: $Lost \033[0m"

echo "#########################################################################"

time_end=`date "+%H:%M:%S"`

echo -e "\033[45;37mlocal  IP is $localIP \033[0m"

echo -e "\033[45;37mremote Ip is $1 \033[0m"

echo "$time2,$time3,$time_end,$up_sender,$up_receiver,$down_sender,$down_receiver,$Jitter,$Lost,$ping_Latency,$ping_lost " >> ./files/${time1}_iperf.csv

echo -e "\033[45;37mrecoder file save as  ./files/${time1}_iperf.csv \033[0m"

#    echo -e "sleep  $4 seconds #####################################################\n\n\n\n"

#    sleep $4

time4=`date +'%s'`

done

rm -rf ./files/tmp1

rm -rf ./files/tmp2

clear

echo -e "\033[31m*******************************************************************\033[0m"

echo -e "Information Collection Complete !                        "

date

echo -e "recoder file save as  ./files/${time1}_iperf.csv                 "

echo -e "\033[31m*******************************************************************\033[0m"

====== 脚本结束 ======================================================

.

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值