2026-10-04 18:34:52 +00:00
|
|
|
#!/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
|
|
|
|
|
|
2026-10-06 19:28:29 +00:00
|
|
|
# Registry-driven node list (was hardcoded 4 nodes; def/dev had no
|
|
|
|
|
# cdp-latency coverage — 2026-10-06).
|
|
|
|
|
watched_nodes() {
|
|
|
|
|
"$BIN_DIR/netvm-registry.py" 2>/dev/null | cut -d: -f1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Allow sourcing for tests without running checks.
|
|
|
|
|
if [ "${CDP_LATENCY_CHECK_LIB_ONLY:-}" = "1" ]; then
|
|
|
|
|
return 0 2>/dev/null || exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
NODES="$(watched_nodes)"
|
|
|
|
|
if [ -z "$NODES" ]; then
|
|
|
|
|
echo "node registry empty/unreadable" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086 (intended word splitting: one node per word)
|
|
|
|
|
for node in $NODES; do
|
2026-10-04 18:34:52 +00:00
|
|
|
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
|