From 58a5d9ec5ef8ae80b623af8fae068794ab445cd3 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Tue, 2 Jun 2026 22:07:02 +0800 Subject: [PATCH] auto-sync: 2026-06-02 22:07:02 --- scripts/gateway-watchdog.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/gateway-watchdog.sh b/scripts/gateway-watchdog.sh index c626d0c..f56b748 100755 --- a/scripts/gateway-watchdog.sh +++ b/scripts/gateway-watchdog.sh @@ -163,14 +163,28 @@ count_rules() { return fi - # R1: 含 "lane task error" 且含 "FailoverError"(两步过滤) - R1_COUNT=$(echo "$recent_lines" | grep "lane task error" | _safe_count "FailoverError" || echo 0) + # R1: 含 "lane task error" 且含 "FailoverError" + local r1_matched + r1_matched=$(echo "$recent_lines" | grep "lane task error" || true) + if [ -n "$r1_matched" ]; then + R1_COUNT=$(echo "$r1_matched" | _safe_count "FailoverError") + else + R1_COUNT=0 + fi - # R2: 含 "stalled session" 且含 "recovery=none"(两步过滤) - R2_COUNT=$(echo "$recent_lines" | grep "stalled session" | _safe_count "recovery=none" || echo 0) + # R2: 含 "stalled session" 且含 "recovery=none" + local r2_matched + r2_matched=$(echo "$recent_lines" | grep "stalled session" || true) + if [ -n "$r2_matched" ]; then + R2_COUNT=$(echo "$r2_matched" | _safe_count "recovery=none") + else + R2_COUNT=0 + fi - # R3: 含 "rate_limit" 或含 "429"(匹配 JSON 中 rate_limit 关键字或 429 错误码) - R3_COUNT=$(echo "$recent_lines" | _safe_count 'rate_limit|429' || echo 0) + # R3: 含 "rate_limit" 或含 "429" + local r3_matched + r3_matched=$(echo "$recent_lines" | grep -E 'rate_limit|429' || true) + R3_COUNT=$(echo "$r3_matched" | _safe_count 'rate_limit|429') } # === 主逻辑 ===