fix(watch): eager probe on resume so metrics appear immediately

After pausing clears Redis snapshots, resuming or adding pins now triggers
an immediate probe before list_slots returns, with frontend refresh fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Agent
2026-06-14 02:53:02 +08:00
parent 825d0297c4
commit 5c508ed14c
7 changed files with 285 additions and 79 deletions
@@ -0,0 +1,39 @@
# 2026-06-14 — 监测开启后立即探针
## 摘要
开启实时监测或新加监测槽后,立即执行一次 5s 探针并写入 Redis,避免「等待服务器回传信息」长时间空白。
## 动机
用户反馈开启监测后「获取不到信息」。根因:暂停监测会 `clear_watch_redis_snapshot`,恢复后 API 返回 `metrics=null`,前端进入等待态,需等后台 5s 探针循环(最坏约 5–15s);若 WebSocket 未及时推送,体验更差。
## 变更
- `server/background/watch_probe_runner.py`:抽取 `_probe_server_with_pins`;新增 `trigger_immediate_watch_probe(server_id)`
- `server/application/services/watch_service.py`:加槽 / 替换槽 / 恢复监测后调用立即探针
- `frontend/src/composables/useWatchPins.ts`:恢复监测后 3s、8s 兜底 `refreshPins`(仍 pending 时)
- `frontend/src/components/watch/WatchSlotCard.vue`:暂停底栏文案「已暂停」替代误显示「已到期」
- `tests/test_watch_pins.py`:恢复监测立即带回 metrics 用例
## 涉及文件
- `server/background/watch_probe_runner.py`
- `server/application/services/watch_service.py`
- `frontend/src/composables/useWatchPins.ts`
- `frontend/src/components/watch/WatchSlotCard.vue`
- `tests/test_watch_pins.py`
## 迁移 / 重启
- 需重启 API(后端逻辑变更)
- 前端需 `vite build` 后部署静态资源
## 验证
```bash
pytest tests/test_watch_pins.py -q
bash scripts/local_verify.sh
```
生产:加槽 → 开启实时监测 → 应在数秒内看到 CPU/内存或明确探针错误态,而非长期空白。