You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
Bash
55 lines
1.9 KiB
Bash
#!/bin/bash
|
|
SCRIPT_NAME=$(basename ${BASH_SOURCE[0]})
|
|
|
|
if ! which jq >/dev/null; then
|
|
logError "${SCRIPT_NAME}: Did not find jq in path!"
|
|
return
|
|
elif ! which iperf3 >/dev/null; then
|
|
logError "${SCRIPT_NAME}: Did not find iperf3 in path!"
|
|
return
|
|
fi
|
|
|
|
# Usage: doIperfTest <target-host> [<time>] [<additional-iperf-args>]
|
|
function doIperfTest {
|
|
HOST="${1}"
|
|
shift
|
|
|
|
TIME=10
|
|
if ! [ "${1}" = "" ]; then
|
|
TIME=${1}
|
|
LOG_SUFFIX=" for ${TIME} seconds"
|
|
shift
|
|
fi
|
|
|
|
logScript "Doing IPerf3 test to ${HOST}${LOG_SUFFIX}"
|
|
|
|
OUT=$(iperf3 -c "${HOST}" -t ${TIME} -i0 -J ${@})
|
|
|
|
SUCCESS=$( [ "$(echo ${OUT} | jq -r .error)" = null ] && echo true || echo false )
|
|
PROTO=$(echo ${OUT} | jq -r .start.test_start.protocol)
|
|
REMOTE_HOST=$(echo ${OUT} | jq -r .start.connected[0].remote_host)
|
|
REMOTE_PORT=$(echo ${OUT} | jq -r .start.connected[0].remote_port)
|
|
|
|
NUM_STREAMS=$(echo ${OUT} | jq -r .start.test_start.num_streams)
|
|
REVERSE=$(echo ${OUT} | jq -r .start.test_start.reverse)
|
|
SENT_SECONDS=$(echo ${OUT} | jq -r .end.sum_sent.seconds)
|
|
SENT_BPS=$(echo ${OUT} | jq -r .end.sum_sent.bits_per_second)
|
|
SENT_RETRANSMITS=$(echo ${OUT} | jq -r .end.sum_sent.retransmits)
|
|
RECEIVED_SECONDS=$(echo ${OUT} | jq -r .end.sum_received.seconds)
|
|
RECEIVED_BPS=$(echo ${OUT} | jq -r .end.sum_received.bits_per_second)
|
|
|
|
if ! [ "${SUCCESS}" = "true" ]; then
|
|
NUM_STREAMS=0
|
|
REVERSE=0
|
|
SENT_SECONDS=0
|
|
SENT_BPS=0
|
|
SENT_RETRANSMITS=0
|
|
RECEIVED_SECONDS=0
|
|
RECEIVED_BPS=0
|
|
fi
|
|
|
|
writeData \
|
|
iperf3 \
|
|
"sourceHost=$(hostname -f),targetHost=${HOST}" \
|
|
"success=${SUCCESS},connected_host=\"${REMOTE_HOST}:${REMOTE_PORT}\",proto=\"${PROTO}\",num_streams=${NUM_STREAMS},reverse=${REVERSE},retransmits=${SENT_RETRANSMITS},sent_seconds=${SENT_SECONDS},sent_bps=${SENT_BPS},received_seconds=${RECEIVED_SECONDS},received_bps=${RECEIVED_BPS}"
|
|
} |