add web UI maintenance toggles: monitor quiet mode + shutdown-web

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
d4nn13andClaude Opus 4.7 committed 2026-04-23 20:19:03 +02:00
1 parent b1085fd23c
commit 0313fb6af8
9 files changed
+197 -6

No files matched your search

+25 -6
View File
@@ -1,8 +1,13 @@
#!/bin/bash
# Edited with Claude Code
# wirecon-monitor.sh — long-running observer. Emits one structured log line
# every MONITOR_INTERVAL seconds with handshake age, throughput deltas,
# endpoint, and in-tunnel RTT. Designed to make silent-death diagnosable
# after the fact via journalctl.
#
# Quiet mode: when MONITOR_QUIET=yes, switches to MONITOR_QUIET_INTERVAL
# and suppresses info-level lines (warn/error still emitted). Toggle from
# the web UI once the link is stable to cut log volume + wake-ups.
set -uo pipefail
@@ -13,6 +18,16 @@ CONF="${WIRECON_CONF:-/etc/wirecon/wirecon.conf}"
: "${WG_INTERFACE:=wg0}"
: "${PEER_IP:=10.42.0.1}"
: "${MONITOR_INTERVAL:=10}"
: "${MONITOR_QUIET:=no}"
: "${MONITOR_QUIET_INTERVAL:=60}"
if [[ "$MONITOR_QUIET" == "yes" ]]; then
ACTIVE_INTERVAL="$MONITOR_QUIET_INTERVAL"
QUIET=1
else
ACTIVE_INTERVAL="$MONITOR_INTERVAL"
QUIET=0
fi
prev_rx=""
prev_tx=""
@@ -22,6 +37,8 @@ prev_mtu=""
log() {
local level="$1"; shift
# In quiet mode, drop info-level chatter. Warn/error always emit.
if [[ "$QUIET" -eq 1 && "$level" == "info" ]]; then return; fi
printf 'level=%s ts=%s %s\n' "$level" "$(date -u +%FT%TZ)" "$*"
}
@@ -34,12 +51,14 @@ rtt_probe() {
echo "$rtt"
}
log info "event=monitor_start iface=$WG_INTERFACE peer_ip=$PEER_IP interval=${MONITOR_INTERVAL}s"
# monitor_start is logged at warn so it's visible even after a quiet-mode
# restart — useful for confirming the toggle landed.
log warn "event=monitor_start iface=$WG_INTERFACE peer_ip=$PEER_IP interval=${ACTIVE_INTERVAL}s quiet=$MONITOR_QUIET"
while :; do
if ! ip link show "$WG_INTERFACE" >/dev/null 2>&1; then
log warn "event=iface_missing iface=$WG_INTERFACE"
sleep "$MONITOR_INTERVAL"
sleep "$ACTIVE_INTERVAL"
continue
fi
@@ -49,7 +68,7 @@ while :; do
dump=$(wg show "$WG_INTERFACE" dump 2>/dev/null | awk 'NR==2')
if [[ -z "$dump" ]]; then
log warn "event=no_peer_dump iface=$WG_INTERFACE"
sleep "$MONITOR_INTERVAL"
sleep "$ACTIVE_INTERVAL"
continue
fi
@@ -66,8 +85,8 @@ while :; do
# byte deltas (bps averaged over interval)
rx_bps="-"; tx_bps="-"
if [[ -n "$prev_rx" && -n "$prev_tx" ]]; then
rx_bps=$(( (rx - prev_rx) * 8 / MONITOR_INTERVAL ))
tx_bps=$(( (tx - prev_tx) * 8 / MONITOR_INTERVAL ))
rx_bps=$(( (rx - prev_rx) * 8 / ACTIVE_INTERVAL ))
tx_bps=$(( (tx - prev_tx) * 8 / ACTIVE_INTERVAL ))
fi
rtt=$(rtt_probe)
@@ -88,5 +107,5 @@ while :; do
log "$level" "event=tick iface=$WG_INTERFACE endpoint=$endpoint handshake_age=${hs_age}s mtu=$mtu rtt_ms=$rtt rx_bps=$rx_bps tx_bps=$tx_bps rx_total=$rx tx_total=$tx${notes}"
prev_rx="$rx"; prev_tx="$tx"; prev_hs="$hs_ts"; prev_ep="$endpoint"; prev_mtu="$mtu"
sleep "$MONITOR_INTERVAL"
sleep "$ACTIVE_INTERVAL"
done