A modern and elegant dashboard for network traffic visualization and analysis.
fix: review follow-ups for v1.4.1
luolei0c8768cd3a97
diff --git a/.gitignore b/.gitignoreindex 43fe309..b506327 100644--- a/.gitignore+++ b/.gitignore@@ -66,3 +66,6 @@ next-env.d.ts.claude/*!.claude/skills/.refactoring_docs/++# Local Go agent build output+apps/agent/agentdiff --git a/CHANGELOG.en.md b/CHANGELOG.en.mdindex 3f30446..f580df4 100644--- a/CHANGELOG.en.md+++ b/CHANGELOG.en.md@@ -13,14 +13,14 @@ This release addresses bug and compatibility reports from GitHub issues.- **Huge traffic spike after upgrading/restarting** ([#50], thanks @PlutoNameless) 🐛- Gateways report cumulative bytes per connection. After a collector or agent restart (e.g. a container upgrade), the first snapshot counted the full history of every already-open long-lived connection again, adding tens of GB within minutes. Connections whose gateway start time (mihomo `start` / Surge `startDate`) is more than 5s before the process start now only establish a baseline, and later deltas are counted normally. Connections without a start time keep the old behavior, so no traffic is dropped. This applies to the direct mihomo collector, the Surge poller and the Go agent- - **Behavior change**: the pre-restart history of connections open at restart time is no longer counted (it was double counting), so the curve at upgrade time is lower than before+ - **Behavior change**: the pre-restart history of connections open at restart time is no longer counted (it was double counting), so the curve at upgrade time is lower than before. Known limits: this relies on the gateway reporting connection start times with roughly synced clocks, and traffic of pre-existing connections during a gateway disconnect longer than 5 minutes is not counted- **Idle agents keep showing offline** ([#58], thanks @yf-9186) 🐛- The offline timeout default (30s) equaled the agent heartbeat interval (30s), agents skip reports when there is no traffic, and the backend list and manual test used an 8s window, so healthy idle agents showed offline most of the time. All checks now use the heartbeat timeout, which defaults to 90s (3 × the heartbeat interval) and can be set with `AGENT_HEARTBEAT_TIMEOUT_MS` (minimum 15000). **Behavior change**: an agent that really goes down is marked offline after up to 90s- **`fetch failed` when Surge `http-api-tls` is enabled** ([#88], thanks @fgprodigal) 🐛- Surge `http-api-tls` and mihomo `external-controller-tls` use self-signed certificates, so every gateway request failed with a bare `fetch failed`. Poll and test-connection errors now include the underlying cause (e.g. `DEPTH_ZERO_SELF_SIGNED_CERT`, `ECONNREFUSED`), with a hint for certificate errors- New `BACKEND_TLS_INSECURE=1` skips certificate verification for gateway APIs only, with a one-time startup warning. GeoIP, ClickHouse and other outbound requests still verify certificates. Use only on trusted networks- **Trend chart tooltip wrong for ranges over 24 hours** ([#82], thanks @pengbins) 🐛- - Fixed daily bucketing in the realtime merger and store, and raised the query bucket limit to 1440 minutes+ - Fixed daily bucketing in the realtime merger and store, and raised the query bucket limit to 1440 minutes. Daily buckets follow UTC days; aligning them to the local day is tracked separately- **PWA forced to portrait on tablets** ([#73], thanks @ICEY16360): manifest `orientation` changed from `natural` to `any`### Agent (shipped as `agent-v1.4.6`)diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 030320f..4985011 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,14 +13,14 @@- **升级/重启后流量出现巨大尖峰**([#50],感谢 @PlutoNameless)🐛- 网关上报的是每条连接的累计字节数。collector 或 agent 重启(例如升级容器)后,首轮快照会把所有已存在长连接的历史累计量当作新增流量再记一遍,10 分钟内凭空多出数十 GB。现在,网关开始时间(mihomo `start` / Surge `startDate`)早于进程启动 5 秒以上的连接只建立基线,此后的增量照常计入;没有开始时间的连接保持旧行为,不丢数据。mihomo 直连、Surge 轮询与 Go agent 三条路径一致生效- - **行为变化**:重启瞬间已存在连接的历史累计量不再计入(这部分本来就是重复计数),所以升级时刻的曲线会比以前"低"+ - **行为变化**:重启瞬间已存在连接的历史累计量不再计入(这部分本来就是重复计数),所以升级时刻的曲线会比以前"低"。已知限制:依赖网关上报连接开始时间且时钟大致同步;网关断连超过 5 分钟期间,已存在连接的增量不计入- **Agent 空闲时频繁显示离线**([#58],感谢 @yf-9186)🐛- 离线判定超时默认值(30 秒)与 agent 心跳间隔(30 秒)相同,再加上没有流量时 agent 不上报,后端列表与手动测试还用的是 8 秒窗口,空闲但健康的 agent 大部分时间都会显示离线。现在统一使用心跳超时,默认改为 90 秒(心跳间隔的 3 倍),可用 `AGENT_HEARTBEAT_TIMEOUT_MS` 调整(最小 15000)。**行为变化**:agent 真正掉线后,最多 90 秒才会标记为离线- **Surge 开启 `http-api-tls` 后报 `fetch failed`**([#88],感谢 @fgprodigal)🐛- Surge `http-api-tls` 与 mihomo `external-controller-tls` 使用自签证书,所有网关请求都会失败,而且只显示一句笼统的 `fetch failed`。现在轮询和测试连接的报错会带上底层原因(如 `DEPTH_ZERO_SELF_SIGNED_CERT`、`ECONNREFUSED`),证书类错误会附带处理提示- 新增 `BACKEND_TLS_INSECURE=1`:仅对网关 API 跳过证书校验,启动时打印一次警告;GeoIP、ClickHouse 等其他出站请求仍正常校验。只建议在可信局域网内使用- **趋势图选择超过 24 小时的范围时 Tooltip 不准确**([#82],感谢 @pengbins)🐛- - 修正 realtime 合并与存储中的按日分桶,并把查询的分桶上限放宽到 1440 分钟+ - 修正 realtime 合并与存储中的按日分桶,并把查询的分桶上限放宽到 1440 分钟。日桶按 UTC 日划分,与本地日对齐另行处理- **平板安装 PWA 后被强制竖屏**([#73],感谢 @ICEY16360):manifest 的 `orientation` 从 `natural` 改为 `any`### Agent(随 `agent-v1.4.6` 发布)diff --git a/apps/agent/nekoagent b/apps/agent/nekoagentindex 3b7591d..a700ac0 100755--- a/apps/agent/nekoagent+++ b/apps/agent/nekoagent@@ -241,7 +241,7 @@ set -- "\$AGENT_BIN" \[ -n "\${NEKO_GATEWAY_TOKEN:-}" ] && set -- "\$@" --gateway-token "\$NEKO_GATEWAY_TOKEN"# Only pass the flag when enabled: older agent binaries reject unknown flags.-case "\${NEKO_GATEWAY_INSECURE_TLS:-}" in 1|true|TRUE|True|yes) set -- "\$@" --gateway-insecure-tls ;; esac+case "\${NEKO_GATEWAY_INSECURE_TLS:-}" in 1|t|T|true|TRUE|True) set -- "\$@" --gateway-insecure-tls ;; esac[ -n "\${NEKO_AGENT_ID:-}" ] && set -- "\$@" --agent-id "\$NEKO_AGENT_ID"[ -n "\${NEKO_REPORT_INTERVAL:-}" ] && set -- "\$@" --report-interval "\$NEKO_REPORT_INTERVAL"[ -n "\${NEKO_HEARTBEAT_INTERVAL:-}" ] && set -- "\$@" --heartbeat-interval "\$NEKO_HEARTBEAT_INTERVAL"@@ -785,7 +785,7 @@ build_agent_args() {fi# Only pass the flag when enabled: older agent binaries reject unknown flags.case "${NEKO_GATEWAY_INSECURE_TLS:-}" in- 1|true|TRUE|True|yes) set -- "$@" --gateway-insecure-tls ;;+ 1|t|T|true|TRUE|True) set -- "$@" --gateway-insecure-tls ;;esacif [ -n "${NEKO_AGENT_ID:-}" ]; thenset -- "$@" --agent-id "$NEKO_AGENT_ID"diff --git a/apps/collector/src/shared/utils/gateway-fetch.test.ts b/apps/collector/src/shared/utils/gateway-fetch.test.tsindex eeb2d2c..03d9018 100644--- a/apps/collector/src/shared/utils/gateway-fetch.test.ts+++ b/apps/collector/src/shared/utils/gateway-fetch.test.ts@@ -44,6 +44,17 @@ describe("describeGatewayError", () => {expect(text).toContain("BACKEND_TLS_INSECURE");});+ it("adds the TLS hint for ws errors that carry a top-level code", () => {+ const err = Object.assign(new Error("self-signed certificate"), {+ code: "DEPTH_ZERO_SELF_SIGNED_CERT",+ });+ const text = describeGatewayError(err);+ expect(text).toContain("DEPTH_ZERO_SELF_SIGNED_CERT");+ expect(text).toContain("BACKEND_TLS_INSECURE");+ const refused = Object.assign(new Error("connect ECONNREFUSED"), { code: "ECONNREFUSED" });+ expect(describeGatewayError(refused)).toBe("connect ECONNREFUSED");+ });+it("keeps plain errors unchanged", () => {expect(describeGatewayError(new Error("HTTP 500"))).toBe("HTTP 500");const refused = new TypeError("fetch failed", {diff --git a/apps/collector/src/shared/utils/gateway-fetch.ts b/apps/collector/src/shared/utils/gateway-fetch.tsindex bc5fc5f..26203a3 100644--- a/apps/collector/src/shared/utils/gateway-fetch.ts+++ b/apps/collector/src/shared/utils/gateway-fetch.ts@@ -45,6 +45,9 @@ export function gatewayFetch(}) as unknown as Promise<Response>;}+const TLS_HINT =+ " (gateway certificate not trusted; set BACKEND_TLS_INSECURE=1 to skip verification on trusted networks)";+/*** Error text for a failed gateway request. Node's fetch throws a bare* "fetch failed" and hides the real reason (TLS, DNS, refused) in `cause`.@@ -54,15 +57,20 @@ export function describeGatewayError(error: unknown): string {const cause = (error as Error & { cause?: unknown }).cause as| { code?: unknown; message?: unknown }| undefined;- const code = typeof cause?.code === "string" ? cause.code : "";const causeMessage = typeof cause?.message === "string" ? cause.message : "";+ // ws reports TLS failures as a top-level error with `code` and no cause.+ const topCode = (error as Error & { code?: unknown }).code;+ if (!cause && typeof topCode === "string") {+ return isTlsVerificationCode(topCode)+ ? `${error.message} (${topCode})${TLS_HINT}`+ : error.message;+ }+ const code = typeof cause?.code === "string" ? cause.code : "";if (!code && !causeMessage) return error.message;const detail = code && causeMessage? causeMessage.includes(code) ? causeMessage : `${code}: ${causeMessage}`: code || causeMessage;- const hint = isTlsVerificationCode(code)- ? " (gateway certificate not trusted; set BACKEND_TLS_INSECURE=1 to skip verification on trusted networks)"- : "";+ const hint = isTlsVerificationCode(code) ? TLS_HINT : "";return `${error.message} (${detail})${hint}`;}