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
12
runtest.sh
12
runtest.sh
|
@ -110,7 +110,6 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
packet_loss=$(ping -c $PING_COUNT -q $PING_TARGET | grep -oP '\d+(?=% packet loss)')
|
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}')
|
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() {
|
run_iperf() {
|
||||||
local target="$1"
|
local target="$1"
|
||||||
local mode="$2"
|
local mode="$2"
|
||||||
|
@ -125,8 +124,11 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
args+=("--reverse")
|
args+=("--reverse")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local tmp_err
|
||||||
|
tmp_err=$(mktemp)
|
||||||
|
|
||||||
local result
|
local result
|
||||||
result=$(iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
result=$(iperf3 "${args[@]}" 2>"$tmp_err" | jq -r '
|
||||||
if .error then
|
if .error then
|
||||||
"iperf3-error"
|
"iperf3-error"
|
||||||
elif has("end") | not then
|
elif has("end") | not then
|
||||||
|
@ -141,12 +143,16 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
|
|
||||||
if [[ "$result" == "iperf3-error" || "$result" == "no-end" || "$result" == "unexpected-format" || "$result" == "execution-failed" ]]; then
|
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 "$(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
|
else
|
||||||
echo "$result"
|
echo "$result"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$tmp_err"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo " Running iperf3 tests..."
|
echo " Running iperf3 tests..."
|
||||||
|
|
||||||
# Run them all. These are in bits per second, convert as needed later.
|
# Run them all. These are in bits per second, convert as needed later.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue