Skip to content

Commit 717911b

Browse files
authored
Feats: Add Custom Iperf3 Server Option (#113)
* add geekbench v6 in main comments * add iperf3 customs servers argument * remove confusing comma in help message
1 parent 35ee337 commit 717911b

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

yabs.sh

100644100755
Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
# Purpose: The purpose of this script is to quickly gauge the performance of a Linux-
1010
# based server by benchmarking network performance via iperf3, CPU and
11-
# overall system performance via Geekbench 4/5, and random disk
11+
# overall system performance via Geekbench 4/5/6, and random disk
1212
# performance via fio. The script is designed to not require any dependencies
1313
# - either compiled or installed - nor admin privileges to run.
1414

@@ -59,11 +59,11 @@ else
5959
fi
6060

6161
# flags to skip certain performance tests
62-
unset PREFER_BIN SKIP_FIO SKIP_IPERF SKIP_GEEKBENCH SKIP_NET PRINT_HELP REDUCE_NET GEEKBENCH_4 GEEKBENCH_5 GEEKBENCH_6 DD_FALLBACK IPERF_DL_FAIL JSON JSON_SEND JSON_RESULT JSON_FILE
62+
unset PREFER_BIN SKIP_FIO SKIP_IPERF SKIP_GEEKBENCH SKIP_NET PRINT_HELP REDUCE_NET GEEKBENCH_4 GEEKBENCH_5 GEEKBENCH_6 DD_FALLBACK IPERF_DL_FAIL JSON JSON_SEND JSON_RESULT JSON_FILE IPERF_SERVERS
6363
GEEKBENCH_6="True" # gb6 test enabled by default
6464

6565
# get any arguments that were passed to the script and set the associated skip flags (if applicable)
66-
while getopts 'bfdignhr4596jw:s:' flag; do
66+
while getopts 'bfdignhr4596jw:s:p:' flag; do
6767
case "${flag}" in
6868
b) PREFER_BIN="True" ;;
6969
f) SKIP_FIO="True" ;;
@@ -77,9 +77,10 @@ while getopts 'bfdignhr4596jw:s:' flag; do
7777
5) GEEKBENCH_5="True" && unset GEEKBENCH_6 ;;
7878
9) GEEKBENCH_4="True" && GEEKBENCH_5="True" && unset GEEKBENCH_6 ;;
7979
6) GEEKBENCH_6="True" ;;
80-
j) JSON+="j" ;;
80+
j) JSON+="j" ;;
8181
w) JSON+="w" && JSON_FILE=${OPTARG} ;;
82-
s) JSON+="s" && JSON_SEND=${OPTARG} ;;
82+
s) JSON+="s" && JSON_SEND=${OPTARG} ;;
83+
p) IPERF_SERVERS=${OPTARG} ;;
8384
*) exit 1 ;;
8485
esac
8586
done
@@ -148,6 +149,9 @@ if [ -n "$PRINT_HELP" ]; then
148149
echo -e " -j : print jsonified YABS results at conclusion of test"
149150
echo -e " -w <filename> : write jsonified YABS results to disk using file name provided"
150151
echo -e " -s <url> : send jsonified YABS results to URL"
152+
echo -e " -p <servers> : specify custom iperf servers (format: host:port_range:name:location:network_modes)"
153+
echo -e " multiple servers separated by commas"
154+
echo -e " example: -p \"example.com:5201-5210:MyServer:New York (10G):IPv4|IPv6\""
151155
echo -e
152156
echo -e "Detected Arch: $ARCH"
153157
echo -e
@@ -161,6 +165,7 @@ if [ -n "$PRINT_HELP" ]; then
161165
[[ -n $GEEKBENCH_4 ]] && echo -e " running geekbench 4"
162166
[[ -n $GEEKBENCH_5 ]] && echo -e " running geekbench 5"
163167
[[ -n $GEEKBENCH_6 ]] && echo -e " running geekbench 6"
168+
[[ -n $IPERF_SERVERS ]] && echo -e " -p, using custom iperf servers: $IPERF_SERVERS"
164169
echo -e
165170
echo -e "Local Binary Check:"
166171
([[ -z $LOCAL_FIO ]] && echo -e " fio not detected, will download precompiled binary") ||
@@ -180,7 +185,7 @@ if [ -n "$PRINT_HELP" ]; then
180185
[[ -z $JSON ]] && echo -e " none"
181186
[[ $JSON = *j* ]] && echo -e " printing json to screen after test"
182187
[[ $JSON = *w* ]] && echo -e " writing json to file ($JSON_FILE) after test"
183-
[[ $JSON = *s* ]] && echo -e " sharing json YABS results to $JSON_SEND"
188+
[[ $JSON = *s* ]] && echo -e " sharing json YABS results to $JSON_SEND"
184189
echo -e
185190
echo -e "Exiting..."
186191

@@ -202,7 +207,7 @@ function format_size {
202207
# ensure the raw value is a number, otherwise return blank
203208
re='^[0-9]+$'
204209
if ! [[ $RAW =~ $re ]] ; then
205-
echo ""
210+
echo ""
206211
return 0
207212
fi
208213

@@ -227,7 +232,7 @@ function format_size {
227232
}
228233

229234
# gather basic system information (inc. CPU, AES-NI/virt status, RAM + swap + disk size)
230-
echo -e
235+
echo -e
231236
echo -e "Basic System Information:"
232237
echo -e "---------------------------------"
233238
UPTIME=$(uptime | awk -F'( |,|:)+' '{d=h=m=0; if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes"}')
@@ -288,7 +293,7 @@ function ip_info() {
288293

289294
# declare local vars
290295
local ip6me_resp net_type net_ip response country region region_code city isp org as
291-
296+
292297
ip6me_resp="$($DL_CMD http://ip6.me/api/)"
293298
net_type="$(echo "$ip6me_resp" | cut -d, -f1)"
294299
net_ip="$(echo "$ip6me_resp" | cut -d, -f2)"
@@ -307,7 +312,7 @@ function ip_info() {
307312
isp=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^isp/ {print $2}' | sed 's/^"\(.*\)"$/\1/')
308313
org=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^org/ {print $2}' | sed 's/^"\(.*\)"$/\1/')
309314
as=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^as/ {print $2}' | sed 's/^"\(.*\)"$/\1/')
310-
315+
311316
echo
312317
echo "$net_type Network Information:"
313318
echo "---------------------------------"
@@ -330,7 +335,7 @@ function ip_info() {
330335
fi
331336
if [[ -n "$country" ]]; then
332337
echo "Country : $country"
333-
fi
338+
fi
334339

335340
[[ -n $JSON ]] && JSON_RESULT+=',"ip_info":{"protocol":"'$net_type'","isp":"'$isp'","asn":"'$as'","org":"'$org'","city":"'$city'","region":"'$region'","region_code":"'$region_code'","country":"'$country'"}'
336341
}
@@ -489,7 +494,7 @@ function disk_test {
489494

490495
# dd_test
491496
# Purpose: This method is invoked if the fio disk test failed. dd sequential speed tests are
492-
# not indiciative or real-world results, however, some form of disk speed measure
497+
# not indiciative or real-world results, however, some form of disk speed measure
493498
# is better than nothing.
494499
# Parameters:
495500
# - (none)
@@ -691,8 +696,8 @@ fi
691696
echo -e "---------------------------------"
692697
printf "%-6s | %-6s %-4s | %-6s %-4s | %-6s %-4s | %-6s %-4s\n" "" "Test 1" "" "Test 2" "" "Test 3" "" "Avg" ""
693698
printf "%-6s | %-6s %-4s | %-6s %-4s | %-6s %-4s | %-6s %-4s\n" "" "" "" "" "" "" "" "" ""
694-
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Write" "${DISK_WRITE_TEST_RES[0]}" "${DISK_WRITE_TEST_RES[1]}" "${DISK_WRITE_TEST_RES[2]}" "${DISK_WRITE_TEST_AVG}" "${DISK_WRITE_TEST_UNIT}"
695-
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Read" "${DISK_READ_TEST_RES[0]}" "${DISK_READ_TEST_RES[1]}" "${DISK_READ_TEST_RES[2]}" "${DISK_READ_TEST_AVG}" "${DISK_READ_TEST_UNIT}"
699+
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Write" "${DISK_WRITE_TEST_RES[0]}" "${DISK_WRITE_TEST_RES[1]}" "${DISK_WRITE_TEST_RES[2]}" "${DISK_WRITE_TEST_AVG}" "${DISK_WRITE_TEST_UNIT}"
700+
printf "%-6s | %-11s | %-11s | %-11s | %-6.2f %-4s\n" "Read" "${DISK_READ_TEST_RES[0]}" "${DISK_READ_TEST_RES[1]}" "${DISK_READ_TEST_RES[2]}" "${DISK_READ_TEST_AVG}" "${DISK_READ_TEST_UNIT}"
696701
else # fio tests completed successfully, print results
697702
CURRENT_PARTITION=$(df -P . 2>/dev/null | tail -1 | cut -d' ' -f 1)
698703
[[ -n $JSON ]] && JSON_RESULT+=',"partition":"'$CURRENT_PARTITION'","fio":['
@@ -726,7 +731,7 @@ fi
726731

727732
# iperf_test
728733
# Purpose: This method is designed to test the network performance of the host by executing an
729-
# iperf3 test to/from the public iperf server passed to the function. Both directions
734+
# iperf3 test to/from the public iperf server passed to the function. Both directions
730735
# (send and receive) are tested.
731736
# Parameters:
732737
# 1. URL - URL/domain name of the iperf server
@@ -738,7 +743,7 @@ function iperf_test {
738743
PORTS=$2
739744
HOST=$3
740745
FLAGS=$4
741-
746+
742747
# attempt the iperf send test 3 times, allowing for a slot to become available on the
743748
# server or to throw out any bad/error results
744749
I=1
@@ -791,9 +796,9 @@ function iperf_test {
791796
fi
792797
echo -en "\r\033[0K"
793798
done
794-
799+
795800
# Run a latency test via ping -c1 command -> will return "xx.x ms"
796-
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 "$URL" 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
801+
[[ -n $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 "$URL" 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)"
797802
[[ -z $LATENCY_RUN ]] && LATENCY_RUN="--"
798803

799804
# parse the resulting send and receive speed results
@@ -817,7 +822,7 @@ function launch_iperf {
817822
echo -e "---------------------------------"
818823
printf "%-15s | %-25s | %-15s | %-15s | %-15s\n" "Provider" "Location (Link)" "Send Speed" "Recv Speed" "Ping"
819824
printf "%-15s | %-25s | %-15s | %-15s | %-15s\n" "-----" "-----" "----" "----" "----"
820-
825+
821826
# loop through iperf locations array to run iperf test using each public iperf server
822827
for (( i = 0; i < IPERF_LOCS_NUM; i++ )); do
823828
# test if the current iperf location supports the network mode being tested (IPv4/IPv6)
@@ -867,7 +872,7 @@ if [ -z "$SKIP_IPERF" ]; then
867872
IPERF_CMD=$IPERF_PATH/iperf3
868873
fi
869874
fi
870-
875+
871876
# array containing all currently available iperf3 public servers to use for the network test
872877
# format: "1" "2" "3" "4" "5" \
873878
# 1. domain name of the iperf server
@@ -896,11 +901,29 @@ if [ -z "$SKIP_IPERF" ]; then
896901
"speedtest.nyc1.us.leaseweb.net" "5201-5210" "Leaseweb" "NYC, NY, US (10G)" "IPv4|IPv6" \
897902
)
898903
fi
899-
904+
905+
# if custom iperf servers are provided, use them instead of the default servers
906+
if [ -n "$IPERF_SERVERS" ]; then
907+
# clear the default iperf locations array
908+
IPERF_LOCS=()
909+
910+
# parse the custom iperf servers and add them to the array
911+
IFS=',' read -ra CUSTOM_SERVERS <<< "$IPERF_SERVERS"
912+
for server in "${CUSTOM_SERVERS[@]}"; do
913+
# parse server definition: host:port_range:name:location:network_modes
914+
IFS=':' read -ra SERVER_PARTS <<< "$server"
915+
if [ ${#SERVER_PARTS[@]} -eq 5 ]; then
916+
IPERF_LOCS+=("${SERVER_PARTS[0]}" "${SERVER_PARTS[1]}" "${SERVER_PARTS[2]}" "${SERVER_PARTS[3]}" "${SERVER_PARTS[4]}")
917+
else
918+
echo -e "Invalid server format: $server (expected format: host:port_range:name:location:network_modes)"
919+
fi
920+
done
921+
fi
922+
900923
# get the total number of iperf locations (total array size divided by 5 since each location has 5 elements)
901924
IPERF_LOCS_NUM=${#IPERF_LOCS[@]}
902925
IPERF_LOCS_NUM=$((IPERF_LOCS_NUM / 5))
903-
926+
904927
if [ -z "$IPERF_DL_FAIL" ]; then
905928
[[ -n $JSON ]] && JSON_RESULT+=',"iperf":['
906929
# check if the host has IPv4 connectivity, if so, run iperf3 IPv4 tests
@@ -914,7 +937,7 @@ if [ -z "$SKIP_IPERF" ]; then
914937
fi
915938

916939
# launch_geekbench
917-
# Purpose: This method is designed to run the Primate Labs' Geekbench 4/5 Cross-Platform Benchmark utility
940+
# Purpose: This method is designed to run the Primate Labs' Geekbench 4/5/6 Cross-Platform Benchmark utility
918941
# Parameters:
919942
# 1. VERSION - indicates which Geekbench version to run
920943
function launch_geekbench {
@@ -999,10 +1022,10 @@ function launch_geekbench {
9991022
# parse the public results page for the single and multi core geekbench scores
10001023
[[ $VERSION == *4* ]] && GEEKBENCH_SCORES=$($DL_CMD "$GEEKBENCH_URL" | grep "span class='score'") || \
10011024
GEEKBENCH_SCORES=$($DL_CMD "$GEEKBENCH_URL" | grep "div class='score'")
1002-
1025+
10031026
GEEKBENCH_SCORES_SINGLE=$(echo "$GEEKBENCH_SCORES" | awk -v FS="(>|<)" '{ print $3 }' | head -n 1)
10041027
GEEKBENCH_SCORES_MULTI=$(echo "$GEEKBENCH_SCORES" | awk -v FS="(>|<)" '{ print $3 }' | tail -n 1)
1005-
1028+
10061029
# print the Geekbench results
10071030
echo -en "\r\033[0K"
10081031
echo -e "Geekbench $VERSION Benchmark Test:"

0 commit comments

Comments
 (0)