Add cdp-latency-check.sh and box cdp-latency action

Proper script replacing the inline-SSH latency monitor. Probes each relay /json/version via pinned ports from netvm-names.sh, outputs name:latency_ms:code per node. box-ctl.py cdp-latency runs it and returns JSON.
This commit is contained in:
operator-main
2026-10-04 18:34:52 +00:00
parent 882dfd8254
commit a76a776a87
2 changed files with 65 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/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