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)')
|
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"
|
||||||
local direction="$3"
|
local direction="$3"
|
||||||
local args=("-c" "$target" "-J" "-t" "10")
|
local args=("-c" "$target" "-J" "-t" "10")
|
||||||
|
|
||||||
if [ "$mode" = "udp" ]; then
|
if [ "$mode" = "udp" ]; then
|
||||||
args+=("-u")
|
args+=("-u")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$direction" = "down" ]; then
|
if [ "$direction" = "down" ]; then
|
||||||
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
|
||||||
|
@ -138,15 +140,19 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
||||||
else
|
else
|
||||||
"unexpected-format"
|
"unexpected-format"
|
||||||
end' || echo "execution-failed")
|
end' || echo "execution-failed")
|
||||||
|
|
||||||
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