Improve iperf3 error handling in runtest.sh by capturing stderr and logging detailed error messages
This commit is contained in:
parent
cb3278b280
commit
26c3927e75
1 changed files with 13 additions and 7 deletions
20
runtest.sh
20
runtest.sh
|
@ -110,23 +110,25 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
|||
packet_loss=$(ping -c $PING_COUNT -q $PING_TARGET | grep -oP '\d+(?=% packet loss)')
|
||||
jitter=$(ping -c $PING_COUNT $PING_TARGET | grep "time=" | awk '{print $(NF-1)}' | sed 's/time=//g' | awk '{sum+=$1; sumsq+=$1*$1} END {if (NR>1) print sqrt(sumsq/NR - (sum/NR)**2); else print 0}')
|
||||
|
||||
# iperf3 function
|
||||
run_iperf() {
|
||||
local target="$1"
|
||||
local mode="$2"
|
||||
local direction="$3"
|
||||
local args=("-c" "$target" "-J" "-t" "10")
|
||||
|
||||
|
||||
if [ "$mode" = "udp" ]; then
|
||||
args+=("-u")
|
||||
fi
|
||||
|
||||
|
||||
if [ "$direction" = "down" ]; then
|
||||
args+=("--reverse")
|
||||
fi
|
||||
|
||||
|
||||
local tmp_err
|
||||
tmp_err=$(mktemp)
|
||||
|
||||
local result
|
||||
result=$(iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
||||
result=$(iperf3 "${args[@]}" 2>"$tmp_err" | jq -r '
|
||||
if .error then
|
||||
"iperf3-error"
|
||||
elif has("end") | not then
|
||||
|
@ -138,15 +140,19 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
|||
else
|
||||
"unexpected-format"
|
||||
end' || echo "execution-failed")
|
||||
|
||||
|
||||
if [[ "$result" == "iperf3-error" || "$result" == "no-end" || "$result" == "unexpected-format" || "$result" == "execution-failed" ]]; then
|
||||
echo "$(date -Iseconds),iperf $mode $direction to $target failed with '$result'" >> "$FAILURE_LOG"
|
||||
echo "0" # Fallback value for CSV
|
||||
echo "[stderr] $(cat "$tmp_err")" >> "$FAILURE_LOG"
|
||||
echo "0"
|
||||
else
|
||||
echo "$result"
|
||||
fi
|
||||
|
||||
rm -f "$tmp_err"
|
||||
}
|
||||
|
||||
|
||||
echo " Running iperf3 tests..."
|
||||
|
||||
# Run them all. These are in bits per second, convert as needed later.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue