#!/bin/bash # 查隧道为什么只有 1 条连接 set -u echo "===== 1. 服务状态 =====" systemctl is-active lanremote-tunnel systemctl show lanremote-tunnel -p ExecMainStartTimestamp --value | sed 's/^/ 启动于: /' echo echo "===== 2. metrics 全部隧道指标 =====" curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null \ | grep -E '^cloudflared_tunnel' | sed 's/^/ /' echo echo "===== 3. 最近注册的连接 =====" grep -E 'Registered tunnel connection' /root/lanremote-relay/tunnel.log 2>/dev/null | tail -6 \ | sed 's/.*\(connIndex=[0-9]*\).*\(location=[a-z0-9]*\).*\(protocol=[a-z0-9]*\).*/ \1 \2 \3/' echo echo "===== 4. 有没有注册失败 =====" grep -iE 'failed|error|retry' /root/lanremote-relay/tunnel.log 2>/dev/null | tail -6 | sed 's/^/ /' echo echo "===== 5. HA 连接数设置 =====" grep -o 'ha-connections [0-9]*' /etc/systemd/system/lanremote-tunnel.service | sed 's/^/ /' echo echo "===== 6. 日志里 Initial protocol 的次数(每次重启会打)=====" grep -c 'Initial protocol' /root/lanremote-relay/tunnel.log 2>/dev/null | sed 's/^/ /' echo " 最近 3 条:" grep 'Initial protocol' /root/lanremote-relay/tunnel.log 2>/dev/null | tail -3 | sed 's/^/ /' echo echo "===== 7. 进程 =====" ps aux 2>/dev/null | grep -c '[c]loudflared' | sed 's/^/ cloudflared 进程数: /'