#!/bin/bash # 公网间歇 530 —— 查隧道当前真实状态 set -u echo " relay=$(systemctl is-active lanremote-relay) tunnel=$(systemctl is-active lanremote-tunnel)" echo " 隧道连接数: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')" echo echo "════════ watchdog 最近 15 行 ════════" tail -15 /root/lanremote-relay/watchdog.log 2>/dev/null | sed 's/^/ /' echo echo "════════ watchdog 怎么被调起来的 ════════" echo " 服务: $(systemctl is-active lanremote-watchdog 2>&1)" crontab -l 2>/dev/null | grep -i watch | sed 's/^/ cron: /' systemctl list-timers --all 2>/dev/null | grep -i watch | sed 's/^/ timer: /' echo echo "════════ 隧道最近的重连频率(1500 行内)════════" for kw in 'Registered tunnel connection' 'Lost connection' 'Retrying connection' 'i/o timeout' 'context deadline'; do n=$(tail -1500 /root/lanremote-relay/tunnel.log 2>/dev/null | grep -c "$kw") printf " %-34s %s 次\n" "$kw" "$n" done echo echo "════════ 出口 IP 可达性 ════════" python3 - <<'PY' import socket, time ips = ["198.41.192.107", "198.41.200.43", "198.41.192.77", "198.41.200.113", "198.41.192.227", "198.41.200.193", "198.41.192.37", "198.41.200.63"] ok = 0 for ip in ips: s = socket.socket(); s.settimeout(3) t = time.perf_counter() try: s.connect((ip, 7844)) print(" %-16s %4.0f ms" % (ip, (time.perf_counter()-t)*1000)); ok += 1 except OSError: print(" %-16s 不通" % ip) finally: s.close() print(" => %d/%d 可达" % (ok, len(ips))) PY echo echo "════════ 公网连打 12 次 ════════" ok=0 for i in $(seq 1 12); do c=$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health) [ "$c" = "200" ] && ok=$((ok+1)) printf " %2d: %s\n" "$i" "$c" sleep 1 done echo " 可用 $ok/12" echo echo "════════ 本机 relay(排除源站问题)════════" for i in 1 2 3; do printf " %d: HTTP %s\n" "$i" "$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 http://127.0.0.1:8080/v1/health)" done echo echo "════════ 网络质量 ════════" ping -c 10 -W 2 1.1.1.1 2>/dev/null | tail -2 | sed 's/^/ /'