mirror of
https://github.com/teddysun/across.git
synced 2025-01-19 06:19:35 +08:00
Update Comments
Change to speedtest-cli for network speed test Signed-off-by: Teddysun <i@teddysun.com>
This commit is contained in:
parent
9012079a90
commit
23ffec1c83
71
bench.sh
71
bench.sh
@ -36,6 +36,14 @@ _exists() {
|
||||
return ${rt}
|
||||
}
|
||||
|
||||
_64bit(){
|
||||
if [ $(getconf WORD_BIT) = '32' ] && [ $(getconf LONG_BIT) = '64' ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
@ -46,26 +54,31 @@ next() {
|
||||
printf "%-70s\n" "-" | sed 's/\s/-/g'
|
||||
}
|
||||
|
||||
speed_test_v4() {
|
||||
local output=$(LANG=C wget -4O /dev/null -T300 $1 2>&1)
|
||||
local speedtest=$(printf '%s' "$output" | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
|
||||
local ipaddress=$(printf '%s' "$output" | awk -F'|' '/Connecting to .*\|([^\|]+)\|/ {print $2}')
|
||||
speed_test() {
|
||||
speedtest-cli/speedtest -p no $1 --accept-license > speedtest-cli/speedtest.log 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
local nodeName=$2
|
||||
printf "\033[0;33m%-32s\033[0;32m%-24s\033[0;31m%-14s\033[0m\n" "${nodeName}" "${ipaddress}" "${speedtest}"
|
||||
local dl_speed=$(awk '/Download/{print $3}' speedtest-cli/speedtest.log)
|
||||
local up_speed=$(awk '/Upload/{print $3}' speedtest-cli/speedtest.log)
|
||||
local latency=$(awk '/Latency/{print $2}' speedtest-cli/speedtest.log)
|
||||
if [[ -n "${dl_speed}" && -n "${up_speed}" && -n "${latency}" ]]; then
|
||||
printf "\033[0;33m%-18s\033[0;32m%-18s\033[0;31m%-20s\033[0;36m%-12s\033[0m\n" " ${nodeName}" "${up_speed} Mbit/s" "${dl_speed} Mbit/s" "${latency} ms"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
speed_v4() {
|
||||
speed_test_v4 'http://cachefly.cachefly.net/100mb.test' 'CacheFly'
|
||||
speed_test_v4 'http://speedtest.tokyo2.linode.com/100MB-tokyo2.bin' 'Linode, Tokyo2, 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, US'
|
||||
speed_test_v4 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, US'
|
||||
speed_test_v4 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, US'
|
||||
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() {
|
||||
speed_test '' 'Speedtest.net'
|
||||
speed_test '-s 5145' 'Beijing CU'
|
||||
speed_test '-s 3633' 'Shanghai CT'
|
||||
speed_test '-s 24447' 'Shanghai CU'
|
||||
speed_test '-s 27594' 'Guangzhou CT'
|
||||
speed_test '-s 26678' 'Guangzhou CU'
|
||||
speed_test '-s 16192' 'Shenzhen CU'
|
||||
speed_test '-s 4515' 'Shenzhen CM'
|
||||
speed_test '-s 32155' 'Hongkong CN'
|
||||
speed_test '-s 13623' 'Singapore SG'
|
||||
speed_test '-s 15047' 'Tokyo JP'
|
||||
}
|
||||
|
||||
io_test() {
|
||||
@ -143,12 +156,27 @@ ipv4_info() {
|
||||
[[ -n "$region" ]] && echo " Region : $(_blue "$region")"
|
||||
}
|
||||
|
||||
install_speedtest() {
|
||||
if [ ! -e "./speedtest-cli/speedtest" ]; then
|
||||
_64bit && sys_bit=x86_64 || sys_bit=i386
|
||||
url1="https://dl.bintray.com/ookla/download/ookla-speedtest-1.0.0-${sys_bit}-linux.tgz"
|
||||
url2="https://dl.lamp.sh/files/ookla-speedtest-1.0.0-${sys_bit}-linux.tgz"
|
||||
wget --no-check-certificate -qO speedtest.tgz ${url1}
|
||||
if [ $? -ne 0 ]; then
|
||||
wget --no-check-certificate -qO speedtest.tgz ${url2}
|
||||
[ $? -ne 0 ] && _red "Error: Failed to download speedtest-cli.\n" && exit 1
|
||||
fi
|
||||
mkdir -p speedtest-cli && tar zxf speedtest.tgz -C ./speedtest-cli && chmod +x ./speedtest-cli/speedtest
|
||||
rm -f speedtest.tgz
|
||||
fi
|
||||
}
|
||||
|
||||
! _exists "wget" && _red "Error: wget command not found. You must be install wget command at first.\n" && exit 1
|
||||
# Get System information
|
||||
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/ {print $4;exit}' /proc/cpuinfo )
|
||||
corescache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
|
||||
ccache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /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}' )
|
||||
@ -170,7 +198,7 @@ next
|
||||
echo " CPU Model : $(_blue "$cname")"
|
||||
echo " CPU Cores : $(_blue "$cores")"
|
||||
echo " CPU Frequency : $(_blue "$freq MHz")"
|
||||
echo "CPU Cache : $(_blue "$corescache")"
|
||||
echo " CPU Cache : $(_blue "$ccache")"
|
||||
echo " Total Disk : $(_blue "$disk_total_size GB ($disk_used_size GB Used)")"
|
||||
echo " Total Mem : $(_blue "$tram MB ($uram MB Used)")"
|
||||
echo " Total Swap : $(_blue "$swap MB ($uswap MB Used)")"
|
||||
@ -199,6 +227,7 @@ ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' )
|
||||
ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' )
|
||||
echo -e " Average I/O speed : $(_yellow "$ioavg MB/s")"
|
||||
next
|
||||
printf "%-32s%-24s%-14s\n" "Node Name" "IPv4 address" "Download Speed"
|
||||
speed_v4
|
||||
install_speedtest
|
||||
printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency"
|
||||
speed && rm -fr speedtest-cli
|
||||
next
|
||||
|
Loading…
x
Reference in New Issue
Block a user