From b53410bc777f337fffa70ac432d32ed0fb96cb5c Mon Sep 17 00:00:00 2001 From: qinglong Date: Sat, 13 Jun 2026 17:54:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Sentinel=20SSE=20=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E8=BD=AE=E8=AF=A2=E9=83=BD=E6=8E=A8=E9=80=81=20(=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=80=A7)=20+=20isolation=20=E9=BB=98=E8=AE=A4=20fals?= =?UTF-8?q?e=20+=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sentinel: - poll_interval 3s→2s, 每次轮询都推 SSE (不再等状态变化) - 解决稳定状态下数据更新不实时问题 插件系统: - 默认 isolation: false (避免插件 WebUI 不显示) - example_plugin 显式设置 isolation: false - 插件开发指南: settings 示例增加 isolation 说明 Co-Authored-By: Claude --- config/framework/base_config.yaml.example | 2 +- docs/SenSu 插件开发详细指南.md | 1 + plugins/example_plugin/config.yaml | 1 + plugins/sentinel/__init__.py | 11 +++-------- plugins/sentinel/config.yaml | 2 +- services/init_service.py | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/config/framework/base_config.yaml.example b/config/framework/base_config.yaml.example index fad04b6..b3d3dfa 100644 --- a/config/framework/base_config.yaml.example +++ b/config/framework/base_config.yaml.example @@ -11,7 +11,7 @@ plugins: auto_load: true hot_reload: true max_retry_count: 3 - isolation: true + isolation: false # 自动启动脚本 — 框架启动时后台拉起 auto_start_scripts: enabled: true diff --git a/docs/SenSu 插件开发详细指南.md b/docs/SenSu 插件开发详细指南.md index e275b29..10fc181 100644 --- a/docs/SenSu 插件开发详细指南.md +++ b/docs/SenSu 插件开发详细指南.md @@ -156,6 +156,7 @@ license: "MIT" # 开源许可证 settings: enabled: true # 是否启用 auto_start: true # 是否自动启动 + isolation: false # 进程隔离: true=独立子进程(无WebUI), false=框架内运行(支持WebUI/网络路由) log_level: "INFO" # 日志级别:DEBUG, INFO, WARNING, ERROR max_retry_count: 3 # 失败重试次数 health_check_interval: 60 # 健康检查间隔(秒) diff --git a/plugins/example_plugin/config.yaml b/plugins/example_plugin/config.yaml index 3cd7d09..4c8c4b5 100644 --- a/plugins/example_plugin/config.yaml +++ b/plugins/example_plugin/config.yaml @@ -9,6 +9,7 @@ settings: enabled: true auto_start: true log_level: "INFO" + isolation: false # 示例功能配置 features: diff --git a/plugins/sentinel/__init__.py b/plugins/sentinel/__init__.py index 9f8a0c6..b4ed5bf 100644 --- a/plugins/sentinel/__init__.py +++ b/plugins/sentinel/__init__.py @@ -175,23 +175,18 @@ class Plugin(PluginWebMixin): async def _poll_loop(self, interval: int): while self._running: nodes = self._get_nodes() - changed = False for node in nodes: if not node.get("enabled", True): continue - prev = _NODE_CACHE.get(node.get("id", ""), {}) online, sys_info, err = await self._fetch_system(node) - new_status = { + _NODE_CACHE[node.get("id", "")] = { "online": online, "system": sys_info or {}, "last_seen": time.time(), "error": err if not online else "", } - if (prev.get("online") != online - or abs(prev.get("last_seen", 0) - new_status["last_seen"]) > 5): - changed = True - _NODE_CACHE[node.get("id", "")] = new_status - if changed: + # 每次轮询都推送 SSE (确保实时性) + if nodes: await self.push_sse_event("nodes_update", {"nodes": self._build_cache_list()}) await asyncio.sleep(interval) diff --git a/plugins/sentinel/config.yaml b/plugins/sentinel/config.yaml index 345f35b..d18c756 100644 --- a/plugins/sentinel/config.yaml +++ b/plugins/sentinel/config.yaml @@ -11,6 +11,6 @@ nodes: settings: auto_start: true isolation: false - poll_interval: 3 + poll_interval: 2 request_timeout: 5 version: 1.0.0 diff --git a/services/init_service.py b/services/init_service.py index c3bd043..57f3cd2 100644 --- a/services/init_service.py +++ b/services/init_service.py @@ -228,7 +228,7 @@ class InitService: 'auto_load': True, 'hot_reload': True, 'max_retry_count': 3, - 'isolation': True, # 生产默认进程隔离,插件崩溃不影响框架 + 'isolation': False, # 默认不隔离 (需要 Web 页面的插件必须非隔离) }, 'auto_start_scripts': { 'enabled': True,