Skip to content

修复应用流量监控自动关闭且不记录的问题#36

Merged
huangxida merged 2 commits intomainfrom
fix/per-app-monitoring-stall
Mar 25, 2026
Merged

修复应用流量监控自动关闭且不记录的问题#36
huangxida merged 2 commits intomainfrom
fix/per-app-monitoring-stall

Conversation

@huangxida
Copy link
Copy Markdown
Owner

问题

  • 开启应用流量监控后,过一段时间会被自动关闭。
  • 重新开启后仍然不记录应用流量。

原因

  • 当前实现使用常驻 nettop 进程配合 Pipe 流式读取。
  • 在 macOS 下,nettop 写入管道时存在缓冲,导致监控器长时间收不到采样数据,被 watchdog 误判为卡死。
  • 连续失败达到阈值后,代码会自动把 perAppMonitoring.enabled 置回 false

修改

  • 将应用流量采样改为按设定间隔执行一次 nettop -L 1 单次采样,绕开流式输出缓冲问题。
  • 保留单次采样超时和连续失败保护。
  • 失败时重置快照基线,避免后续速率计算出现脏数据。
  • 按真实采样间隔计算上下行速率,减少采样抖动带来的误差。

验证

  • 执行 swiftc -typecheck FlowWatch/*.swift 通过。
  • 未执行构建。

@huangxida huangxida merged commit eff317f into main Mar 25, 2026
2 checks passed
@huangxida huangxida deleted the fix/per-app-monitoring-stall branch March 25, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant