across/bench.sh

167 lines
7.6 KiB
Bash
Raw Normal View History

2016-11-29 14:25:31 +09:00
#!/usr/bin/env bash
#
# Description: Auto test download & I/O speed script
#
# Copyright (C) 2015 - 2016 Teddysun <i@teddysun.com>
#
# Thanks: LookBack <admin@dwhd.org>
#
# URL: https://teddysun.com/444.html
#
2015-09-09 10:39:03 +08:00
2016-11-24 22:23:24 +09:00
if [ ! -e '/usr/bin/wget' ]; then
echo "Error: wget command not found. You must be install wget command at first."
exit 1
fi
2016-11-30 11:24:07 +09:00
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
2016-11-30 11:34:48 +09:00
PLAIN='\033[0m'
2016-11-30 11:24:07 +09:00
2015-12-14 22:15:18 +08:00
get_opsy() {
2016-07-02 12:32:36 +09:00
[ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
2015-12-25 20:16:48 +08:00
[ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
2015-12-14 22:15:18 +08:00
[ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}
2015-09-09 10:39:03 +08:00
next() {
2015-09-23 10:04:56 +08:00
printf "%-70s\n" "-" | sed 's/\s/-/g'
2015-09-09 10:39:03 +08:00
}
2016-12-01 18:29:17 +09:00
display() {
2016-12-01 18:34:05 +09:00
unset nodeName ipaddress speedtest
2016-12-01 18:29:17 +09:00
local nodeName=$1
local ipaddress=$2
local speedtest=$3
if [ "${#nodeName}" -lt "8" ]; then
2016-11-30 11:34:48 +09:00
echo -e "${YELLOW}${nodeName}\t\t\t\t${GREEN}${ipaddress}\t\t${RED}${speedtest}${PLAIN}"
2015-09-23 10:04:56 +08:00
elif [ "${#nodeName}" -lt "13" ]; then
2016-11-30 11:34:48 +09:00
echo -e "${YELLOW}${nodeName}\t\t\t${GREEN}${ipaddress}\t\t${RED}${speedtest}${PLAIN}"
2016-12-01 18:29:17 +09:00
elif [ "${#nodeName}" -lt "24" -a "${#ipaddress}" -gt "13" ]; then
echo -e "${YELLOW}${nodeName}\t\t${GREEN}${ipaddress}\t${RED}${speedtest}${PLAIN}"
2015-09-23 10:04:56 +08:00
elif [ "${#nodeName}" -lt "24" ]; then
2016-11-30 11:34:48 +09:00
echo -e "${YELLOW}${nodeName}\t\t${GREEN}${ipaddress}\t\t${RED}${speedtest}${PLAIN}"
2016-12-01 18:29:17 +09:00
elif [ "${#nodeName}" -ge "24" -a "${#ipaddress}" -gt "13" ]; then
echo -e "${YELLOW}${nodeName}\t${GREEN}${ipaddress}\t${RED}${speedtest}${PLAIN}"
2015-09-23 10:04:56 +08:00
elif [ "${#nodeName}" -ge "24" ]; then
2016-11-30 11:34:48 +09:00
echo -e "${YELLOW}${nodeName}\t${GREEN}${ipaddress}\t\t${RED}${speedtest}${PLAIN}"
2015-09-23 10:04:56 +08:00
fi
2015-11-29 18:39:56 +08:00
}
2016-12-01 18:29:17 +09:00
speed_test() {
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
2016-12-01 18:36:16 +09:00
display "${nodeName}" "${ipaddress}" "${speedtest}"
2016-12-01 18:29:17 +09:00
}
2015-11-29 18:39:56 +08:00
speed_test_v6() {
2016-11-24 22:23:24 +09:00
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
2016-12-01 18:36:16 +09:00
display "${nodeName}" "${ipaddress}" "${speedtest}"
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://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-12-03 14:33:33 +08:00
io_test() {
2016-11-24 22:23:24 +09:00
(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]*$//'
2015-12-03 14:33:33 +08:00
}
2016-11-24 22:23:24 +09:00
calc_disk() {
local total_size=0
2016-11-25 00:46:43 +09:00
local array=$@
2016-11-24 22:23:24 +09:00
for size in ${array[@]}
do
2016-11-25 00:46:43 +09:00
[ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}`
2016-11-27 16:37:14 +09:00
[ "`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}
2016-11-25 11:33:45 +09:00
total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' )
2016-11-24 22:23:24 +09:00
done
echo ${total_size}
}
2015-12-14 22:15:18 +08:00
2016-11-24 22:23:24 +09:00
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}' )
2016-11-24 23:40:26 +09:00
uram=$( free -m | awk '/Mem/ {print $3}' )
2016-11-24 22:23:24 +09:00
swap=$( free -m | awk '/Swap/ {print $2}' )
2016-11-29 14:25:31 +09:00
uswap=$( free -m | awk '/Swap/ {print $3}' )
2016-11-25 00:58:42 +09:00
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 )
2016-11-24 22:23:24 +09:00
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 )
2016-11-27 00:44:36 +09:00
disk_size1=($( df -ahPl | grep -wvE '\-|none|tmpfs|by-uuid|Filesystem' | awk '{print $2}' ))
disk_size2=($( df -ahPl | grep -wvE '\-|none|tmpfs|by-uuid|Filesystem' | awk '{print $3}' ))
2016-11-25 00:46:43 +09:00
disk_total_size=$( calc_disk ${disk_size1[@]} )
disk_used_size=$( calc_disk ${disk_size2[@]} )
2015-09-09 10:39:03 +08:00
2016-11-24 22:23:24 +09:00
clear
next
echo "CPU model : $cname"
echo "Number of cores : $cores"
echo "CPU frequency : $freq MHz"
2016-11-24 23:40:26 +09:00
echo "Total size of Disk : $disk_total_size GB ($disk_used_size GB Used)"
echo "Total amount of Mem : $tram MB ($uram MB Used)"
2016-11-29 14:25:31 +09:00
echo "Total amount of Swap : $swap MB ($uswap MB Used)"
2016-11-24 22:23:24 +09:00
echo "System uptime : $up"
echo "Load average : $load"
echo "OS : $opsy"
echo "Arch : $arch ($lbit Bit)"
echo "Kernel : $kern"
next
2015-12-03 14:33:33 +08:00
io1=$( io_test )
2016-11-24 22:38:36 +09:00
echo "I/O speed(1st run) : $io1"
2015-12-03 14:33:33 +08:00
io2=$( io_test )
2016-11-24 22:38:36 +09:00
echo "I/O speed(2nd run) : $io2"
2015-12-03 14:33:33 +08:00
io3=$( io_test )
2016-11-24 22:38:36 +09:00
echo "I/O speed(3rd run) : $io3"
2015-12-03 01:28:21 +08:00
ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' )
2015-12-27 14:47:56 +08:00
[ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' )
2015-12-03 01:28:21 +08:00
ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' )
2015-12-27 14:47:56 +08:00
[ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' )
2015-12-03 01:28:21 +08:00
ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' )
2015-12-27 14:47:56 +08:00
[ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' )
2015-12-02 22:16:44 +08:00
ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' )
2016-11-25 16:24:37 +09:00
ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' )
2016-11-24 22:38:36 +09:00
echo "Average I/O speed : $ioavg MB/s"
next
echo -e "Node Name\t\t\tIPv4 address\t\tDownload Speed"
speed && next
if [[ "$ipv6" != "" ]]; then
echo -e "Node Name\t\t\tIPv6 address\t\tDownload Speed"
speed_v6 && next
fi