2.6 KiB
2.6 KiB
监测槽实时监测开关
日期: 2026-06-11
摘要
为每台已固定监测槽的服务器增加「实时监测」开关。关闭后停止 5 秒探针与 WebSocket 推送,槽位仍保留同一台服务器,8 小时倒计时暂停;重新开启时重置 8 小时窗口。
动机
用户希望随时关闭某台服务器的实时监测,而不必等到 8 小时到期或点击删除释放槽位。
涉及文件
server/domain/models/__init__.py—WatchPin.monitoring_enabledserver/infrastructure/database/migrations.py— 列迁移server/infrastructure/database/watch_repo.py— 暂停/恢复、过期逻辑server/application/services/watch_service.py—set_slot_monitoring、槽位 payloadserver/api/watch.py—PATCH /api/watch/pins/{slot_index}/monitoringserver/background/watch_probe_runner.py— 仅探针已开启的 pinfrontend/src/api/index.ts—http.patchfrontend/src/composables/useWatchPins.tsfrontend/src/components/watch/WatchSlotCard.vuefrontend/src/components/watch/WatchSlotRow.vuetests/test_watch_pins.py
迁移 / 重启
- 需 API 重启以执行 schema migration(
monitoring_enabled列) - 无需手动 SQL
验证
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/lastRedis;子机 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_atPOST /api/watch/pins可选ttl_hours: 8 | 24(默认 8)- 槽位卡片「8h / 24h」切换按钮,须显式点击才改为 24h