32a1885f0d
支持随时暂停/恢复实时监测并保留槽位;TTL 到期自动暂停不占删槽;修复到期竞态导致空槽与唯一约束冲突;探针 parse_error 与中文错误;移除失败 snackbar。
56 lines
2.6 KiB
Markdown
56 lines
2.6 KiB
Markdown
# 监测槽实时监测开关
|
||
|
||
**日期**: 2026-06-11
|
||
|
||
## 摘要
|
||
|
||
为每台已固定监测槽的服务器增加「实时监测」开关。关闭后停止 5 秒探针与 WebSocket 推送,槽位仍保留同一台服务器,8 小时倒计时暂停;重新开启时重置 8 小时窗口。
|
||
|
||
## 动机
|
||
|
||
用户希望随时关闭某台服务器的实时监测,而不必等到 8 小时到期或点击删除释放槽位。
|
||
|
||
## 涉及文件
|
||
|
||
- `server/domain/models/__init__.py` — `WatchPin.monitoring_enabled`
|
||
- `server/infrastructure/database/migrations.py` — 列迁移
|
||
- `server/infrastructure/database/watch_repo.py` — 暂停/恢复、过期逻辑
|
||
- `server/application/services/watch_service.py` — `set_slot_monitoring`、槽位 payload
|
||
- `server/api/watch.py` — `PATCH /api/watch/pins/{slot_index}/monitoring`
|
||
- `server/background/watch_probe_runner.py` — 仅探针已开启的 pin
|
||
- `frontend/src/api/index.ts` — `http.patch`
|
||
- `frontend/src/composables/useWatchPins.ts`
|
||
- `frontend/src/components/watch/WatchSlotCard.vue`
|
||
- `frontend/src/components/watch/WatchSlotRow.vue`
|
||
- `tests/test_watch_pins.py`
|
||
|
||
## 迁移 / 重启
|
||
|
||
- 需 API 重启以执行 schema migration(`monitoring_enabled` 列)
|
||
- 无需手动 SQL
|
||
|
||
## 验证
|
||
|
||
```bash
|
||
pytest tests/test_watch_pins.py -q
|
||
cd frontend && npm run type-check
|
||
```
|
||
|
||
- 仪表盘监测槽:开关关闭 → 卡片灰显、无实时指标;重新开启 → 恢复探针并重置倒计时
|
||
- 时长切换:默认 8h;点击 24h → 重置为 24 小时窗口;暂停时切换时长保留偏好,开启后生效
|
||
|
||
## 2026-06-11 补充:暂停永久占槽 + 恢复 Agent 60s
|
||
|
||
- **暂停/时长到期**:不再删除 pin;`monitoring_enabled=false`,槽位永久保留直至手动移除或重新开启
|
||
- **8h/24h 到期**:自动暂停(等同关开关),结束 session(`expired`),保留槽位
|
||
- **恢复 Agent 模式**:当无任何槽位对该机开启 5s 监测时,清理 `watch:live/proc/last` Redis;子机 Agent 始终 60s 智能心跳(CPU 波动 >10% 或超阈值才上报),无需改 Agent 配置
|
||
- **重新开启**:若 session 已结束则自动开新 session
|
||
- **涉及**:`server/utils/watch_state.py`、`watch_repo.expire_due_pins`、`watch_service`、`watch_probe_runner`、前端 countdown 到期 refresh
|
||
|
||
## 2026-06-11 补充:8h / 24h 时长选项
|
||
|
||
- `watch_pins.ttl_hours` 列(默认 8,仅允许 8 或 24)
|
||
- `PATCH /api/watch/pins/{slot_index}/ttl` — 切换时长;监测开启时同步重置 `expires_at`
|
||
- `POST /api/watch/pins` 可选 `ttl_hours: 8 | 24`(默认 8)
|
||
- 槽位卡片「8h / 24h」切换按钮,须显式点击才改为 24h
|