across/bench.sh

112 lines
5.9 KiB
Bash
Raw Normal View History

2015-09-09 10:39:03 +08:00
#!/bin/bash
#==============================================================#
# Description: bench test script #
# Author: Teddysun <i@teddysun.com> #
# Thanks: LookBack <admin@dwhd.org> #
# Visit: https://teddysun.com #
#==============================================================#
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=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60;d=$1%60} {printf("%ddays, %d:%d:%d\n",a,b,c,d)}' /proc/uptime )
next() {
2015-09-23 10:04:56 +08:00
printf "%-70s\n" "-" | sed 's/\s/-/g'
2015-09-09 10:39:03 +08:00
}
speed_test() {
2015-11-29 19:56:42 +08:00
speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
2015-11-29 18:39:56 +08:00
ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}')
2015-09-23 10:04:56 +08:00
nodeName=$2
if [ "${#nodeName}" -lt "8" ]; then
echo -e "\e[33m$2\e[0m\t\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
elif [ "${#nodeName}" -lt "13" ]; then
echo -e "\e[33m$2\e[0m\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
elif [ "${#nodeName}" -lt "24" ]; then
echo -e "\e[33m$2\e[0m\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
elif [ "${#nodeName}" -ge "24" ]; then
echo -e "\e[33m$2\e[0m\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
fi
2015-11-29 18:39:56 +08:00
}
speed_test_v6() {
2015-11-29 19:56:42 +08:00
speedtest=$(wget -6O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
2015-11-29 18:39:56 +08:00
ipaddress=$(ping6 -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}')
nodeName=$2
2015-11-29 19:07:00 +08:00
if [ "${#nodeName}" -lt "8" -a "${#ipaddress}" -eq "13" ]; then
2015-11-29 18:39:56 +08:00
echo -e "\e[33m$2\e[0m\t\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
2015-11-29 19:07:00 +08:00
elif [ "${#nodeName}" -lt "13" -a "${#ipaddress}" -eq "13" ]; then
2015-11-29 18:39:56 +08:00
echo -e "\e[33m$2\e[0m\t\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
2015-11-29 19:07:00 +08:00
elif [ "${#nodeName}" -lt "24" -a "${#ipaddress}" -eq "13" ]; then
echo -e "\e[33m$2\e[0m\t\t\e[32m$ipaddress\e[0m\t\t\e[31m$speedtest\e[0m"
elif [ "${#nodeName}" -lt "24" -a "${#ipaddress}" -gt "13" ]; then
2015-11-29 18:39:56 +08:00
echo -e "\e[33m$2\e[0m\t\t\e[32m$ipaddress\e[0m\t\e[31m$speedtest\e[0m"
elif [ "${#nodeName}" -ge "24" ]; then
echo -e "\e[33m$2\e[0m\t\e[32m$ipaddress\e[0m\t\e[31m$speedtest\e[0m"
fi
2015-09-09 10:39:03 +08:00
}
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.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG'
speed_test 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK'
speed_test 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE'
speed_test 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA'
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.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.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE'
speed_test 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG'
speed_test 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN'
}
2015-11-29 18:39:56 +08:00
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'
}
2015-09-09 10:39:03 +08:00
clear
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"
next
2015-09-09 17:00:16 +08:00
if [ -e '/usr/bin/wget' ]; then
2015-11-29 19:07:00 +08:00
echo -e "Node Name\t\t\tIPv4 address\t\tDownload Speed"
2015-09-09 17:00:16 +08:00
speed && next
2015-11-29 19:43:13 +08:00
if [ -e '/usr/bin/curl' ]; then
ipv6=$(curl -s -6 icanhazip.com)
2015-11-29 19:59:07 +08:00
if [[ "$ipv6" != "" ]]; then
2015-11-29 19:43:13 +08:00
echo -e "Node Name\t\t\tIPv6 address\t\tDownload Speed"
speed_v6 && next
fi
else
echo "curl command not found. IPv6 speed test is ignored."
2015-11-29 18:39:56 +08:00
fi
2015-09-09 17:00:16 +08:00
else
echo "Error: wget command not found. You must be install wget command at first."
exit 1
fi
2015-09-09 10:39:03 +08:00
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"
echo ""