nonebot-plugin-ruok 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/PKG-INFO +35 -5
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/README.md +34 -4
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/pyproject.toml +2 -2
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/pyproject.toml.orig +2 -2
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/AGENTS.md +4 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/__init__.py +8 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/api.py +8 -6
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collector.py +20 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/AGENTS.md +6 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/__init__.py +20 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/metrics.py +37 -19
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/modules.py +57 -12
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/sessions.py +298 -29
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/config.py +7 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/AGENTS.md +6 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/router.py +400 -84
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/AGENTS.md +4 -0
- nonebot_plugin_ruok-0.4.2/src/nonebot_plugin_ruok/webui/templates/_session_bulk.html.jinja2 +74 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_session_container.html.jinja2 +6 -1
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/sessions.html.jinja2 +100 -1
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/chat_render.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/monitor.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/notifications.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/storage.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/trackers.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/protocol.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/auth.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/jinja.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/sse.py +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/chartjs/LICENSE.md +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/chartjs/chart.umd.min.js +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/htmx/LICENSE +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/htmx/htmx.min.js +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/idiomorph/LICENSE +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/idiomorph/idiomorph-ext.min.js +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/pico/LICENSE.md +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/static/vendor/pico/pico.min.css +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_auth_shell.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_connections.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_disk.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_hero.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_metrics.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_stats.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_system.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_dashboard_trends.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_linked_list.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_module_form.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_modules_table.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_notification_form.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_notifications_list.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_session_card.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_session_detail_content.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_sessions_list.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_user_sessions.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/_users_panel.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/base.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/chat_session_list.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/chat_status.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/dashboard.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/dashboard_user.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/login.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/modules.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/modules_detail.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/notifications.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/notifications_detail.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/register.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/reset_password.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/sessions_detail.html.jinja2 +0 -0
- {nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/webui/templates/users.html.jinja2 +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: nonebot-plugin-ruok
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Bot health monitoring, session tracking, and WebUI for NoneBot2
|
|
5
5
|
Author: p0rt39
|
|
6
6
|
Author-email: p0rt39 <YuibataMiraa@gmail.com>
|
|
@@ -49,7 +49,7 @@ Description-Content-Type: text/markdown
|
|
|
49
49
|
- 系统指标:CPU、内存、磁盘、网络、进程、运行时间。
|
|
50
50
|
- 连接监控:Bot 连接/断开、适配器、自身 ID、可选深度延迟检查。
|
|
51
51
|
- 插件内省:自动捕获已加载插件、元信息、Matcher、健康提示。
|
|
52
|
-
- Session
|
|
52
|
+
- Session 追踪:自动捕获日志错误,支持手动上报、查找、备注、关联、确认、解决、忽略,可按筛选批量处理与清理陈旧积压。
|
|
53
53
|
- 插件级影响传播:确认 Session 时可指定影响插件,相关模块自动进入 `unavailable`。
|
|
54
54
|
- WebUI:完整鉴权、实时更新、关键指标实时显示、Bot用户/Bot开发者双显示模板。
|
|
55
55
|
- 账号体系:内置 admin、普通用户注册、平台账号绑定、记住登录、自助重设密码。
|
|
@@ -200,8 +200,37 @@ SSE 每秒发送一次轻量 tick,并按此 TTL 触发完整状态采集;小
|
|
|
200
200
|
| `RUOK__REPORT_WHITELIST_USERS` | `list[str]` | `[]` | 上报白名单用户 ID |
|
|
201
201
|
| `RUOK__REPORT_WHITELIST_GROUPS` | `list[str]` | `[]` | 上报白名单群 ID |
|
|
202
202
|
| `RUOK__CRISIS_MODE` | `bool` | `false` | 危机模式,跳过上报权限检查 |
|
|
203
|
+
| `RUOK__STALE_PENDING_AFTER_HOURS` | `float` | `0.0` | 待确认 Session 超过该小时数未更新即视为陈旧;`0` 关闭陈旧统计、WebUI 陈旧面板与定时清理 |
|
|
204
|
+
| `RUOK__STALE_PENDING_AUTO_RESOLVE` | `bool` | `false` | 是否启用定时清理陈旧待确认 Session(需要 `nonebot-plugin-apscheduler`) |
|
|
205
|
+
| `RUOK__STALE_PENDING_RESOLVE_STATUS` | `"solved" \| "ignored"` | `"ignored"` | 自动处理陈旧 Session 时写入的状态 |
|
|
203
206
|
| `RUOK__SUMMARY_INTERVAL_HOURS` | `float` | `4.0` | 未解决 Session 汇总通知间隔 |
|
|
204
207
|
|
|
208
|
+
### 批量处理积压 Session
|
|
209
|
+
|
|
210
|
+
长时间停留在「待确认」的 Session 会持续堆积。RUOK 提供两种批量入口,两者都只处理
|
|
211
|
+
`pending` 与 `unsolved` 的 Session,已有的 `solved`/`ignored` 记录不会被改写。
|
|
212
|
+
|
|
213
|
+
**WebUI 批量面板**(无需配置):`/ruok/sessions` 的列表上方有「批量处理当前筛选结果」。
|
|
214
|
+
它处理的是**当前筛选条件命中的全部 Session(跨分页)**,而不是仅当前页:
|
|
215
|
+
|
|
216
|
+
- 先选择批量动作(确认为未解决 / 标记为已解决 / 标记为已忽略),提交按钮在选中动作后才启用;
|
|
217
|
+
- 单次最多处理 500 条,超出时提示缩小筛选范围,不会部分执行;
|
|
218
|
+
- 提交前有二次确认;操作不可撤销。
|
|
219
|
+
|
|
220
|
+
批量确认等价于不带插件参数的确认:Session 变为 `unsolved`,但不会记录影响插件,
|
|
221
|
+
因此不会向共享插件的模块传播 `unavailable`。需要插件级传播时请在详情页逐条确认。
|
|
222
|
+
|
|
223
|
+
**陈旧待确认清理**(需配置):设置 `RUOK__STALE_PENDING_AFTER_HOURS` 大于 `0` 后,
|
|
224
|
+
Session 页面会出现陈旧面板,显示「`last_seen_at` 超过该小时数仍未更新」的待确认数量,
|
|
225
|
+
并可一键处理。若同时把 `RUOK__STALE_PENDING_AUTO_RESOLVE` 设为 `true`,插件启动时会注册
|
|
226
|
+
一个周期任务自动处理;该任务依赖 `nonebot-plugin-apscheduler`,未安装时自动清理不生效。
|
|
227
|
+
|
|
228
|
+
判定陈旧使用 `last_seen_at`(与列表排序、页面显示一致):反复出现的错误只要仍在更新就
|
|
229
|
+
不会被视为陈旧。写入状态由 `RUOK__STALE_PENDING_RESOLVE_STATUS` 决定,默认 `ignored`
|
|
230
|
+
(按误报处理),避免把真实缺陷误标为已修复。
|
|
231
|
+
|
|
232
|
+
批量写入在单次请求内完成,只重建一次插件影响索引;处理后会即时更新状态计数与模块健康。
|
|
233
|
+
|
|
205
234
|
上报权限顺序:
|
|
206
235
|
|
|
207
236
|
1. `RUOK__CRISIS_MODE=true`
|
|
@@ -357,7 +386,7 @@ stateDiagram-v2
|
|
|
357
386
|
| 页面 | 路由 | 说明 |
|
|
358
387
|
| :--- | :--- | :--- |
|
|
359
388
|
| 总览 | `/ruok` | 系统指标、连接、插件、模块、趋势、Session 统计 |
|
|
360
|
-
| Sessions | `/ruok/sessions` | 按状态、模块、插件、时间筛选和搜索,每页 20
|
|
389
|
+
| Sessions | `/ruok/sessions` | 按状态、模块、插件、时间筛选和搜索,每页 20 条;支持确认、解决、忽略,以及按当前筛选批量处理 |
|
|
361
390
|
| Session 详情 | `/ruok/sessions/{id}` | 完整信息、用户说明、Traceback、关联 Session、影响插件、备注 |
|
|
362
391
|
| 模块 | `/ruok/modules` | 模块列表与创建 |
|
|
363
392
|
| 模块详情 | `/ruok/modules/{name}` | 编辑名称、显示名、描述、关联插件、删除 |
|
|
@@ -608,15 +637,16 @@ src/nonebot_plugin_ruok/
|
|
|
608
637
|
- `webui_test_utils.py`:FastAPI `TestClient`、WebUI 登录、模块/通知测试辅助函数。
|
|
609
638
|
- `plugin_test.py`:NoneBot `/ruok` 命令、绑定、重设密码、状态查询、确认/解决等交互测试。
|
|
610
639
|
- `test_collector.py`:指标采集、进程快照、网络/磁盘速率追踪。
|
|
611
|
-
- `test_sessions.py`:Session CRUD
|
|
640
|
+
- `test_sessions.py`:Session CRUD、筛选、搜索、关联、统计、插件影响索引、批量状态变更与陈旧判定。
|
|
612
641
|
- `test_modules.py`:模块 CRUD、直接/插件传播状态推导、相关 Session 查询。
|
|
613
642
|
- `test_web_api.py`:API key 与路由优先级回归测试。
|
|
614
643
|
- `test_web_api_auth.py`:登录、注册、绑定、记住登录、密码重设、鉴权边界。
|
|
615
644
|
- `test_web_api_dashboard.py`:管理员/普通用户 Dashboard、趋势图和趋势数据端点。
|
|
616
|
-
- `test_web_api_sessions.py`:Session WebUI、Session API
|
|
645
|
+
- `test_web_api_sessions.py`:Session WebUI、Session API、影响插件编辑、批量面板与批量 action。
|
|
617
646
|
- `test_web_api_modules.py`:模块 WebUI 列表、详情、编辑、删除。
|
|
618
647
|
- `test_web_api_notifications.py`:通知规则 WebUI 列表、详情、编辑、删除。
|
|
619
648
|
- `test_web_api_users.py`:用户管理与普通用户自助账号操作。
|
|
649
|
+
- `test_webui_sessions_perf.py`:Session 读取路径与批量 action 的单次目录扫描、事件循环不阻塞回归。
|
|
620
650
|
|
|
621
651
|
## 开发
|
|
622
652
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
- 系统指标:CPU、内存、磁盘、网络、进程、运行时间。
|
|
26
26
|
- 连接监控:Bot 连接/断开、适配器、自身 ID、可选深度延迟检查。
|
|
27
27
|
- 插件内省:自动捕获已加载插件、元信息、Matcher、健康提示。
|
|
28
|
-
- Session
|
|
28
|
+
- Session 追踪:自动捕获日志错误,支持手动上报、查找、备注、关联、确认、解决、忽略,可按筛选批量处理与清理陈旧积压。
|
|
29
29
|
- 插件级影响传播:确认 Session 时可指定影响插件,相关模块自动进入 `unavailable`。
|
|
30
30
|
- WebUI:完整鉴权、实时更新、关键指标实时显示、Bot用户/Bot开发者双显示模板。
|
|
31
31
|
- 账号体系:内置 admin、普通用户注册、平台账号绑定、记住登录、自助重设密码。
|
|
@@ -176,8 +176,37 @@ SSE 每秒发送一次轻量 tick,并按此 TTL 触发完整状态采集;小
|
|
|
176
176
|
| `RUOK__REPORT_WHITELIST_USERS` | `list[str]` | `[]` | 上报白名单用户 ID |
|
|
177
177
|
| `RUOK__REPORT_WHITELIST_GROUPS` | `list[str]` | `[]` | 上报白名单群 ID |
|
|
178
178
|
| `RUOK__CRISIS_MODE` | `bool` | `false` | 危机模式,跳过上报权限检查 |
|
|
179
|
+
| `RUOK__STALE_PENDING_AFTER_HOURS` | `float` | `0.0` | 待确认 Session 超过该小时数未更新即视为陈旧;`0` 关闭陈旧统计、WebUI 陈旧面板与定时清理 |
|
|
180
|
+
| `RUOK__STALE_PENDING_AUTO_RESOLVE` | `bool` | `false` | 是否启用定时清理陈旧待确认 Session(需要 `nonebot-plugin-apscheduler`) |
|
|
181
|
+
| `RUOK__STALE_PENDING_RESOLVE_STATUS` | `"solved" \| "ignored"` | `"ignored"` | 自动处理陈旧 Session 时写入的状态 |
|
|
179
182
|
| `RUOK__SUMMARY_INTERVAL_HOURS` | `float` | `4.0` | 未解决 Session 汇总通知间隔 |
|
|
180
183
|
|
|
184
|
+
### 批量处理积压 Session
|
|
185
|
+
|
|
186
|
+
长时间停留在「待确认」的 Session 会持续堆积。RUOK 提供两种批量入口,两者都只处理
|
|
187
|
+
`pending` 与 `unsolved` 的 Session,已有的 `solved`/`ignored` 记录不会被改写。
|
|
188
|
+
|
|
189
|
+
**WebUI 批量面板**(无需配置):`/ruok/sessions` 的列表上方有「批量处理当前筛选结果」。
|
|
190
|
+
它处理的是**当前筛选条件命中的全部 Session(跨分页)**,而不是仅当前页:
|
|
191
|
+
|
|
192
|
+
- 先选择批量动作(确认为未解决 / 标记为已解决 / 标记为已忽略),提交按钮在选中动作后才启用;
|
|
193
|
+
- 单次最多处理 500 条,超出时提示缩小筛选范围,不会部分执行;
|
|
194
|
+
- 提交前有二次确认;操作不可撤销。
|
|
195
|
+
|
|
196
|
+
批量确认等价于不带插件参数的确认:Session 变为 `unsolved`,但不会记录影响插件,
|
|
197
|
+
因此不会向共享插件的模块传播 `unavailable`。需要插件级传播时请在详情页逐条确认。
|
|
198
|
+
|
|
199
|
+
**陈旧待确认清理**(需配置):设置 `RUOK__STALE_PENDING_AFTER_HOURS` 大于 `0` 后,
|
|
200
|
+
Session 页面会出现陈旧面板,显示「`last_seen_at` 超过该小时数仍未更新」的待确认数量,
|
|
201
|
+
并可一键处理。若同时把 `RUOK__STALE_PENDING_AUTO_RESOLVE` 设为 `true`,插件启动时会注册
|
|
202
|
+
一个周期任务自动处理;该任务依赖 `nonebot-plugin-apscheduler`,未安装时自动清理不生效。
|
|
203
|
+
|
|
204
|
+
判定陈旧使用 `last_seen_at`(与列表排序、页面显示一致):反复出现的错误只要仍在更新就
|
|
205
|
+
不会被视为陈旧。写入状态由 `RUOK__STALE_PENDING_RESOLVE_STATUS` 决定,默认 `ignored`
|
|
206
|
+
(按误报处理),避免把真实缺陷误标为已修复。
|
|
207
|
+
|
|
208
|
+
批量写入在单次请求内完成,只重建一次插件影响索引;处理后会即时更新状态计数与模块健康。
|
|
209
|
+
|
|
181
210
|
上报权限顺序:
|
|
182
211
|
|
|
183
212
|
1. `RUOK__CRISIS_MODE=true`
|
|
@@ -333,7 +362,7 @@ stateDiagram-v2
|
|
|
333
362
|
| 页面 | 路由 | 说明 |
|
|
334
363
|
| :--- | :--- | :--- |
|
|
335
364
|
| 总览 | `/ruok` | 系统指标、连接、插件、模块、趋势、Session 统计 |
|
|
336
|
-
| Sessions | `/ruok/sessions` | 按状态、模块、插件、时间筛选和搜索,每页 20
|
|
365
|
+
| Sessions | `/ruok/sessions` | 按状态、模块、插件、时间筛选和搜索,每页 20 条;支持确认、解决、忽略,以及按当前筛选批量处理 |
|
|
337
366
|
| Session 详情 | `/ruok/sessions/{id}` | 完整信息、用户说明、Traceback、关联 Session、影响插件、备注 |
|
|
338
367
|
| 模块 | `/ruok/modules` | 模块列表与创建 |
|
|
339
368
|
| 模块详情 | `/ruok/modules/{name}` | 编辑名称、显示名、描述、关联插件、删除 |
|
|
@@ -584,15 +613,16 @@ src/nonebot_plugin_ruok/
|
|
|
584
613
|
- `webui_test_utils.py`:FastAPI `TestClient`、WebUI 登录、模块/通知测试辅助函数。
|
|
585
614
|
- `plugin_test.py`:NoneBot `/ruok` 命令、绑定、重设密码、状态查询、确认/解决等交互测试。
|
|
586
615
|
- `test_collector.py`:指标采集、进程快照、网络/磁盘速率追踪。
|
|
587
|
-
- `test_sessions.py`:Session CRUD
|
|
616
|
+
- `test_sessions.py`:Session CRUD、筛选、搜索、关联、统计、插件影响索引、批量状态变更与陈旧判定。
|
|
588
617
|
- `test_modules.py`:模块 CRUD、直接/插件传播状态推导、相关 Session 查询。
|
|
589
618
|
- `test_web_api.py`:API key 与路由优先级回归测试。
|
|
590
619
|
- `test_web_api_auth.py`:登录、注册、绑定、记住登录、密码重设、鉴权边界。
|
|
591
620
|
- `test_web_api_dashboard.py`:管理员/普通用户 Dashboard、趋势图和趋势数据端点。
|
|
592
|
-
- `test_web_api_sessions.py`:Session WebUI、Session API
|
|
621
|
+
- `test_web_api_sessions.py`:Session WebUI、Session API、影响插件编辑、批量面板与批量 action。
|
|
593
622
|
- `test_web_api_modules.py`:模块 WebUI 列表、详情、编辑、删除。
|
|
594
623
|
- `test_web_api_notifications.py`:通知规则 WebUI 列表、详情、编辑、删除。
|
|
595
624
|
- `test_web_api_users.py`:用户管理与普通用户自助账号操作。
|
|
625
|
+
- `test_webui_sessions_perf.py`:Session 读取路径与批量 action 的单次目录扫描、事件循环不阻塞回归。
|
|
596
626
|
|
|
597
627
|
## 开发
|
|
598
628
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "nonebot-plugin-ruok"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2"
|
|
4
4
|
description = "Bot health monitoring, session tracking, and WebUI for NoneBot2"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -53,7 +53,7 @@ requires = ["uv_build>=0.11.0,<0.12.0"]
|
|
|
53
53
|
build-backend = "uv_build"
|
|
54
54
|
|
|
55
55
|
[tool.bumpversion]
|
|
56
|
-
current_version = "0.4.
|
|
56
|
+
current_version = "0.4.2"
|
|
57
57
|
commit = true
|
|
58
58
|
message = "release: bump vesion from {current_version} to {new_version}"
|
|
59
59
|
tag = true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "nonebot-plugin-ruok"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2"
|
|
4
4
|
description = "Bot health monitoring, session tracking, and WebUI for NoneBot2"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -53,7 +53,7 @@ build-backend = "uv_build"
|
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
[tool.bumpversion]
|
|
56
|
-
current_version = "0.4.
|
|
56
|
+
current_version = "0.4.2"
|
|
57
57
|
commit = true
|
|
58
58
|
message = "release: bump vesion from {current_version} to {new_version}"
|
|
59
59
|
tag = true
|
|
@@ -30,6 +30,7 @@ Scope:`src/nonebot_plugin_ruok/`(Python 包根)。在进入子目录前请
|
|
|
30
30
|
|
|
31
31
|
- Startup 必须零配置可用;非 ASGI 驱动跳过 ASGI 挂载。
|
|
32
32
|
- APScheduler、监控、通知、指标、摘要调度均为 **best-effort**;失败要记录日志且不得拖垮主 Bot。
|
|
33
|
+
陈旧待确认自动清理由 `register_stale_cleanup_job` 在 startup 注册,同样受此约束。
|
|
33
34
|
- 配置统一走 `ScopedConfig`,dotenv 键保持 `RUOK__...`。
|
|
34
35
|
- API key(`/ruok/api/*`)与 WebUI 认证相互独立;改动任一侧时不要串用另一侧的守卫。
|
|
35
36
|
- 健康聚合值(`available`/`degraded`/`unavailable`)与单项检查值
|
|
@@ -42,6 +43,9 @@ Scope:`src/nonebot_plugin_ruok/`(Python 包根)。在进入子目录前请
|
|
|
42
43
|
## 配置约束(config.py)
|
|
43
44
|
|
|
44
45
|
- `cache_ttl` 必须为有限值且 `>= 0.5` 秒;`webui_session_ttl` 必须为正整数。
|
|
46
|
+
- `stale_pending_after_hours` 用 `ge=0.0` 保留零值语义:`0` 同时关闭陈旧计数、WebUI 陈旧入口
|
|
47
|
+
与定时清理;`stale_pending_resolve_status` 只接受 `solved`/`ignored`(终态),默认
|
|
48
|
+
`ignored`,避免自动清理把真实缺陷标为已修复。
|
|
45
49
|
- 空值语义:`webui_admin_password` 为空会禁用**整个 WebUI 登录**(含内置 admin 与普通用户,
|
|
46
50
|
见 `webui/auth.py` `admin_configured` 分支);`api_key` 为空时受保护的 `/ruok/api/*` 端点
|
|
47
51
|
返回 401 而非公开(`/health` 除外)。
|
|
@@ -729,6 +729,14 @@ async def _startup() -> None:
|
|
|
729
729
|
except Exception as exc:
|
|
730
730
|
logger.warning(f"RUOK: summary job registration failed: {exc}")
|
|
731
731
|
|
|
732
|
+
# Register stale pending cleanup (best-effort, APScheduler optional)
|
|
733
|
+
try:
|
|
734
|
+
from .collectors.sessions import register_stale_cleanup_job
|
|
735
|
+
|
|
736
|
+
register_stale_cleanup_job(plugin_config, data_dir)
|
|
737
|
+
except Exception as exc:
|
|
738
|
+
logger.warning(f"RUOK: stale cleanup job registration failed: {exc}")
|
|
739
|
+
|
|
732
740
|
logger.info("RUOK plugin started")
|
|
733
741
|
|
|
734
742
|
|
|
@@ -168,7 +168,8 @@ def create_ruok_router(config: ScopedConfig, data_dir: Path) -> APIRouter:
|
|
|
168
168
|
status_code=400,
|
|
169
169
|
detail="Invalid ISO datetime filter",
|
|
170
170
|
) from exc
|
|
171
|
-
sessions =
|
|
171
|
+
sessions = await asyncio.to_thread(
|
|
172
|
+
list_sessions,
|
|
172
173
|
data_dir,
|
|
173
174
|
status=status,
|
|
174
175
|
module_name=module,
|
|
@@ -239,7 +240,7 @@ def create_ruok_router(config: ScopedConfig, data_dir: Path) -> APIRouter:
|
|
|
239
240
|
@router.get("/sessions/stats")
|
|
240
241
|
async def api_session_stats(_: None = Depends(_require_api_key)) -> dict[str, Any]:
|
|
241
242
|
"""Return aggregate session statistics."""
|
|
242
|
-
stats = get_session_stats
|
|
243
|
+
stats = await asyncio.to_thread(get_session_stats, data_dir)
|
|
243
244
|
return stats.model_dump(mode="json")
|
|
244
245
|
|
|
245
246
|
@router.get("/sessions/{session_id}")
|
|
@@ -354,10 +355,10 @@ def create_ruok_router(config: ScopedConfig, data_dir: Path) -> APIRouter:
|
|
|
354
355
|
_: None = Depends(_require_api_key),
|
|
355
356
|
) -> dict[str, Any]:
|
|
356
357
|
"""Get all sessions in the same link_group."""
|
|
357
|
-
session = get_session
|
|
358
|
+
session = await asyncio.to_thread(get_session, data_dir, session_id)
|
|
358
359
|
if session is None:
|
|
359
360
|
raise HTTPException(status_code=404, detail="Session not found")
|
|
360
|
-
linked = get_linked_sessions
|
|
361
|
+
linked = await asyncio.to_thread(get_linked_sessions, data_dir, session_id)
|
|
361
362
|
return {
|
|
362
363
|
"link_group": session.link_group,
|
|
363
364
|
"linked": [s.model_dump(mode="json") for s in linked],
|
|
@@ -370,7 +371,8 @@ def create_ruok_router(config: ScopedConfig, data_dir: Path) -> APIRouter:
|
|
|
370
371
|
_: None = Depends(_require_api_key),
|
|
371
372
|
) -> list[dict[str, Any]]:
|
|
372
373
|
"""List modules with real-time status."""
|
|
373
|
-
|
|
374
|
+
modules = await asyncio.to_thread(list_modules, data_dir, config)
|
|
375
|
+
return [m.model_dump(mode="json") for m in modules]
|
|
374
376
|
|
|
375
377
|
@router.get("/modules/{name}")
|
|
376
378
|
async def api_get_module(
|
|
@@ -378,7 +380,7 @@ def create_ruok_router(config: ScopedConfig, data_dir: Path) -> APIRouter:
|
|
|
378
380
|
_: None = Depends(_require_api_key),
|
|
379
381
|
) -> dict[str, Any]:
|
|
380
382
|
"""Get one module."""
|
|
381
|
-
mod = get_module
|
|
383
|
+
mod = await asyncio.to_thread(get_module, data_dir, config, name)
|
|
382
384
|
if mod is None:
|
|
383
385
|
raise HTTPException(status_code=404, detail="Module not found")
|
|
384
386
|
return mod.model_dump(mode="json")
|
{nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collector.py
RENAMED
|
@@ -19,10 +19,13 @@ from .protocol import MetricPoint
|
|
|
19
19
|
|
|
20
20
|
# ── Re-export everything from the collectors subpackage ──
|
|
21
21
|
from .collectors import (
|
|
22
|
+
BULK_MAX_SESSIONS,
|
|
22
23
|
# monitor
|
|
23
24
|
LogMonitor,
|
|
24
25
|
# trackers
|
|
25
26
|
DiskRateTracker,
|
|
27
|
+
SessionSnapshot,
|
|
28
|
+
BulkSessionResult,
|
|
26
29
|
NetworkRateTracker,
|
|
27
30
|
SessionPluginValidationError,
|
|
28
31
|
SessionUpdateValidationError,
|
|
@@ -35,6 +38,7 @@ from .collectors import (
|
|
|
35
38
|
delete_module,
|
|
36
39
|
link_sessions,
|
|
37
40
|
list_sessions,
|
|
41
|
+
load_sessions,
|
|
38
42
|
upsert_module,
|
|
39
43
|
create_session,
|
|
40
44
|
unlink_session,
|
|
@@ -42,11 +46,15 @@ from .collectors import (
|
|
|
42
46
|
# sessions
|
|
43
47
|
_network_tracker,
|
|
44
48
|
get_session_stats,
|
|
49
|
+
module_plugin_map,
|
|
50
|
+
stale_pending_ids,
|
|
45
51
|
_handle_ruok_error,
|
|
46
52
|
resolve_log_source,
|
|
47
53
|
_connection_history,
|
|
54
|
+
count_stale_pending,
|
|
48
55
|
get_linked_sessions,
|
|
49
56
|
build_plugin_impacts,
|
|
57
|
+
bulk_update_sessions,
|
|
50
58
|
collect_all_statuses,
|
|
51
59
|
collect_fast_metrics,
|
|
52
60
|
derive_module_status,
|
|
@@ -58,17 +66,22 @@ from .collectors import (
|
|
|
58
66
|
collect_process_snapshot,
|
|
59
67
|
# metrics (webui/router)
|
|
60
68
|
_collect_plugin_inventory,
|
|
69
|
+
bulk_resolve_stale_pending,
|
|
70
|
+
register_stale_cleanup_job,
|
|
61
71
|
list_module_related_sessions,
|
|
62
72
|
derive_module_status_with_reasons,
|
|
63
73
|
)
|
|
64
74
|
from .collectors.storage import locked_file, atomic_write_text
|
|
65
75
|
|
|
66
76
|
__all__ = [
|
|
77
|
+
"BULK_MAX_SESSIONS",
|
|
78
|
+
"BulkSessionResult",
|
|
67
79
|
"DiskRateTracker",
|
|
68
80
|
"LogMonitor",
|
|
69
81
|
"MetricsStore",
|
|
70
82
|
"NetworkRateTracker",
|
|
71
83
|
"SessionPluginValidationError",
|
|
84
|
+
"SessionSnapshot",
|
|
72
85
|
"SessionUpdateValidationError",
|
|
73
86
|
"_collect_plugin_inventory",
|
|
74
87
|
"_connection_history",
|
|
@@ -76,10 +89,13 @@ __all__ = [
|
|
|
76
89
|
"_network_tracker",
|
|
77
90
|
"_startup_time",
|
|
78
91
|
"build_plugin_impacts",
|
|
92
|
+
"bulk_resolve_stale_pending",
|
|
93
|
+
"bulk_update_sessions",
|
|
79
94
|
"collect_all_statuses",
|
|
80
95
|
"collect_fast_metrics",
|
|
81
96
|
"collect_process_snapshot",
|
|
82
97
|
"confirm_session_plugins",
|
|
98
|
+
"count_stale_pending",
|
|
83
99
|
"create_session",
|
|
84
100
|
"delete_module",
|
|
85
101
|
"derive_module_status",
|
|
@@ -93,10 +109,14 @@ __all__ = [
|
|
|
93
109
|
"list_module_related_sessions",
|
|
94
110
|
"list_modules",
|
|
95
111
|
"list_sessions",
|
|
112
|
+
"load_sessions",
|
|
113
|
+
"module_plugin_map",
|
|
96
114
|
"parse_filter_datetime",
|
|
97
115
|
"rebuild_plugin_impacts",
|
|
116
|
+
"register_stale_cleanup_job",
|
|
98
117
|
"resolve_log_source",
|
|
99
118
|
"resolve_module_display",
|
|
119
|
+
"stale_pending_ids",
|
|
100
120
|
"unlink_session",
|
|
101
121
|
"update_session",
|
|
102
122
|
"upsert_module",
|
{nonebot_plugin_ruok-0.4.0 → nonebot_plugin_ruok-0.4.2}/src/nonebot_plugin_ruok/collectors/AGENTS.md
RENAMED
|
@@ -40,6 +40,12 @@ Scope:`src/nonebot_plugin_ruok/collectors/`。先读根 `AGENTS.md` 与包级
|
|
|
40
40
|
pending 经当前插件传播 `degraded`;confirmed 仅经持久化 `affected_plugins` 传播 `unavailable`;
|
|
41
41
|
`unavailable` 优先;`list_module_related_sessions()` 合并直接与经共享插件影响的 Session 并去重。
|
|
42
42
|
- 设置 `affected_plugins` 必须走 `confirm_session_plugins(...)`。
|
|
43
|
+
- 批量状态变更必须走 `bulk_update_sessions(...)`:单次 `_data_dir_lock`、结束时最多一次
|
|
44
|
+
`rebuild_plugin_impacts()`、只发一条聚合 SSE 事件。逐行调用 `update_session` 会按行重建
|
|
45
|
+
影响索引(每次全目录扫描),不得用于批量维护。
|
|
46
|
+
- 批量只处理 `pending`/`unsolved`;目标状态与现状一致时不写盘,缺失/非法 id 记入返回值
|
|
47
|
+
而不是抛异常。
|
|
48
|
+
- 陈旧判定用 `last_seen_at < cutoff`(与列表排序、行内时间一致),不用 `first_seen_at`。
|
|
43
49
|
- 通知规则按状态与直接模块名匹配;冷却键为 `rule.name:session.module_name`;
|
|
44
50
|
dispatch 先原子声明再发送,全通道失败才释放声明。
|
|
45
51
|
- 指标/通知/自动采集保持 best-effort,不得拖垮主插件。
|
|
@@ -16,6 +16,7 @@ from .modules import (
|
|
|
16
16
|
list_modules,
|
|
17
17
|
delete_module,
|
|
18
18
|
upsert_module,
|
|
19
|
+
module_plugin_map,
|
|
19
20
|
resolve_log_source,
|
|
20
21
|
derive_module_status,
|
|
21
22
|
resolve_module_display,
|
|
@@ -27,6 +28,9 @@ from .monitor import (
|
|
|
27
28
|
_make_log_sink,
|
|
28
29
|
)
|
|
29
30
|
from .sessions import (
|
|
31
|
+
BULK_MAX_SESSIONS,
|
|
32
|
+
SessionSnapshot,
|
|
33
|
+
BulkSessionResult,
|
|
30
34
|
SessionPluginValidationError,
|
|
31
35
|
SessionUpdateValidationError,
|
|
32
36
|
get_session,
|
|
@@ -34,20 +38,26 @@ from .sessions import (
|
|
|
34
38
|
_save_session,
|
|
35
39
|
link_sessions,
|
|
36
40
|
list_sessions,
|
|
41
|
+
load_sessions,
|
|
37
42
|
create_session,
|
|
38
43
|
unlink_session,
|
|
39
44
|
update_session,
|
|
40
45
|
_gen_session_id,
|
|
41
46
|
_make_signature,
|
|
42
47
|
get_session_stats,
|
|
48
|
+
stale_pending_ids,
|
|
43
49
|
_handle_ruok_error,
|
|
50
|
+
count_stale_pending,
|
|
44
51
|
get_linked_sessions,
|
|
45
52
|
build_plugin_impacts,
|
|
53
|
+
bulk_update_sessions,
|
|
46
54
|
parse_filter_datetime,
|
|
47
55
|
_find_existing_session,
|
|
48
56
|
_publish_session_event,
|
|
49
57
|
rebuild_plugin_impacts,
|
|
50
58
|
confirm_session_plugins,
|
|
59
|
+
bulk_resolve_stale_pending,
|
|
60
|
+
register_stale_cleanup_job,
|
|
51
61
|
)
|
|
52
62
|
from .trackers import (
|
|
53
63
|
DiskRateTracker,
|
|
@@ -62,10 +72,13 @@ from .notifications import (
|
|
|
62
72
|
)
|
|
63
73
|
|
|
64
74
|
__all__ = [
|
|
75
|
+
"BULK_MAX_SESSIONS",
|
|
76
|
+
"BulkSessionResult",
|
|
65
77
|
"DiskRateTracker",
|
|
66
78
|
"LogMonitor",
|
|
67
79
|
"NetworkRateTracker",
|
|
68
80
|
"SessionPluginValidationError",
|
|
81
|
+
"SessionSnapshot",
|
|
69
82
|
"SessionUpdateValidationError",
|
|
70
83
|
"_collect_bot_info",
|
|
71
84
|
"_collect_connection_status",
|
|
@@ -84,10 +97,13 @@ __all__ = [
|
|
|
84
97
|
"_save_session",
|
|
85
98
|
"_startup_time",
|
|
86
99
|
"build_plugin_impacts",
|
|
100
|
+
"bulk_resolve_stale_pending",
|
|
101
|
+
"bulk_update_sessions",
|
|
87
102
|
"collect_all_statuses",
|
|
88
103
|
"collect_fast_metrics",
|
|
89
104
|
"collect_process_snapshot",
|
|
90
105
|
"confirm_session_plugins",
|
|
106
|
+
"count_stale_pending",
|
|
91
107
|
"create_session",
|
|
92
108
|
"delete_module",
|
|
93
109
|
"derive_module_status",
|
|
@@ -101,12 +117,16 @@ __all__ = [
|
|
|
101
117
|
"list_module_related_sessions",
|
|
102
118
|
"list_modules",
|
|
103
119
|
"list_sessions",
|
|
120
|
+
"load_sessions",
|
|
104
121
|
"locked_rules",
|
|
122
|
+
"module_plugin_map",
|
|
105
123
|
"parse_filter_datetime",
|
|
106
124
|
"rebuild_plugin_impacts",
|
|
125
|
+
"register_stale_cleanup_job",
|
|
107
126
|
"register_summary_job",
|
|
108
127
|
"resolve_log_source",
|
|
109
128
|
"resolve_module_display",
|
|
129
|
+
"stale_pending_ids",
|
|
110
130
|
"unlink_session",
|
|
111
131
|
"update_session",
|
|
112
132
|
"upsert_module",
|
|
@@ -16,7 +16,7 @@ from nonebot import get_driver
|
|
|
16
16
|
|
|
17
17
|
from ..config import ScopedConfig
|
|
18
18
|
from .modules import list_modules
|
|
19
|
-
from .sessions import
|
|
19
|
+
from .sessions import SessionSnapshot, load_sessions
|
|
20
20
|
from ..protocol import (
|
|
21
21
|
CheckResult,
|
|
22
22
|
MetricPoint,
|
|
@@ -25,6 +25,7 @@ from ..protocol import (
|
|
|
25
25
|
StatusResult,
|
|
26
26
|
ProcessSnapshot,
|
|
27
27
|
AggregatedStatus,
|
|
28
|
+
ModuleDefinition,
|
|
28
29
|
PluginHealthInfo,
|
|
29
30
|
BotConnectionStatus,
|
|
30
31
|
FastMetricsSnapshot,
|
|
@@ -382,9 +383,16 @@ _startup_time: float | None = None
|
|
|
382
383
|
|
|
383
384
|
|
|
384
385
|
async def collect_all_statuses(
|
|
385
|
-
config: ScopedConfig,
|
|
386
|
+
config: ScopedConfig,
|
|
387
|
+
data_dir: Path,
|
|
388
|
+
*,
|
|
389
|
+
snapshot: SessionSnapshot | None = None,
|
|
386
390
|
) -> AggregatedStatus:
|
|
387
|
-
"""Gather all health data into a single AggregatedStatus.
|
|
391
|
+
"""Gather all health data into a single AggregatedStatus.
|
|
392
|
+
|
|
393
|
+
``snapshot`` lets a caller that already read the sessions directory reuse
|
|
394
|
+
that read for module status and the appended metric point.
|
|
395
|
+
"""
|
|
388
396
|
global _startup_time
|
|
389
397
|
if _startup_time is None:
|
|
390
398
|
_startup_time = time.time()
|
|
@@ -425,9 +433,20 @@ async def collect_all_statuses(
|
|
|
425
433
|
pass
|
|
426
434
|
plugins = _collect_plugin_inventory()
|
|
427
435
|
|
|
436
|
+
# Module status derivation and the metric counters both need the session
|
|
437
|
+
# directory; load it once and keep that work off the event loop.
|
|
438
|
+
if snapshot is None:
|
|
439
|
+
try:
|
|
440
|
+
snapshot = await asyncio.to_thread(load_sessions, data_dir)
|
|
441
|
+
except (json.JSONDecodeError, OSError, ValueError):
|
|
442
|
+
snapshot = None
|
|
443
|
+
|
|
428
444
|
# Load module definitions (with real-time derived status)
|
|
445
|
+
modules: list[ModuleDefinition] = []
|
|
429
446
|
try:
|
|
430
|
-
modules =
|
|
447
|
+
modules = await asyncio.to_thread(
|
|
448
|
+
list_modules, data_dir, config, snapshot=snapshot
|
|
449
|
+
)
|
|
431
450
|
except (json.JSONDecodeError, OSError, ValueError):
|
|
432
451
|
modules = []
|
|
433
452
|
|
|
@@ -512,21 +531,20 @@ async def collect_all_statuses(
|
|
|
512
531
|
cpu_pct = _extract_cpu_percent(sys_results)
|
|
513
532
|
mem_pct = _extract_memory_percent(sys_results)
|
|
514
533
|
disk_pct = _extract_disk_percent(sys_results)
|
|
515
|
-
sessions =
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
retention_days=config.metrics_retention_days,
|
|
534
|
+
sessions = snapshot.sessions if snapshot is not None else []
|
|
535
|
+
point = MetricPoint(
|
|
536
|
+
ts=datetime.now(timezone.utc).isoformat(),
|
|
537
|
+
cpu_percent=cpu_pct,
|
|
538
|
+
memory_percent=mem_pct,
|
|
539
|
+
disk_percent=disk_pct,
|
|
540
|
+
sessions_total=len(sessions),
|
|
541
|
+
sessions_pending=sum(1 for s in sessions if s.status == "pending"),
|
|
542
|
+
sessions_unsolved=sum(1 for s in sessions if s.status == "unsolved"),
|
|
543
|
+
connections_total=len(connections),
|
|
544
|
+
connections_online=sum(1 for c in connections if c.connected),
|
|
545
|
+
)
|
|
546
|
+
await asyncio.to_thread(
|
|
547
|
+
MetricsStore.append, data_dir, point, config.metrics_retention_days
|
|
530
548
|
)
|
|
531
549
|
except (json.JSONDecodeError, OSError, ValueError):
|
|
532
550
|
pass # Metrics are best-effort
|