2024-01-01 17:42:17 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
|
2024-01-02 05:16:22 +01:00
|
|
|
node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"}
|
2024-01-01 17:42:17 +01:00
|
|
|
shift 2
|
|
|
|
|
2024-01-02 07:33:24 +01:00
|
|
|
if [[ $node == node-* ]]; then
|
|
|
|
index=${node#node-}
|
|
|
|
host="10.55.$index.77"
|
|
|
|
else
|
|
|
|
host=$node
|
|
|
|
fi
|
|
|
|
|
2024-01-01 17:42:17 +01:00
|
|
|
connect_timeout_sec=3
|
|
|
|
|
|
|
|
function with_set_x() {
|
|
|
|
set -x
|
|
|
|
"$@"
|
|
|
|
{
|
|
|
|
ec=$?
|
|
|
|
set +x
|
|
|
|
return $ec
|
|
|
|
} 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$tool" in
|
|
|
|
ping)
|
2024-01-02 07:33:24 +01:00
|
|
|
with_set_x exec ping -W $connect_timeout_sec "$@" "$host"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
iperf3)
|
|
|
|
port=5001
|
2024-01-02 07:33:24 +01:00
|
|
|
with_set_x exec iperf3 --client "$host" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "$@"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
curl)
|
|
|
|
port=8080
|
2024-01-02 07:33:24 +01:00
|
|
|
with_set_x exec curl "http://$host:$port/" -v --connect-timeout $connect_timeout_sec "$@"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
ab)
|
|
|
|
port=8080
|
2024-01-02 07:33:24 +01:00
|
|
|
if [[ " $*" != *" -n "* && " $*" != *" -c "* ]]; then
|
|
|
|
set -- -n 500 -c 50 "$@"
|
|
|
|
fi
|
|
|
|
with_set_x exec ab -s $connect_timeout_sec "$@" "http://$host:$port/"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
2024-01-02 05:16:22 +01:00
|
|
|
*)
|
|
|
|
echo "Unknown tool: $tool" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
2024-01-01 17:42:17 +01:00
|
|
|
esac
|