Skip to content

feat(dashboard): 增加运行监控页 - #409

Merged
deepcoldy merged 16 commits into
masterfrom
codex/resource-monitor-plan
Jul 9, 2026
Merged

deepcoldy merged 16 commits into
masterfrom
codex/resource-monitor-plan

Conversation

@xiongz-c

@xiongz-c xiongz-c commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

背景 / 动机

Botmux 经常运行在远端 Linux 开发机上,同一台机器里可能同时存在多个 bot、多个 live 会话、worker 进程和底层 AI CLI。出现卡顿、内存上涨或会话堆积时,使用者首先需要判断的是“当前运行环境是否健康、容量风险在哪里”:宿主机资源是否紧张,botmux 自身是否异常上涨,daemon 是否在线,会话是否堆积,资源是否能关联到具体 bot / 会话。

这些问题过去需要离开 Dashboard 到机器上用 shell 工具排查,Dashboard 缺少一个面向实时排障的第一现场视图。本 PR 将 Dashboard 的「监控」定义为运行健康入口,而不是 AI 行为分析入口:监控回答“现在是否健康、哪里有容量风险”,洞察继续回答“AI CLI 做了什么、行为质量和长期模式怎样”。

本版是运行监控 v1,只做只读观察;不新增 kill、restart、cleanup 等操作能力,也不新增长期落盘或数据库依赖。

改动

  • 新增 Dashboard 运行监控页 #/monitoring,展示运行健康、资源压力、趋势、会话压力、Bot 运行表和当前会话资源表。
  • 新增 Linux /proc 资源采样,采集宿主机 CPU / Memory / load,以及进程 RSS、CPU tick delta。
  • 新增进程关联与资源聚合,把 daemon、worker、CLI PID marker、adopted CLI 和进程子树关联到 bot / session,聚合出 botmux、bot、会话级 CPU/RSS。
  • 新增运行健康摘要:采样 fresh/stale/unsupported、daemon online/offline、live session 状态分布、最长运行/等待会话、未关联进程会话数。
  • 新增 /api/resources/current 与 /api/resources/history,current 返回全量 live session 当前值,history 只返回保留趋势的数据集。
  • 总览页新增一行纯数据运行摘要,展示整体健康状态、CPU、Memory、Botmux RSS、会话数/等待数,并用健康色表达状态。
  • RSS 指标增加 tooltip,说明 Resident Set Size、共享内存重复计数风险,以及适合用来判断内存热点和上涨趋势。

默认值 / 兼容性依据

  • 采样间隔为 10s。
  • Host / Botmux / bot 聚合趋势默认保留 24h,重启后清空。
  • 会话趋势只保留 Top 30,默认 3h;Top 由 CPU、RSS、RSS 增长三个候选集合从全量当前会话重新计算,并带短 grace 避免边界抖动。
  • 所有 live session 都会进入 current snapshot;Top 只决定哪些会话保留历史趋势,避免用 Top 子集反推整体资源压力。
  • 监控数据只存在内存中,不写入 ~/.botmux、usage ledger、workflow runs、PM2 log 或新数据库。
  • 非 Linux 或 /proc 不可用时资源采样返回 unsupported;运行健康仍尽量展示 daemon/session 状态。
  • 首次 CPU 采样没有 delta 基线时显示未知,不把未知误展示成真实 0%。
  • RSS 聚合可能因共享内存重复计数偏大,UI 明确提示它适合定位热点、持续上涨和异常占用,不作为精确物理内存分摊。

测试覆盖

  • /proc parser:覆盖 CPU tick、idle tick、loadavg、meminfo、带括号/空格的 process stat。
  • 进程关联与聚合:覆盖 worker 子树、CLI marker、adopted CLI、bot daemon、自身 botmux 进程、歧义 PID 和 stale worker PID。
  • 运行健康摘要:覆盖 sample health、daemon online/offline、session buckets、最长运行/等待、未关联进程计数。
  • Top 会话选择:覆盖 CPU / RSS / RSS growth 候选、全量当前会话重算、grace 保留和过期淘汰。
  • Dashboard service/API:覆盖 current/history、unsupported snapshot、CPU readiness、全量当前会话与 Top 历史会话分离。
  • Dashboard UI:覆盖监控路由、i18n、RSS tooltip、tooltip 层级、会话表 10 行滚动、总览摘要、unknown/unsupported/0s 展示。

验证

  • pnpm vitest run test/resource-monitor-procfs.test.ts test/resource-monitor-ring-buffer.test.ts test/resource-monitor-runtime.test.ts test/resource-monitor-attribution.test.ts test/resource-monitor-top-selector.test.ts test/dashboard-resource-service.test.ts test/dashboard-resource-api.test.ts test/dashboard-resource-row.test.ts test/dashboard-monitoring-ui.test.ts test/dashboard-i18n.test.ts test/dashboard-route-smoke.test.ts
  • pnpm build
  • git diff --check
  • 远程 Linux 测试环境:打开 Dashboard 验证总览摘要、运行监控页、资源 API、趋势图、RSS tooltip、会话表滚动和「未关联进程」文案均能正常展示。

影响范围

  • 影响 Dashboard runtime、Dashboard web UI,以及 Dashboard session row 暴露给监控服务的运行字段。
  • 新增能力为只读观察,不改变 bot 配置、会话生命周期、CLI adapter 交互或用户操作权限。
  • Linux 环境可见真实资源数据;其它平台 graceful fallback 为资源采样不支持。
  • 每 10s 读取 /proc 并在内存中维护短期趋势,不新增外部服务、数据库或长期磁盘堆积。

@xiongz-c
xiongz-c force-pushed the codex/resource-monitor-plan branch from abab537 to f6eb294 Compare July 9, 2026 02:48
@xiongz-c xiongz-c changed the title feat(dashboard): 增加运行资源监控 feat(dashboard): 增加运行监控页 Jul 9, 2026
@xiongz-c
xiongz-c marked this pull request as ready for review July 9, 2026 07:00
@xiongz-c
xiongz-c requested a review from deepcoldy as a code owner July 9, 2026 07:00
@xiongz-c
xiongz-c force-pushed the codex/resource-monitor-plan branch from 45a41f3 to 118efcb Compare July 9, 2026 07:20

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

二次 review 已完成。重点检查了资源归因、/proc fallback、ring buffer 外层历史保留、采样服务/API 鉴权;已补充一个 follow-up 修复,收敛 tracked session 历史 Map 并用 procStart 校验 PID marker,相关测试与 build 已通过。

@deepcoldy
deepcoldy merged commit 2a5573a into master Jul 9, 2026
1 check passed
@deepcoldy
deepcoldy deleted the codex/resource-monitor-plan branch July 9, 2026 11:49
deepcoldy pushed a commit that referenced this pull request Jul 10, 2026
将 dashboard 迁移到 React(esbuild 按页面分包),按统一 UI 规范重构工作台/会话/洞察/工作流/群组/定时/白板/角色/Bot配置/Skills/团队/Webhook/全局设置等页面,沉淀 UI 基准规范与通用组件。含 review 修复(locate 图标/team capability/timezone/DropdownMenu/floating-scrollbars/insights/bot-defaults/legacy-workflow/替身编辑等)+ 集成 master 新功能(#404 会话筛选列/#405 监控室/#409 运行监控页/#412 lark-cli状态+飞书QR/#401 替身/#420 agentbuddy 源)。build 绿、全量 unit 0 非环境失败。
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.

2 participants