#!/bin/bash # 长测结束后,把所有数据汇总成一份可直接引用的报告 set -u echo "################################################################" echo "# 中转稳定性最终数据汇总" echo "# 生成时间: $(date '+%Y-%m-%d %H:%M:%S')" echo "################################################################" echo echo "════════════════════ 一、最终配置 ════════════════════" echo " ── 隧道实例 ──" for svc in lanremote-tunnel lanremote-tunnel-h2; do echo " $svc:" systemctl cat "$svc" 2>/dev/null \ | grep -oE '\-\-metrics [0-9.:]+|\-\-protocol [a-z0-9]+|\-\-ha-connections [0-9]+|\-\-edge-ip-version [0-9]+|\-\-retries [0-9]+' \ | sed 's/^/ /' done echo " ── 网络层 ──" echo " wlan0 MTU: $(cat /sys/class/net/wlan0/mtu)" iptables -t mangle -S OUTPUT 2>/dev/null | grep TCPMSS | sed 's/^/ /' echo " keepalive: time=$(sysctl -n net.ipv4.tcp_keepalive_time) intvl=$(sysctl -n net.ipv4.tcp_keepalive_intvl) probes=$(sysctl -n net.ipv4.tcp_keepalive_probes)" echo " ── 中转 ──" echo " 长轮询: $(grep -oE 'RELAY_POLL=[0-9]+' /etc/systemd/system/lanremote-relay.service 2>/dev/null)" curl -s --max-time 10 http://127.0.0.1:8080/v1/health | head -c 120 | sed 's/^/ /' echo echo " ── watchdog ──" echo " $(systemctl is-active lanremote-watchdog.timer) / $(wc -l < /root/lanremote-relay/watchdog.sh) 行" echo echo "════════════════════ 二、长测结果 ════════════════════" # ---- 设备侧健康 ---- H=/root/long2h_health.tsv if [ -f "$H" ]; then n=$(grep -c . "$H") ok=$(awk -F'\t' '$2=="200"' "$H" | wc -l) echo " ── 设备侧公网可用率(含设备自己的 4G 那一段,偏悲观)──" echo " 样本 $n 成功 $ok = $(awk -v a="$ok" -v b="$n" 'BEGIN{printf "%.1f", a*100/b}')%" awk -F'\t' '$2=="200"{print $3}' "$H" | sort -n | awk '{a[NR]=$1} END{ if(NR==0){print " 无数据"; exit} printf " 耗时: 最小 %d 中位 %d P90 %d P99 %d 最大 %d ms\n", a[1], a[int(NR/2)+1], a[int(NR*0.9)+1], a[int(NR*0.99)+1], a[NR]}' echo " 状态码分布:" awk -F'\t' '{print $2}' "$H" | sort | uniq -c | sort -rn | sed 's/^/ /' echo " 失败时刻(全部):" awk -F'\t' '$2!="200"{print " " $1 " 码=" $2 " " $3 "ms"}' "$H" fi # ---- 轮询 ---- P=/root/rp_poll30.tsv if [ -f "$P" ]; then n=$(grep -c . "$P") ok=$(awk -F'\t' '$2=="200"' "$P" | wc -l) echo echo " ── 长轮询(30 次,每次挂 60 秒)──" echo " $ok/$n = $(awk -v a="$ok" -v b="$n" 'BEGIN{printf "%.1f", a*100/b}')%" awk -F'\t' '$2=="200"{print $3}' "$P" | sort -n | awk '{a[NR]=$1} END{ if(NR==0){print " 无数据"; exit} printf " 最小 %d P50 %d P90 %d P99 %d 最大 %d ms(理想 ≈ 61000)\n", a[1], a[int(NR/2)+1], a[int(NR*0.9)+1], a[int(NR*0.99)+1], a[NR]}' echo " 超过 90000ms 的样本(会打到客户端 120 秒超时的边缘):" awk -F'\t' '$3>90000{print " #" $1 " " $3 "ms 开始 " $4}' "$P" fi # ---- 连接数 ---- C=/root/long2h_conns.tsv if [ -f "$C" ]; then echo echo " ── 连接数波动 ──" awk -F'\t' 'NR>1 && $2 ~ /^[0-9]+$/ {if(min==""||$2max)max=$2} NR>1 && $3 ~ /^[0-9]+$/ {if(min2==""||$3max2)max2=$3} END{ printf " quic: %s ~ %s\n", min, max printf " http2: %s ~ %s\n", min2, max2}' echo " 出现过的组合(次数 top 8):" awk -F'\t' 'NR>1{print "quic="$2" http2="$3}' "$C" | sort | uniq -c | sort -rn | head -8 | sed 's/^/ /' echo " 总连接数掉到 3 以下的时刻:" awk -F'\t' 'NR>1 && $2 ~ /^[0-9]+$/ && $3 ~ /^[0-9]+$/ && $2+$3<3 {print " " $1 " quic="$2" http2="$3}' "$C" fi # ---- PC 侧 ---- PC=/root/../dev/null echo echo " ── PC 侧(真实用户视角,只有回源那一跳走 4G)──" echo " (数据在本地 _build/rp_pc_long.tsv,见报告正文)" echo echo "════════════════════ 三、隧道事件增量 ════════════════════" echo " ── QUIC 实例(tunnel.log 全量)──" for kw in 'Registered tunnel connection' 'Failed to dial' 'Lost connection' 'i/o timeout' 'no recent network activity'; do printf " %-34s %s\n" "$kw" "$(grep -c "$kw" /root/lanremote-relay/tunnel.log 2>/dev/null)" done echo " ── HTTP/2 实例(tunnel-h2.log 全量)──" for kw in 'Registered tunnel connection' 'Failed to dial' 'Lost connection' 'i/o timeout'; do printf " %-34s %s\n" "$kw" "$(grep -c "$kw" /root/lanremote-relay/tunnel-h2.log 2>/dev/null)" done echo echo "════════════════════ 四、watchdog 处置记录 ════════════════════" grep -E '重启|无响应|建齐' /root/lanremote-relay/watchdog.log 2>/dev/null | tail -15 | sed 's/^/ /' echo echo "════════════════════ 五、中转自身 ════════════════════" echo " BrokenPipeError 次数: $(grep -c 'BrokenPipeError' /root/lanremote-relay/relay.log 2>/dev/null)" echo " 下载中断次数: $(grep -c '下载中断' /root/lanremote-relay/relay.log 2>/dev/null)" echo " 内存占用: $(systemctl show lanremote-relay -p MemoryCurrent --value | awk '{printf "%.1f MB", $1/1024/1024}')" echo " 运行时长: $(systemctl show lanremote-relay -p ActiveEnterTimestamp --value)"