目前一键测试脚本bench.sh已经非常成熟,你看到过的很多VPS服务器评测可能都是使用此脚本进行系统信息、IO读写、下载速度测试。bench.sh几乎支持所有Linux发行版系统的带宽、IO测试和服务器基本信息检测。
脚本使用命令
命令1:
yum -y install wget wget -qO- bench.sh | bash
或者
curl -Lso- bench.sh | bash
命令2:
yum -y install wget wget -qO- 86.re/bench.sh | bash
bench.sh脚本源码
#!/usr/bin/env bash # # Description: Auto test download & I/O speed script # # Copyright (C) 2015 - 2018 Teddysun <i@teddysun.com> # # Thanks: LookBack <admin@dwhd.org> # # URL: https://teddysun.com/444.html # if [ ! -e '/usr/bin/wget' ]; then echo "Error: wget command not found. You must be install wget command at first." exit 1 fi # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;36m' PLAIN='\033[0m' get_opsy() { [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return } next() { printf "%-70s\n" "-" | sed 's/\s/-/g' } speed_test_v4() { local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') local ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') local nodeName=$2 printf "${YELLOW}%-32s${GREEN}%-24s${RED}%-14s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" } speed_test_v6() { local speedtest=$(wget -6O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') local ipaddress=$(ping6 -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') local nodeName=$2 printf "${YELLOW}%-32s${GREEN}%-24s${RED}%-14s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" } speed_v4() { speed_test_v4 'http://cachefly.cachefly.net/100mb.test' 'CacheFly' speed_test_v4 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' speed_test_v4 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' speed_test_v4 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK' speed_test_v4 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE' speed_test_v4 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA' speed_test_v4 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, TX' speed_test_v4 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, WA' speed_test_v4 'http://speedtest.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE' speed_test_v4 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' speed_test_v4 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN' } speed_v6() { speed_test_v6 'http://speedtest.atlanta.linode.com/100MB-atlanta.bin' 'Linode, Atlanta, GA' speed_test_v6 'http://speedtest.dallas.linode.com/100MB-dallas.bin' 'Linode, Dallas, TX' speed_test_v6 'http://speedtest.newark.linode.com/100MB-newark.bin' 'Linode, Newark, NJ' speed_test_v6 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' speed_test_v6 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' speed_test_v6 'http://speedtest.sjc03.softlayer.com/downloads/test100.zip' 'Softlayer, San Jose, CA' speed_test_v6 'http://speedtest.wdc01.softlayer.com/downloads/test100.zip' 'Softlayer, Washington, WA' speed_test_v6 'http://speedtest.par01.softlayer.com/downloads/test100.zip' 'Softlayer, Paris, FR' speed_test_v6 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' speed_test_v6 'http://speedtest.tok02.softlayer.com/downloads/test100.zip' 'Softlayer, Tokyo, JP' } io_test() { (LANG=C dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' } calc_disk() { local total_size=0 local array=$@ for size in ${array[@]} do [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` [ "`echo ${size:(-1)}`" == "K" ] && size=0 [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) done echo ${total_size} } cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) tram=$( free -m | awk '/Mem/ {print $2}' ) uram=$( free -m | awk '/Mem/ {print $3}' ) swap=$( free -m | awk '/Swap/ {print $2}' ) uswap=$( free -m | awk '/Swap/ {print $3}' ) up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days, %d hour %d min\n",a,b,c)}' /proc/uptime ) load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) opsy=$( get_opsy ) arch=$( uname -m ) lbit=$( getconf LONG_BIT ) kern=$( uname -r ) ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) disk_total_size=$( calc_disk ${disk_size1[@]} ) disk_used_size=$( calc_disk ${disk_size2[@]} ) clear next echo -e "CPU model : ${BLUE}$cname${PLAIN}" echo -e "Number of cores : ${BLUE}$cores${PLAIN}" echo -e "CPU frequency : ${BLUE}$freq MHz${PLAIN}" echo -e "Total size of Disk : ${BLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" echo -e "Total amount of Mem : ${BLUE}$tram MB ($uram MB Used)${PLAIN}" echo -e "Total amount of Swap : ${BLUE}$swap MB ($uswap MB Used)${PLAIN}" echo -e "System uptime : ${BLUE}$up${PLAIN}" echo -e "Load average : ${BLUE}$load${PLAIN}" echo -e "OS : ${BLUE}$opsy${PLAIN}" echo -e "Arch : ${BLUE}$arch ($lbit Bit)${PLAIN}" echo -e "Kernel : ${BLUE}$kern${PLAIN}" next io1=$( io_test ) echo -e "I/O speed(1st run) : ${YELLOW}$io1${PLAIN}" io2=$( io_test ) echo -e "I/O speed(2nd run) : ${YELLOW}$io2${PLAIN}" io3=$( io_test ) echo -e "I/O speed(3rd run) : ${YELLOW}$io3${PLAIN}" ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) echo -e "Average I/O speed : ${YELLOW}$ioavg MB/s${PLAIN}" next printf "%-32s%-24s%-14s\n" "Node Name" "IPv4 address" "Download Speed" speed_v4 && next if [[ "$ipv6" != "" ]]; then printf "%-32s%-24s%-14s\n" "Node Name" "IPv6 address" "Download Speed" speed_v6 && next fi
脚本使用小结
bench.sh使用非常简单。基本支持所有的Linux系统,而且测试结果呈现出来非常美观。使用此脚本可以一目了然的知道当前测试的各种系统信息、IO读写情况、全球下载速度测试。脚本的IO读写测试,采用三次读写测试后取平均值;下载测速是采用全球多处知名数据中心进行测试,并且还支持IPv6下载测速。如果再配合 unixbench.sh 脚本测试,即可全面测试 VPS 的性能。
经过几个版本的演化,一键测试脚本 bench.sh 已经几乎全面适用于各种 Linux 发行版的网络(下行)和 IO 测试。
并将测试结果以较为美观的方式显示出来。
总结一下 bench.sh 特点:
1、显示当前测试的各种系统信息;
2、取自世界多处的知名数据中心的测试点,下载测试比较全面;
3、支持 IPv6 下载测速;
4、IO 测试三次,并显示平均值。
再配合 unixbench.sh 脚本测试,即可全面测试 VPS 的性能。
使用方法:
命令1:
复制
wget -qO- bench.sh | bash
或者
复制
curl -Lso- bench.sh | bash
命令2:
复制
wget -qO- 86.re/bench.sh | bash
或者
复制
curl -so- 86.re/bench.sh | bash
备注:
bench.sh 既是脚本名,同时又是域名。所以不要怀疑我写错了或者你看错了。
下载地址:
https://github.com/teddysun/across/blob/master/bench.sh
2020 年 07 月 29 日更新:
1. 修改:测速为 speedtest 提供的,区分上传下载,更实用;
2. 增加:TCP Congestion Control;虚拟化方式;IP 信息等。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...