Compare commits

..

No commits in common. "9d94a26b12c44423230dbe2b8addd94ab86433f8" and "70f8bd140d02332a3e34f435932b0c9657fd7ae8" have entirely different histories.

129
bench.sh
View File

@ -57,16 +57,12 @@ next() {
speed_test() { speed_test() {
local nodeName="$2" local nodeName="$2"
if [ -z "$1" ];then [ -z "$1" ] && ./speedtest-cli/speedtest --progress=no --accept-license --accept-gdpr >./speedtest-cli/speedtest.log 2>&1 || \
./speedtest-cli/speedtest --progress=no --accept-license --accept-gdpr >./speedtest-cli/speedtest.log 2>&1 ./speedtest-cli/speedtest --progress=no --server-id=$1 --accept-license --accept-gdpr >./speedtest-cli/speedtest.log 2>&1
else
./speedtest-cli/speedtest --progress=no --server-id="$1" --accept-license --accept-gdpr >./speedtest-cli/speedtest.log 2>&1
fi
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
local dl_speed up_speed latency local dl_speed=$(awk '/Download/{print $3" "$4}' ./speedtest-cli/speedtest.log)
dl_speed=$(awk '/Download/{print $3" "$4}' ./speedtest-cli/speedtest.log) local up_speed=$(awk '/Upload/{print $3" "$4}' ./speedtest-cli/speedtest.log)
up_speed=$(awk '/Upload/{print $3" "$4}' ./speedtest-cli/speedtest.log) local latency=$(awk '/Latency/{print $3" "$4}' ./speedtest-cli/speedtest.log)
latency=$(awk '/Latency/{print $3" "$4}' ./speedtest-cli/speedtest.log)
if [[ -n "${dl_speed}" && -n "${up_speed}" && -n "${latency}" ]]; then 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}" "${dl_speed}" "${latency}" printf "\033[0;33m%-18s\033[0;32m%-18s\033[0;31m%-20s\033[0;36m%-12s\033[0m\n" " ${nodeName}" "${up_speed}" "${dl_speed}" "${latency}"
fi fi
@ -90,7 +86,7 @@ speed() {
} }
io_test() { io_test() {
(LANG=C dd if=/dev/zero of=benchtest_$$ bs=512k count="$1" conv=fdatasync && rm -f benchtest_$$) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' (LANG=C dd if=/dev/zero of=benchtest_$$ bs=512k count=$1 conv=fdatasync && rm -f benchtest_$$) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//'
} }
calc_size() { calc_size() {
@ -115,27 +111,10 @@ calc_size() {
echo "${total_size}" echo "${total_size}"
return return
fi fi
total_size=$(awk 'BEGIN{printf "%.1f", '"$raw"' / '$num'}') total_size=$(awk 'BEGIN{printf "%.1f", '$raw' / '$num'}')
echo "${total_size} ${unit}" echo "${total_size} ${unit}"
} }
# since calc_size converts kilobyte to MB, GB and TB
# to_kibyte converts zfs size from bytes to kilobyte
to_kibyte() {
local raw=$1
awk 'BEGIN{printf "%.0f", '"$raw"' / 1024}'
}
calc_sum() {
local arr=("$@")
local s
s=0
for i in "${arr[@]}"; do
s=$((s + i))
done
echo ${s}
}
check_virt() { check_virt() {
_exists "dmesg" && virtualx="$(dmesg 2>/dev/null)" _exists "dmesg" && virtualx="$(dmesg 2>/dev/null)"
if _exists "dmidecode"; then if _exists "dmidecode"; then
@ -193,21 +172,20 @@ check_virt() {
} }
ipv4_info() { ipv4_info() {
local org city country region local org="$(wget -q -T10 -O- ipinfo.io/org)"
org="$(wget -q -T10 -O- ipinfo.io/org)" local city="$(wget -q -T10 -O- ipinfo.io/city)"
city="$(wget -q -T10 -O- ipinfo.io/city)" local country="$(wget -q -T10 -O- ipinfo.io/country)"
country="$(wget -q -T10 -O- ipinfo.io/country)" local region="$(wget -q -T10 -O- ipinfo.io/region)"
region="$(wget -q -T10 -O- ipinfo.io/region)" if [[ -n "$org" ]]; then
if [[ -n "${org}" ]]; then echo " Organization : $(_blue "$org")"
echo " Organization : $(_blue "${org}")"
fi fi
if [[ -n "${city}" && -n "${country}" ]]; then if [[ -n "$city" && -n "country" ]]; then
echo " Location : $(_blue "${city} / ${country}")" echo " Location : $(_blue "$city / $country")"
fi fi
if [[ -n "${region}" ]]; then if [[ -n "$region" ]]; then
echo " Region : $(_yellow "${region}")" echo " Region : $(_yellow "$region")"
fi fi
if [[ -z "${org}" ]]; then if [[ -z "$org" ]]; then
echo " Region : $(_red "No ISP detected")" echo " Region : $(_red "No ISP detected")"
fi fi
} }
@ -215,10 +193,9 @@ ipv4_info() {
install_speedtest() { install_speedtest() {
if [ ! -e "./speedtest-cli/speedtest" ]; then if [ ! -e "./speedtest-cli/speedtest" ]; then
sys_bit="" sys_bit=""
local sysarch local sysarch="$(uname -m)"
sysarch="$(uname -m)"
if [ "${sysarch}" = "unknown" ] || [ "${sysarch}" = "" ]; then if [ "${sysarch}" = "unknown" ] || [ "${sysarch}" = "" ]; then
sysarch="$(arch)" local sysarch="$(arch)"
fi fi
if [ "${sysarch}" = "x86_64" ]; then if [ "${sysarch}" = "x86_64" ]; then
sys_bit="x86_64" sys_bit="x86_64"
@ -238,10 +215,10 @@ install_speedtest() {
[ -z "${sys_bit}" ] && _red "Error: Unsupported system architecture (${sysarch}).\n" && exit 1 [ -z "${sys_bit}" ] && _red "Error: Unsupported system architecture (${sysarch}).\n" && exit 1
url1="https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-${sys_bit}.tgz" url1="https://install.speedtest.net/app/cli/ookla-speedtest-1.2.0-linux-${sys_bit}.tgz"
url2="https://dl.lamp.sh/files/ookla-speedtest-1.2.0-linux-${sys_bit}.tgz" url2="https://dl.lamp.sh/files/ookla-speedtest-1.2.0-linux-${sys_bit}.tgz"
if ! wget --no-check-certificate -q -T10 -O speedtest.tgz ${url1}; then wget --no-check-certificate -q -T10 -O speedtest.tgz ${url1}
if ! wget --no-check-certificate -q -T10 -O speedtest.tgz ${url2}; then if [ $? -ne 0 ]; then
_red "Error: Failed to download speedtest-cli.\n" && exit 1 wget --no-check-certificate -q -T10 -O speedtest.tgz ${url2}
fi [ $? -ne 0 ] && _red "Error: Failed to download speedtest-cli.\n" && exit 1
fi fi
mkdir -p speedtest-cli && tar zxf speedtest.tgz -C ./speedtest-cli && chmod +x ./speedtest-cli/speedtest mkdir -p speedtest-cli && tar zxf speedtest.tgz -C ./speedtest-cli && chmod +x ./speedtest-cli/speedtest
rm -f speedtest.tgz rm -f speedtest.tgz
@ -267,22 +244,22 @@ get_system_info() {
LANG=C LANG=C
free | awk '/Mem/ {print $2}' free | awk '/Mem/ {print $2}'
) )
tram=$(calc_size "$tram") tram=$(calc_size $tram)
uram=$( uram=$(
LANG=C LANG=C
free | awk '/Mem/ {print $3}' free | awk '/Mem/ {print $3}'
) )
uram=$(calc_size "$uram") uram=$(calc_size $uram)
swap=$( swap=$(
LANG=C LANG=C
free | awk '/Swap/ {print $2}' free | awk '/Swap/ {print $2}'
) )
swap=$(calc_size "$swap") swap=$(calc_size $swap)
uswap=$( uswap=$(
LANG=C LANG=C
free | awk '/Swap/ {print $3}' free | awk '/Swap/ {print $3}'
) )
uswap=$(calc_size "$uswap") uswap=$(calc_size $uswap)
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) 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)
if _exists "w"; then if _exists "w"; then
load=$( load=$(
@ -300,23 +277,19 @@ get_system_info() {
if _exists "getconf"; then if _exists "getconf"; then
lbit=$(getconf LONG_BIT) lbit=$(getconf LONG_BIT)
else else
echo "${arch}" | grep -q "64" && lbit="64" || lbit="32" echo ${arch} | grep -q "64" && lbit="64" || lbit="32"
fi fi
kern=$(uname -r) kern=$(uname -r)
in_kernel_no_swap_total_size=$( disk_total_size=$(
LANG=C LANG=C
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs --total 2>/dev/null | grep total | awk '{ print $2 }' df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $2 }'
) )
swap_total_size=$(free -k | grep Swap | awk '{print $2}') disk_total_size=$(calc_size $disk_total_size)
zfs_total_size=$(to_kibyte "$(calc_sum "$(zpool list -o size -Hp 2> /dev/null)")") disk_used_size=$(
disk_total_size=$(calc_size $((swap_total_size + in_kernel_no_swap_total_size + zfs_total_size)))
in_kernel_no_swap_used_size=$(
LANG=C LANG=C
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs --total 2>/dev/null | grep total | awk '{ print $3 }' df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $3 }'
) )
swap_used_size=$(free -k | grep Swap | awk '{print $3}') disk_used_size=$(calc_size $disk_used_size)
zfs_used_size=$(to_kibyte "$(calc_sum "$(zpool list -o allocated -Hp 2> /dev/null)")")
disk_used_size=$(calc_size $((swap_used_size + in_kernel_no_swap_used_size + zfs_used_size)))
tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}') tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
} }
# Print System information # Print System information
@ -364,7 +337,7 @@ print_io_test() {
if [ -z "${freespace}" ]; then if [ -z "${freespace}" ]; then
freespace=$(df -m . | awk 'NR==3 {print $3}') freespace=$(df -m . | awk 'NR==3 {print $3}')
fi fi
if [ "${freespace}" -gt 1024 ]; then if [ ${freespace} -gt 1024 ]; then
writemb=2048 writemb=2048
io1=$(io_test ${writemb}) io1=$(io_test ${writemb})
echo " I/O Speed(1st run) : $(_yellow "$io1")" echo " I/O Speed(1st run) : $(_yellow "$io1")"
@ -372,14 +345,14 @@ print_io_test() {
echo " I/O Speed(2nd run) : $(_yellow "$io2")" echo " I/O Speed(2nd run) : $(_yellow "$io2")"
io3=$(io_test ${writemb}) io3=$(io_test ${writemb})
echo " I/O Speed(3rd run) : $(_yellow "$io3")" echo " I/O Speed(3rd run) : $(_yellow "$io3")"
ioraw1=$(echo "$io1" | awk 'NR==1 {print $1}') ioraw1=$(echo $io1 | awk 'NR==1 {print $1}')
[ "$(echo "$io1" | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw1=$(awk 'BEGIN{print '"$ioraw1"' * 1024}') [ "$(echo $io1 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw1=$(awk 'BEGIN{print '$ioraw1' * 1024}')
ioraw2=$(echo "$io2" | awk 'NR==1 {print $1}') ioraw2=$(echo $io2 | awk 'NR==1 {print $1}')
[ "$(echo "$io2" | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw2=$(awk 'BEGIN{print '"$ioraw2"' * 1024}') [ "$(echo $io2 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw2=$(awk 'BEGIN{print '$ioraw2' * 1024}')
ioraw3=$(echo "$io3" | awk 'NR==1 {print $1}') ioraw3=$(echo $io3 | awk 'NR==1 {print $1}')
[ "$(echo "$io3" | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw3=$(awk 'BEGIN{print '"$ioraw3"' * 1024}') [ "$(echo $io3 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw3=$(awk 'BEGIN{print '$ioraw3' * 1024}')
ioall=$(awk 'BEGIN{print '"$ioraw1"' + '"$ioraw2"' + '"$ioraw3"'}') ioall=$(awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}')
ioavg=$(awk 'BEGIN{printf "%.1f", '"$ioall"' / 3}') ioavg=$(awk 'BEGIN{printf "%.1f", '$ioall' / 3}')
echo " I/O Speed(average) : $(_yellow "$ioavg MB/s")" echo " I/O Speed(average) : $(_yellow "$ioavg MB/s")"
else else
echo " $(_red "Not enough space for I/O Speed test!")" echo " $(_red "Not enough space for I/O Speed test!")"
@ -388,10 +361,10 @@ print_io_test() {
print_end_time() { print_end_time() {
end_time=$(date +%s) end_time=$(date +%s)
time=$((end_time - start_time)) time=$((${end_time} - ${start_time}))
if [ ${time} -gt 60 ]; then if [ ${time} -gt 60 ]; then
min=$((time / 60)) min=$(expr $time / 60)
sec=$((time % 60)) sec=$(expr $time % 60)
echo " Finished in : ${min} min ${sec} sec" echo " Finished in : ${min} min ${sec} sec"
else else
echo " Finished in : ${time} sec" echo " Finished in : ${time} sec"
@ -403,11 +376,11 @@ print_end_time() {
! _exists "wget" && _red "Error: wget command not found.\n" && exit 1 ! _exists "wget" && _red "Error: wget command not found.\n" && exit 1
! _exists "free" && _red "Error: free command not found.\n" && exit 1 ! _exists "free" && _red "Error: free command not found.\n" && exit 1
# check for curl/wget # check for curl/wget
_exists "curl" && local_curl=true command -v curl >/dev/null 2>&1 && local_curl=true || unset local_curl
# test if the host has IPv4/IPv6 connectivity # test if the host has IPv4/IPv6 connectivity
[[ -n ${local_curl} ]] && ip_check_cmd="curl -s -m 4" || ip_check_cmd="wget -qO- -T 4" [[ ! -z ${local_curl} ]] && ip_check_cmd="curl -s -m 4" || ip_check_cmd="wget -qO- -T 4"
ipv4_check=$( (ping -4 -c 1 -W 4 ipv4.google.com >/dev/null 2>&1 && echo true) || ${ip_check_cmd} -4 icanhazip.com 2> /dev/null) ipv4_check=$((ping -4 -c 1 -W 4 ipv4.google.com >/dev/null 2>&1 && echo true) || ${ip_check_cmd} -4 icanhazip.com 2> /dev/null)
ipv6_check=$( (ping -6 -c 1 -W 4 ipv6.google.com >/dev/null 2>&1 && echo true) || ${ip_check_cmd} -6 icanhazip.com 2> /dev/null) ipv6_check=$((ping -6 -c 1 -W 4 ipv6.google.com >/dev/null 2>&1 && echo true) || ${ip_check_cmd} -6 icanhazip.com 2> /dev/null)
if [[ -z "$ipv4_check" && -z "$ipv6_check" ]]; then if [[ -z "$ipv4_check" && -z "$ipv6_check" ]]; then
_yellow "Warning: Both IPv4 and IPv6 connectivity were not detected.\n" _yellow "Warning: Both IPv4 and IPv6 connectivity were not detected.\n"
fi fi