Linux之VPS测试脚本

摘要

不知道是不是强迫症,虽然自己写的也不好但是看人家的那个更乱,更不舒服,所以就给改了。

###VPS流量跑不完?运行下面的命令
while true; do curl -Lks onekey.sh/bench|bash; done
###测试方法
curl -Lks onekey.sh/bench|bash

code.png


2015-09-25更新到1.3Beat版本

新版显示样式:
Linux之VPS测试脚本

Linux之VPS测试脚本

下面是这个版本的源码

Linux之VPS测试脚本

#!/bin/bash
#########################################################################
# File Name: bench.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version: 1.3Beta
# Created Time: 2015年09月05日 星期六 20时54分46秒
#########################################################################


sort_speed() {
    Speed_Test http://cachefly.cachefly.net/100mb.test 'CacheFly'
    Speed_Test http://speedtest.tokyo.linode.com/100MB-tokyo.bin 'Linode, Tokyo, JP'
    Speed_Test http://speedtest.london.linode.com/100MB-london.bin 'Linode, London, UK'
    Speed_Test http://mirror.nl.leaseweb.net/speedtest/100mb.bin 'Leaseweb, Amsterdam, NL'
    Speed_Test http://mirror.us.leaseweb.net/speedtest/100mb.bin 'Leaseweb, Virginia, USA'
    Speed_Test http://mirror.de.leaseweb.net/speedtest/100mb.bin 'Leaseweb, Frankfurt, DE'
    Speed_Test http://tx-us-ping.vultr.com/vultr.com.100MB.bin 'Vultr, Dallas, TX'
    Speed_Test http://wa-us-ping.vultr.com/vultr.com.100MB.bin 'Vultr, Seattle, WA'
    Speed_Test http://lax-ca-us-ping.vultr.com/vultr.com.100MB.bin 'Vultr, Los Angeles, CA'
    Speed_Test http://fra-de-ping.vultr.com/vultr.com.100MB.bin 'Vultr, Frankfurt, DE'
    Speed_Test http://hnd-jp-ping.vultr.com/vultr.com.100MB.bin 'Vultr, Tokyo, JP'
    Speed_Test http://speedtest.wdc01.softlayer.com/downloads/test100.zip 'Softlayer, Washington, DC'
    Speed_Test http://speedtest.dal05.softlayer.com/downloads/test100.zip 'Softlayer, Dallas, TX'
    Speed_Test http://speedtest.sea01.softlayer.com/downloads/test100.zip 'Softlayer, Seattle, WA'
    Speed_Test http://speedtest.sjc01.softlayer.com/downloads/test100.zip 'Softlayer, San Jose, CA'
    Speed_Test http://speedtest.sng01.softlayer.com/downloads/test100.zip 'Softlayer, Badhoevedorp, SG'
    Speed_Test http://speedtest.hkg02.softlayer.com/downloads/test100.zip 'Softlayer, HongKong, CN'
    Speed_Test http://proof.ovh.net/files/100Mb.dat 'OVH, EU'
    Speed_Test http://proof.ovh.ca/files/100Mb.dat 'OVH, CA'
    #Speed_Test http://dldir1.qq.com/qqfile/qq/QQ7.6/15742/QQ7.6.exe QQ
    #Speed_Test http://lax-noc.com/100mb.bin QuadraNet
}

Speed_Test() {
    speedtest=$(wget -4O /dev/null $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
    #ipcheck=$(curl -4v -r 0-128 -o /dev/null $1 2>&1| awk -F'[()]' '/Connected/{print$2}')
    ipcheck=$(ping -c1 `awk -F'/' '{if($0~/^(ht|f)tps?/){print $3}else{print $1}}' <<< $1` | awk -F'[()]' '{print $2;exit}')
    #pingtest=$(ping -qc4 $ipcheck | awk 'END{print}')
    sumTab "$2" "$ipcheck" "$speedtest"
    echo -e "${CYELLOW}$2${NodeTab}${CDGREEN}$ipcheck${ipTab}${CWARNING}$speedtest${CEND}"
}

IOtest() {
    io=$((dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && /bin/rm -f test_$$) 2>&1 | awk 'END{print}')
    echo "I/O speed : $io"
}

systemInfo() {
    cname=$(awk -F':[ ]' '/model name/{printf ("%s\n",$2);exit}' /proc/cpuinfo)
    cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
    freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
    tram=$( free -m | awk 'NR==2 {print $2}' )
    swap=$( free -m | awk 'NR==4 {print $2}' )
    up=$(awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60}{printf("%ddays, %dH %dM %dS\n",a,b,c,d)}' /proc/uptime)
    if [ -b "/dev/sda" ]; then
        if which smartctl >/dev/null 2>&1; then diskonline=`smartctl -A /dev/sda |awk '/Power_On_Hours/{print $NF" Hours"}'`;fi
    fi

    echo "$(awk -F':[ ]' '/model name/{printf ("CPU model : %s\n",$2);exit}' /proc/cpuinfo)
Number of cores : $cores
CPU frequency : $freq MHz
Total amount of ram : $tram MB
Total amount of swap : $swap MB
System uptime : $up"
    [[ -n "$diskonline" ]] && echo "/dev/sda Online : $diskonline"
    Next_Info
}

PrintColour() {
    echo=echo
    for cmd in echo /bin/echo; do
        $cmd >/dev/null 2>&1 || continue
        if ! $cmd -e "" | grep -qE '^-e'; then
            echo=$cmd
            break
        fi
    done
    CSI=$($echo -e "\033[")
    CEND="${CSI}0m"
    CDGREEN="${CSI}32m"
    CRED="${CSI}1;31m"
    CGREEN="${CSI}1;32m"
    CYELLOW="${CSI}1;33m"
    CBLUE="${CSI}1;34m"
    CMAGENTA="${CSI}1;35m"
    CCYAN="${CSI}1;36m"
    CQUESTION="$CMAGENTA"
    CWARNING="$CRED"
    CMSG="$CCYAN"
}

Next_Info() {
    printf "%-70s\n" "-" | sed 's/\s/-/g'
}

sumTab(){
    nodeName=$1 && ipTab=$2
    NodeTab=`printf "%-$(expr 30 - ${#nodeName})s" " "`
    ipTab=`printf "%-$(expr 24 - ${#ipTab})s" " "`
}

printSpeed() {
    sumTab "Node Name" "Node IPaddress"
    echo -e "Node Name${NodeTab}Node IPaddress${ipTab}Download Speed"
    sort_speed | tee /tmp/Speed_Test_$$
    Next_Info
}

awk_sort_speed() {
    sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" /tmp/Speed_Test_$$ | \
    awk '{if ($(NF-2)~/MB/){a[i++]=+$(NF-2)*1024;d+=+$(NF-2)*1024;e++}else if ($(NF-2)~/KB/){a[i++]=+$(NF-2);d+=+$(NF-2);e++}}END{b=asort(a,c);for(i=1;i<=b;i++){if(i==b){if(c[i]>=1024){print c[i]/1024"MB/s"}else{print c[i]"KB/s"}}else if(i%8==0){if(c[i]>=1024){print c[i]/1024"MB/s"}else{print c[i]"KB/s"}}else{if(c[i]>=1024){printf c[i]/1024"MB/s "}else{printf c[i]"KB/s "}}}}END{printf "Download Speed Average : "d/e/1024"MB/s\n"}'
    /bin/rm -rf /tmp/Speed_Test_$$
}

#echo -e "\n\e[32m$(awk_sort_speed)\e[0m"
#fdisk -l | awk '/^\/dev/{if ($3%4==0){print $1" : 4K Alignment"}else {print $1" : 4K Not Alignment"}}'
#Next_Info

PrintColour
systemInfo
printSpeed
IOtest

2015-08-13更新到1.2Beat版本
Linux之VPS测试脚本
根据网上一个比较流行的VPS测试脚本做的更改。。。

[root@vps197121 ~]# wget -4qO- onekey.sh/bench|bash
CPU model : Intel Xeon E312xx (Sandy Bridge)
Number of cores : 1
CPU frequency :  2394.454 MHz
Total amount of ram : 1829 MB
Total amount of swap : 0 MB
System uptime : 7days, 5H 40M 43S
------------------------------------------------------------
Download speed from CacheFly: 12.0MB/s IP 62.210.187.96
Download speed from QQ: 10.8MB/s IP 151.249.94.25
Download speed from Linode, Tokyo, JP: 3.08MB/s IP 106.187.96.148
Download speed from Linode, London: 11.9MB/s IP 176.58.107.39
Download speed from QuadraNet: 6.49MB/s IP 198.55.111.5
Download speed from Leaseweb, Amsterdam, NL: 11.9MB/s IP 94.75.223.121
Download speed from VULTR, Los Angeles, USA: 8.68MB/s IP 108.61.219.200
Download speed from VULTR, Tokyo, Japan: 4.74MB/s IP 108.61.201.151
Download speed from Softlayer, Washington, DC: 10.6MB/s IP 208.43.102.250
Download speed from Softlayer, Dallas, TX: 8.49MB/s IP 173.192.68.18
Download speed from Softlayer, Seattle, WA: 7.29MB/s IP 67.228.112.250
Download speed from Softlayer, San Jose, CA: 8.76MB/s IP 50.23.64.58
Download speed from Softlayer, Singapore: 4.49MB/s IP 119.81.28.170
Download speed from Softlayer, HKSAR: 4.75MB/s IP 119.81.130.170
Download speed from OVH, EU: 11.6MB/s IP 188.165.12.106
Download speed from OVH, CA: 5.21MB/s IP 192.99.19.165

3.08MB/s 4.49MB/s 4.74MB/s 4.75MB/s 5.21MB/s 6.49MB/s 7.29MB/s 8.49MB/s 8.68MB/s 8.76MB/s 10.6MB/s 10.8MB/s 11.6MB/s 11.9MB/s 11.9MB/s 12MB/s
Average : 8.17375MB
------------------------------------------------------------
I/O speed : 1073741824 bytes (1.1 GB) copied, 2.86226 s, 375 MB/s
------------------------------------------------------------
[root@vps197121 ~]#

网上版本的源码

#!/bin/bash

cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
tram=$( free -m | awk 'NR==2 {print $2}' )
swap=$( free -m | awk 'NR==4 {print $2}' )
up=$(uptime|awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }')

echo "CPU model : $cname"
echo "Number of cores : $cores"
echo "CPU frequency : $freq MHz"
echo "Total amount of ram : $tram MB"
echo "Total amount of swap : $swap MB"
echo "System uptime : $up"

cachefly=$( wget -O /dev/null http://cachefly.cachefly.net/100mb.test 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from CacheFly: $cachefly "
coloatatl=$( wget -O /dev/null http://speed.atl.coloat.com/100mb.test 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Coloat, Atlanta GA: $coloatatl "
sldltx=$( wget -O /dev/null http://speedtest.dal05.softlayer.com/downloads/test100.zip 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Dallas, TX: $sldltx "
linodejp=$( wget -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Linode, Tokyo, JP: $linodejp "
i3d=$( wget -O /dev/null http://mirror.i3d.net/100mb.bin 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from i3d.net, Rotterdam, NL: $i3d"

#linodeuk=$( wget -O /dev/null http://speedtest.london.linode.com/100MB-london.bin 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
#echo "Download speed from Linode, London, UK: $linodeuk "
leaseweb=$( wget -O /dev/null http://mirror.leaseweb.com/speedtest/100mb.bin 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Leaseweb, Haarlem, NL: $leaseweb "
slsg=$( wget -O /dev/null http://speedtest.sng01.softlayer.com/downloads/test100.zip 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Singapore: $slsg "
slwa=$( wget -O /dev/null http://speedtest.sea01.softlayer.com/downloads/test100.zip 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Seattle, WA: $slwa "
slsjc=$( wget -O /dev/null http://speedtest.sjc01.softlayer.com/downloads/test100.zip 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, San Jose, CA: $slsjc "
slwdc=$( wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
echo "Download speed from Softlayer, Washington, DC: $slwdc "
io=$((dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync &amp;amp;&amp;amp; /bin/rm -f test_$$) 2&amp;gt;&amp;amp;1 | awk 'END{print}')
echo "I/O speed : $io"

下面是脚本源码
Linux之VPS测试脚本

#!/bin/bash
#########################################################################
# File Name: bench.sh
# Author: LookBack
# Email: admin#dwhd.org
# Version:
# Created Time: 2015年09月05日 星期六 20时54分46秒
#########################################################################

Next_Info() {
        printf "%-60s\n" "-" | sed 's/\s/-/g'
}

#cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )
cname=$(awk -F':[ ]' '/model name/{printf ("%s\n",$2);exit}' /proc/cpuinfo)
cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )
tram=$( free -m | awk 'NR==2 {print $2}' )
swap=$( free -m | awk 'NR==4 {print $2}' )
up=$(awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60}{printf("%ddays, %dH %dM %dS\n",a,b,c,d)}' /proc/uptime)

echo "$(awk -F':[ ]' '/model name/{printf ("CPU model : %s\n",$2);exit}' /proc/cpuinfo)
Number of cores : $cores
CPU frequency : $freq MHz
Total amount of ram : $tram MB
Total amount of swap : $swap MB
System uptime : $up"
Next_Info

Speed_Test() {
        speedtest=$(wget -4O /dev/null $2 2&amp;gt;&amp;amp;1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
        ipcheck=$(curl -4v -r 0-128 -o /dev/null $2 2&amp;gt;&amp;amp;1| awk -F'[()]' '/Connected/{print$2}')
        echo -e "Download speed from \e[33m$3\e[0m: \e[31m$speedtest\e[0m IP \e[32m$ipcheck\e[0m"
}


sort_speed() {
        Speed_Test cachefly http://cachefly.cachefly.net/100mb.test CacheFly
        Speed_Test qq http://dldir1.qq.com/qqfile/qq/QQ7.6/15742/QQ7.6.exe QQ
        Speed_Test linodejp http://speedtest.tokyo.linode.com/100MB-tokyo.bin 'Linode, Tokyo, JP'
        Speed_Test linodeLondon http://speedtest.london.linode.com/100MB-london.bin 'Linode, London'
        Speed_Test QuadraNet http://lax-noc.com/100mb.bin QuadraNet
        Speed_Test leaseweb http://mirror.leaseweb.com/speedtest/100mb.bin 'Leaseweb, Amsterdam, NL'
        Speed_Test vultrla http://lax-ca-us-ping.vultr.com/vultr.com.100MB.bin 'VULTR, Los Angeles, USA'
        Speed_Test vultrjp http://hnd-jp-ping.vultr.com/vultr.com.100MB.bin 'VULTR, Tokyo, Japan'
        Speed_Test slwdc http://speedtest.wdc01.softlayer.com/downloads/test100.zip 'Softlayer, Washington, DC'
        Speed_Test sldltx http://speedtest.dal05.softlayer.com/downloads/test100.zip 'Softlayer, Dallas, TX'
        Speed_Test slwa http://speedtest.sea01.softlayer.com/downloads/test100.zip 'Softlayer, Seattle, WA'
        Speed_Test slsjc http://speedtest.sjc01.softlayer.com/downloads/test100.zip 'Softlayer, San Jose, CA'
        Speed_Test slsg http://speedtest.sng01.softlayer.com/downloads/test100.zip 'Softlayer, Singapore'
        Speed_Test slhk http://speedtest.hkg02.softlayer.com/downloads/test100.zip 'Softlayer, HKSAR'
        Speed_Test ovheu http://proof.ovh.net/files/100Mb.dat 'OVH, EU'
        Speed_Test ovhca http://proof.ovh.ca/files/100Mb.dat 'OVH, CA'
}

sort_speed | tee /tmp/speed_test_$$

awk_sort_speed() {
        sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" /tmp/speed_test_$$ | \
        awk '{if ($(NF-2)~/MB/){a[i++]=+$(NF-2)*1024;d+=+$(NF-2)*1024;e++}else if ($(NF-2)~/KB/){a[i++]=+$(NF-2);d+=+$(NF-2);e++}}END{b=asort(a,c);for(i=1;i&amp;lt;=b;i++){if(i==b){if(c[i]&amp;gt;=1024){print c[i]/1024"MB/s"}else{print c[i]"KB/s"}}else if(i%8==0){if(c[i]&amp;gt;=1024){print c[i]/1024"MB/s"}else{print c[i]"KB/s"}}else{if(c[i]&amp;gt;=1024){printf c[i]/1024"MB/s "}else{printf c[i]"KB/s "}}}}END{printf "Download Speed Average : "d/e/1024"MB\n"}'
        /bin/rm -rf /tmp/speed_test_$$
}

echo -e "\n\e[32m$(awk_sort_speed)\e[0m" &amp;amp;&amp;amp; Next_Info

io=$((dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync &amp;amp;&amp;amp; /bin/rm -f test_$$) 2&amp;gt;&amp;amp;1 | awk 'END{print}')
echo "I/O speed : $io"
Next_Info

fdisk -l | awk '/^\/dev/{if ($3%4==0){print $1" : 4K Alignment"}else {print $1" : 4K Not Alignment"}}'
Next_Info

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: