From f7722be539888e74f6a23160da158d7f61b1da80 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Mon, 1 Jun 2026 20:35:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B3=BB=E7=BB=9F=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=9C=AA=E5=BC=80=E5=AE=9E=E6=97=B6=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E6=97=B6=E6=8C=89=E9=A1=B5=E9=9D=A2=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 systemRefreshTimer,切换至系统Tab时自动启动 - 未开实时监控 → 按页面「刷新间隔」秒数定时刷新系统资源 - 开启实时监控 → 按实时间隔秒数刷新(原有逻辑不变) - 关闭实时监控 → 切回页面刷新间隔继续更新 - 修改页面刷新间隔 → 同步更新系统资源刷新频率 - 新增 watchdog.sh 守护脚本,端口掉线自动重启 --- templates_full.txt | 39 +++++++++++++++++++++++++++++++++++---- watchdog.sh | 24 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 watchdog.sh diff --git a/templates_full.txt b/templates_full.txt index 675dd04..85ca0e0 100644 --- a/templates_full.txt +++ b/templates_full.txt @@ -929,6 +929,7 @@ // Tab 切换 // 系统资源监控变量(必须先声明) let realtimeTimer = null; + let systemRefreshTimer = null; let realtimeInterval = 2; // 秒 let lastAlertTime = 0; // 上次警告时间 let thresholds = { cpu: 80, cpu_temp: 80, memory: 85, disk: 90, interval: 60 }; @@ -957,6 +958,12 @@ document.getElementById('processListSection').classList.add('hidden'); } + // 离开系统Tab时关闭非实时刷新定时器 + if (tab !== 'system' && systemRefreshTimer) { + clearInterval(systemRefreshTimer); + systemRefreshTimer = null; + } + if (tab === 'cron') { loadCronTasks(); } @@ -965,6 +972,8 @@ loadDesktopNotifySetting(); renderEmailRules(); loadSystemStats(); + // 启动系统资源定时刷新(按页面刷新间隔) + startSystemRefresh(); } } @@ -1281,14 +1290,17 @@ const toggle = document.getElementById('realtimeToggle'); const indicator = document.getElementById('realtimeIndicator'); + // 先停止系统定时刷新 + if (systemRefreshTimer) { + clearInterval(systemRefreshTimer); + systemRefreshTimer = null; + } + if (checked) { toggle.classList.add('active'); indicator.classList.remove('hidden'); - // 立即加载一次 loadSystemStats(); - // 启动定时器 realtimeTimer = setInterval(loadSystemStats, realtimeInterval * 1000); - // 如果进程列表开关也开启,则显示并加载 if (document.getElementById('showProcessListCheck').checked) { document.getElementById('processListSection').classList.remove('hidden'); loadTopProcesses(); @@ -1297,14 +1309,28 @@ toggle.classList.remove('active'); indicator.classList.add('hidden'); document.getElementById('processListSection').classList.add('hidden'); - // 停止定时器 if (realtimeTimer) { clearInterval(realtimeTimer); realtimeTimer = null; } + // 关闭实时后,按页面刷新间隔继续刷新系统资源 + startSystemRefresh(); } } + function startSystemRefresh() { + // 先停掉旧定时器 + if (systemRefreshTimer) { + clearInterval(systemRefreshTimer); + systemRefreshTimer = null; + } + // 如果在实时监控模式则不启动(由realtimeTimer负责) + if (document.getElementById('realtimeCheck').checked) return; + // 按页面刷新间隔定时刷新 + const intervalSec = parseInt(document.getElementById('refreshInterval').value) || 30; + systemRefreshTimer = setInterval(loadSystemStats, intervalSec * 1000); + } + function toggleProcessList() { const checked = document.getElementById('showProcessListCheck').checked; const realtimeChecked = document.getElementById('realtimeCheck').checked; @@ -2751,6 +2777,11 @@ clearInterval(refreshTimer); refreshTimer = setInterval(() => { if (currentTab === 'projects') loadProjects(); }, seconds * 1000); + + // 如果当前在系统Tab且非实时模式,更新系统刷新间隔 + if (currentTab === 'system' && !document.getElementById('realtimeCheck').checked) { + startSystemRefresh(); + } } setInterval(() => { diff --git a/watchdog.sh b/watchdog.sh new file mode 100755 index 0000000..a40ab28 --- /dev/null +++ b/watchdog.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# project-panel 守护脚本 - 进程挂了自动重启 +SERVICE_DIR="/home/openclaw/.openclaw/workspace-hz4th_coder/works/project-panel" +PYTHON="/home/hz1/miniconda3/envs/openclaw/bin/python3.12" +PORT=16022 +LOG="$SERVICE_DIR/logs/watchdog.log" + +echo "[$(date '+%Y-%m-%d %H:%M:%S')] 守护进程启动,监控端口 $PORT" >> "$LOG" + +while true; do + if ! ss -tlnp 2>/dev/null | grep -q ":$PORT "; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] 检测到 $PORT 端口离线,重启服务..." >> "$LOG" + cd "$SERVICE_DIR" + mkdir -p logs + nohup "$PYTHON" app.py > logs/app.log 2>&1 & + sleep 3 + if ss -tlnp 2>/dev/null | grep -q ":$PORT "; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] 服务重启成功" >> "$LOG" + else + echo "[$(date '+%Y-%m-%d %H:%M:%S')] 服务重启失败!" >> "$LOG" + fi + fi + sleep 10 +done