Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1723038
  • 博文数量: 150
  • 博客积分: 660
  • 博客等级: 上士
  • 技术积分: 2480
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 11:39
文章分类

全部博文(150)

文章存档

2019年(4)

2018年(36)

2017年(53)

2016年(7)

2015年(3)

2014年(3)

2013年(27)

2012年(2)

2011年(1)

2006年(1)

2005年(13)

分类: 系统运维

2013-08-22 11:08:07

一、目的
     了解选定的BGP机房的网速
二、方法

     通过在选定的BGP机房内部http访问各省电信、移动、联通的门户网站,获得下载速度
三、说明

    传统的测试ping因为很多门户网站都禁止ping,所以修改http访问,这应该是第二个版本了。

四、脚本说明

1、crontab 定时脚本,每小时运行2次


20,50 * * * * /root/lihui/test.sh


2、 http 测试脚本 test.sh


#!/bin/bash


# Input file : serverlist.txt
# Output file : netspeed.txt
# Temp file :aaa
# Input file format : name(isp name,ct or cu) domain( domain name ,example )
# Output file format : name domain   date&time  speed size


while read  name domain 


   do 


   
   # wget domain for http speed
   /usr/bin/wget -t 3 -T 10 --delete-after  $domain  -o $name


   # get download size 


   size=`sed  -n '/saved/'p $name | sed  's/^.*saved//g' |sed  's/\[//g' | sed 's/\]//g' `


   # get speed 


   speed=`sed '/^$/d' $name |sed '/Removing/d' |sed -n '$p' | sed 's/^.*(//g' |sed 's/).*//g' `


   # recording speed data to Output file
   # for debuging
   echo $name $domain `date "+%F %T" `  $speed  $size
   echo $name  `date "+%F %T" `  $speed  $size >> /root/lihui/netspeed.txt
   echo -e "\n"
   #delete temp file 


   rm -fr $name


   done < /root/lihui/serverlist.txt
   
3、 test脚本用到的 serverlist.txt内容


beijing_ct
beijing_cu
shanghai_cu
shanghai_ct sh.ct10000.com
tianjin_cu
tianjin_ct tj.ct10000.com
zhejiang_ct zj.ct10000.com
zhejiang_cu
hebei_cu
hebei_ct
jiangsu_ct js.ct10000.com
jiangsu_cu
shanxi_cu(xa)
shanxi_ct(xa) sn.ct10000.com
guangdong_ct
guangdong_cu
henan_ct ha.ct10000.com
henan_cu
anhui_ct ah.ct10000.com
anhui_cu
liaoning_cu ln.10155.com
liaoning_ct
hubei_cu
hubei_ct hb.ct10000.com
shanxi_ct(ty) sx.ct10000.com
shanxi_cu(ty) speed.longcity.net 
hunan_cu
hunan_ct
shandong_ct sd.ct10000.com
shandong_cu
sichuan_cu
sichuan_ct sc.ct10000.com
jilin_ct jl.ct10000.com
jilin_cu
chongqing_cu cq.10155.com
chongqing_ct
heilongjiang_cu
yunan_cu
yunnan_ct yn.ct10000.com
guizhou_cu
guizhou_ct gz.ct10000.com
guangxi_cu
guangxi_ct
neimeng_cu nm.10155.com
neimeng_ct nm.ct10000.com
gansu_cu gs.10155.com
gansu_ct
xinjiang_cu
xinjiang_ct
qinghai_cu
qinghai_ct
xizang_cu
xizang_ct xz.ct10000.com
nixia_cu
nixia_ct
jiangxi_cu
jiangxi_ct jx.ct10000.com
fujian_cu
fujian_ct fj.ct10000.com
hainan_cu
hainan_ct hi.ct10000.com


4、测试结果netspeed.txt


liaoning_ct 2011-03-10 14:50:09 48.06 KB/s 54622/54622
hubei_cu 2011-03-10 14:50:09 9.16 MB/s 144116/144116
hubei_ct 2011-03-10 14:50:09 1.13 MB/s 109823/109823
shanxi_ct(ty) 2011-03-10 14:50:09 820.74 KB/s 91608
shanxi_cu(ty) 2011-03-10 14:50:09 507.71 KB/s 5199/5199
hunan_cu 2011-03-10 14:50:10 251.34 KB/s 42981
hunan_ct 2011-03-10 14:50:10 360.19 KB/s 74873/74873
shandong_ct 2011-03-10 14:50:10 316.07 KB/s 61495/61495
shandong_cu 2011-03-10 14:50:11 653.64 KB/s 32797
sichuan_cu 2011-03-10 14:50:11 566.11 KB/s 115940/115940
sichuan_ct 2011-03-10 14:50:11 289.50 KB/s 76781
jilin_ct 2011-03-10 14:50:11 460.67 KB/s 39625
jilin_cu 2011-03-10 14:50:12 402.26 KB/s 38720/38720
chongqing_cu 2011-03-10 14:50:13 706.03 KB/s 142426/142426
chongqing_ct 2011-03-10 14:50:13 273.14 KB/s 63491
heilongjiang_cu 2011-03-10 14:50:13 467.59 KB/s 30644/30644


5、结果统计脚本 result.sh


#!/bin/awk -f


# Counter for every isp test times
# Speed_sum for sum of downloaded speed

BEGIN { 
        ISP[""]
        Counter[0]
        Speed_sum[0]
        i=1
        ISP[i] = $1 
        Counter[i]=0
        Speed_sum[i]=0
#       Isp_counter=0
       }






  {if ( $1==ISP[i]) 
   
   Counter[i] = Counter[i] + 1


   Speed_sum[i] = Speed_sum[i] + $4
   
   print ISP[i], Speed_sum[i]
  }


  {if ($1 != ISP[i])


   ISP[i+1]=$1
  }




  


END { for ( j in ISP  ) print  ISP[j],Counter[j],Speed_sum[j] } 


6、求平均最小最大值命令


awk 'BEGIN{sum=0;max=0;min=0;i=0} {sum=sum+$3;if(max<$3)max=$3;if(min>$3)min=$3;i=i+1} END{print sum/i ,min,max}' r.txt
阅读(4217) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~