fix: 系统资源面板未开实时监控时按页面刷新间隔自动更新
- 新增 systemRefreshTimer,切换至系统Tab时自动启动 - 未开实时监控 → 按页面「刷新间隔」秒数定时刷新系统资源 - 开启实时监控 → 按实时间隔秒数刷新(原有逻辑不变) - 关闭实时监控 → 切回页面刷新间隔继续更新 - 修改页面刷新间隔 → 同步更新系统资源刷新频率 - 新增 watchdog.sh 守护脚本,端口掉线自动重启
This commit is contained in:
@@ -929,6 +929,7 @@
|
|||||||
// Tab 切换
|
// Tab 切换
|
||||||
// 系统资源监控变量(必须先声明)
|
// 系统资源监控变量(必须先声明)
|
||||||
let realtimeTimer = null;
|
let realtimeTimer = null;
|
||||||
|
let systemRefreshTimer = null;
|
||||||
let realtimeInterval = 2; // 秒
|
let realtimeInterval = 2; // 秒
|
||||||
let lastAlertTime = 0; // 上次警告时间
|
let lastAlertTime = 0; // 上次警告时间
|
||||||
let thresholds = { cpu: 80, cpu_temp: 80, memory: 85, disk: 90, interval: 60 };
|
let thresholds = { cpu: 80, cpu_temp: 80, memory: 85, disk: 90, interval: 60 };
|
||||||
@@ -957,6 +958,12 @@
|
|||||||
document.getElementById('processListSection').classList.add('hidden');
|
document.getElementById('processListSection').classList.add('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 离开系统Tab时关闭非实时刷新定时器
|
||||||
|
if (tab !== 'system' && systemRefreshTimer) {
|
||||||
|
clearInterval(systemRefreshTimer);
|
||||||
|
systemRefreshTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (tab === 'cron') {
|
if (tab === 'cron') {
|
||||||
loadCronTasks();
|
loadCronTasks();
|
||||||
}
|
}
|
||||||
@@ -965,6 +972,8 @@
|
|||||||
loadDesktopNotifySetting();
|
loadDesktopNotifySetting();
|
||||||
renderEmailRules();
|
renderEmailRules();
|
||||||
loadSystemStats();
|
loadSystemStats();
|
||||||
|
// 启动系统资源定时刷新(按页面刷新间隔)
|
||||||
|
startSystemRefresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1281,14 +1290,17 @@
|
|||||||
const toggle = document.getElementById('realtimeToggle');
|
const toggle = document.getElementById('realtimeToggle');
|
||||||
const indicator = document.getElementById('realtimeIndicator');
|
const indicator = document.getElementById('realtimeIndicator');
|
||||||
|
|
||||||
|
// 先停止系统定时刷新
|
||||||
|
if (systemRefreshTimer) {
|
||||||
|
clearInterval(systemRefreshTimer);
|
||||||
|
systemRefreshTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
toggle.classList.add('active');
|
toggle.classList.add('active');
|
||||||
indicator.classList.remove('hidden');
|
indicator.classList.remove('hidden');
|
||||||
// 立即加载一次
|
|
||||||
loadSystemStats();
|
loadSystemStats();
|
||||||
// 启动定时器
|
|
||||||
realtimeTimer = setInterval(loadSystemStats, realtimeInterval * 1000);
|
realtimeTimer = setInterval(loadSystemStats, realtimeInterval * 1000);
|
||||||
// 如果进程列表开关也开启,则显示并加载
|
|
||||||
if (document.getElementById('showProcessListCheck').checked) {
|
if (document.getElementById('showProcessListCheck').checked) {
|
||||||
document.getElementById('processListSection').classList.remove('hidden');
|
document.getElementById('processListSection').classList.remove('hidden');
|
||||||
loadTopProcesses();
|
loadTopProcesses();
|
||||||
@@ -1297,14 +1309,28 @@
|
|||||||
toggle.classList.remove('active');
|
toggle.classList.remove('active');
|
||||||
indicator.classList.add('hidden');
|
indicator.classList.add('hidden');
|
||||||
document.getElementById('processListSection').classList.add('hidden');
|
document.getElementById('processListSection').classList.add('hidden');
|
||||||
// 停止定时器
|
|
||||||
if (realtimeTimer) {
|
if (realtimeTimer) {
|
||||||
clearInterval(realtimeTimer);
|
clearInterval(realtimeTimer);
|
||||||
realtimeTimer = null;
|
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() {
|
function toggleProcessList() {
|
||||||
const checked = document.getElementById('showProcessListCheck').checked;
|
const checked = document.getElementById('showProcessListCheck').checked;
|
||||||
const realtimeChecked = document.getElementById('realtimeCheck').checked;
|
const realtimeChecked = document.getElementById('realtimeCheck').checked;
|
||||||
@@ -2751,6 +2777,11 @@
|
|||||||
|
|
||||||
clearInterval(refreshTimer);
|
clearInterval(refreshTimer);
|
||||||
refreshTimer = setInterval(() => { if (currentTab === 'projects') loadProjects(); }, seconds * 1000);
|
refreshTimer = setInterval(() => { if (currentTab === 'projects') loadProjects(); }, seconds * 1000);
|
||||||
|
|
||||||
|
// 如果当前在系统Tab且非实时模式,更新系统刷新间隔
|
||||||
|
if (currentTab === 'system' && !document.getElementById('realtimeCheck').checked) {
|
||||||
|
startSystemRefresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|||||||
24
watchdog.sh
Executable file
24
watchdog.sh
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user