Files
box/bin/cdp-latency-check.sh
T

34 lines
1.1 KiB
Bash
Raw Normal View History

#!/bin/bash
# cdp-latency-check.sh — measure CDP relay latency per node.
#
# Probes each node's host-side relay (PEER_IP:CDP_PORT from netvm-names.sh,
# which pins the registry ports) at /json/version and prints one line per
# node:
# name:latency_ms:code
# On failure (timeout / connection refused / non-200-ish transport error):
# name:FAIL:000
#
# Self-contained: only needs netvm-names.sh in the same directory and curl.
set -u
BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1091
source "$BIN_DIR/netvm-names.sh"
TIMEOUT_S=10
for node in muse pip 646 opm; do
netvm_names "$node"
url="http://${PEER_IP}:${CDP_PORT}/json/version"
probe=$(curl -s -m "$TIMEOUT_S" -o /dev/null -w "%{time_total} %{http_code}" "$url" 2>/dev/null)
rc=$?
secs=$(printf '%s' "$probe" | awk '{print $1}')
code=$(printf '%s' "$probe" | awk '{print $2}')
if [ "$rc" -ne 0 ] || [ -z "$code" ] || [ "$code" = "000" ]; then
echo "${node}:FAIL:000"
continue
fi
ms=$(awk -v s="$secs" 'BEGIN { printf "%d", (s + 0) * 1000 }')
echo "${node}:${ms}:${code}"
done