ops: amanita-probe ref/edge fields + README Verify

This commit is contained in:
Hernâni Marques 2026-09-24 20:42:33 +02:00
parent a10de8f0a9
commit e01fbedcd8
No known key found for this signature in database
2 changed files with 28 additions and 3 deletions

View file

@ -60,6 +60,7 @@ koopa-amanita-probe show
ssh amanita-probe # should print one HB line, no shell ssh amanita-probe # should print one HB line, no shell
# gaps after a freeze: look for icmp=fail/ssh=fail with large gap_s= # gaps after a freeze: look for icmp=fail/ssh=fail with large gap_s=
# also: ref= (rabbithole ICMP) and edge= on icmp/ssh pair change
``` ```
## Uninstall ## Uninstall

View file

@ -14,6 +14,7 @@
# AMANITA_PROBE_USER default vx # AMANITA_PROBE_USER default vx
# AMANITA_PROBE_KEY default ~/.ssh/id_ed25519_amanita_probe # AMANITA_PROBE_KEY default ~/.ssh/id_ed25519_amanita_probe
# AMANITA_PROBE_STATE default ~/.local/state/amanita-probe # AMANITA_PROBE_STATE default ~/.local/state/amanita-probe
# AMANITA_PROBE_REF second ICMP target (default 192.168.100.3, rabbithole)
set +e set +e
set +u set +u
@ -27,6 +28,7 @@ LAST="${STATE}/amanita-probe.last"
META="${STATE}/amanita-probe.meta" META="${STATE}/amanita-probe.meta"
SSH_TO="${AMANITA_PROBE_SSH_TIMEOUT:-5}" SSH_TO="${AMANITA_PROBE_SSH_TIMEOUT:-5}"
PING_TO="${AMANITA_PROBE_PING_TIMEOUT:-2}" PING_TO="${AMANITA_PROBE_PING_TIMEOUT:-2}"
REF="${AMANITA_PROBE_REF:-192.168.100.3}"
mkdir -p "${STATE}" 2>/dev/null || true mkdir -p "${STATE}" 2>/dev/null || true
@ -54,11 +56,22 @@ do_status() {
do_once() { do_once() {
local ts icmp ssh hb gap prev_ts prev_epoch now_epoch local ts icmp ssh hb gap prev_ts prev_epoch now_epoch
local old_icmp old_ssh old_pair new_pair edge ref
ts="$(date -Iseconds)" ts="$(date -Iseconds)"
now_epoch="$(date +%s)" now_epoch="$(date +%s)"
icmp=fail icmp=fail
ssh=fail ssh=fail
hb="-" hb="-"
old_icmp=""
old_ssh=""
old_pair=""
if [ -f "${LAST}" ]; then
old_icmp="$(awk '{for(i=1;i<=NF;i++) if($i ~ /^icmp=/){sub(/^icmp=/,"",$i); print $i; exit}}' "${LAST}" 2>/dev/null)"
old_ssh="$(awk '{for(i=1;i<=NF;i++) if($i ~ /^ssh=/){sub(/^ssh=/,"",$i); print $i; exit}}' "${LAST}" 2>/dev/null)"
if [ -n "${old_icmp}" ] && [ -n "${old_ssh}" ]; then
old_pair="${old_icmp}/${old_ssh}"
fi
fi
if ping -c1 -W "${PING_TO}" "${HOST}" >/dev/null 2>&1; then if ping -c1 -W "${PING_TO}" "${HOST}" >/dev/null 2>&1; then
icmp=ok icmp=ok
@ -74,7 +87,7 @@ do_once() {
-o ConnectTimeout="${SSH_TO}" -o ConnectionAttempts=1 \ -o ConnectTimeout="${SSH_TO}" -o ConnectionAttempts=1 \
-o PreferredAuthentications=publickey \ -o PreferredAuthentications=publickey \
"${USER_R}@${HOST}" true 2>/dev/null \ "${USER_R}@${HOST}" true 2>/dev/null \
| tr '\n' ' ' | tr -s ' ' | head -c 400 | tr '\n' ' ' | tr -s ' ' | head -c 800
)" )"
if [ -n "${hb}" ]; then if [ -n "${hb}" ]; then
ssh=ok ssh=ok
@ -97,9 +110,19 @@ do_once() {
fi fi
fi fi
ref=fail
if ping -c1 -W "${PING_TO}" "${REF}" >/dev/null 2>&1; then
ref=ok
fi
new_pair="${icmp}/${ssh}"
edge=""
if [ -n "${old_pair}" ] && [ "${old_pair}" != "${new_pair}" ]; then
edge=" edge=${old_pair}>${new_pair}"
fi
local line local line
line="$(printf '%s icmp=%s ssh=%s gap_s=%s host=%s user=%s hb=%s' \ line="$(printf '%s icmp=%s ssh=%s gap_s=%s host=%s user=%s ref=%s%s hb=%s' \
"${ts}" "${icmp}" "${ssh}" "${gap}" "${HOST}" "${USER_R}" "${hb}")" "${ts}" "${icmp}" "${ssh}" "${gap}" "${HOST}" "${USER_R}" "${ref}" "${edge}" "${hb}")"
printf '%s\n' "${line}" >>"${LOG}" printf '%s\n' "${line}" >>"${LOG}"
printf '%s\n' "${line}" >"${LAST}" printf '%s\n' "${line}" >"${LAST}"
@ -109,6 +132,7 @@ do_once() {
echo "icmp=${icmp}" echo "icmp=${icmp}"
echo "ssh=${ssh}" echo "ssh=${ssh}"
echo "gap_s=${gap}" echo "gap_s=${gap}"
echo "ref=${ref}"
} >"${META}" } >"${META}"
# Keep log bounded (~14d at 15s ≈ 80k lines; rotate soft at 200k lines) # Keep log bounded (~14d at 15s ≈ 80k lines; rotate soft at 200k lines)