diff --git a/CHANGELOG.md b/CHANGELOG.md index b44a41f..2fc75be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +## 2026-10-26 → ✨ 概览页新增 CPU / 内存占用 Top 5 + +- ✨ 概览页统计条下方新增两个榜单:**CPU 占用 Top 5**(占整机 %,标注核数)、**内存占用 Top 5**(绝对值 + 占整机比例) +- ✨ 每行带排名、应用名、数值与相对进度条,点击任意一行直接进该应用详情 +- 🔧 左侧菜单「概览」去掉数字徽章(原显示异常应用数) +- 🔧 榜单数据取完整应用列表排序,不受当前筛选/排序影响 + ## 2026-10-26 → ✨ 侧栏显示构建时间(确认是否最新版) - ✨ 侧栏底部显示「构建 10-26 18:01」,等于服务端当前版本时间;页面不是最新版时一眼可辨 diff --git a/public/app.js b/public/app.js index 2e7f8a2..a47a730 100644 --- a/public/app.js +++ b/public/app.js @@ -146,15 +146,14 @@ function avatar(name) { async function renderApps(silent) { const q = state.q ? `&q=${encodeURIComponent(state.q)}` : ''; - const [data, h, ev, ins] = await Promise.all([ + const [data, h, ev, ins, full] = await Promise.all([ api(`/api/apps?filter=${state.filter}&sort=${state.sort}&order=${state.order}${q}`), refreshHost(), api('/api/events?limit=8'), api('/api/insights').catch(() => null), + api('/api/apps?sort=cpu&order=desc').catch(() => null), ]); const s = data.summary; - $('#navIssues').textContent = s.critical + s.warning; - $('#navIssues').className = 'nav-badge' + (s.critical ? ' alert' : s.warning ? ' warn' : ''); const disk = h.disk; const pill = (a) => `${a.statusText}`; const chips = [['all', '全部', s.total], ['issues', '有问题', s.critical + s.warning], ['stopped', '已停止', s.stopped], ['high', '高占用', '']]; @@ -187,6 +186,31 @@ async function renderApps(silent) { `).join(''); + const allApps = (full && full.items) || data.items || []; + const topCpu = [...allApps].sort((x, y) => (y.cpuPctOfMachine || 0) - (x.cpuPctOfMachine || 0)).slice(0, 5); + const topMem = [...allApps].sort((x, y) => (y.mem || 0) - (x.mem || 0)).slice(0, 5); + const memTotal = h.memTotal || 1; + const topRow = (a, i, val, pct, kind) => ` +
+ ${i + 1} + ${esc(a.name)} + ${val} + +
`; + const maxCpu = Math.max(1, ...topCpu.map(a => a.cpuPctOfMachine || 0)); + const maxMem = Math.max(1, ...topMem.map(a => a.mem || 0)); + const topHtml = ` +
+
+
CPU 占用 Top 5占整机 · ${h.cpus} 核
+ ${topCpu.map((a, i) => topRow(a, i, fmtPct(a.cpuPctOfMachine || 0), ((a.cpuPctOfMachine || 0) / maxCpu) * 100, 'cpu')).join('') || '
暂无数据
'} +
+
+
内存占用 Top 5占整机 ${fmtBytes(memTotal)}
+ ${topMem.map((a, i) => topRow(a, i, `${fmtBytes(a.mem || 0)} ${((a.mem || 0) / memTotal * 100).toFixed(1)}%`, ((a.mem || 0) / maxMem) * 100, 'mem')).join('') || '
暂无数据
'} +
+
`; + const insItems = (ins && ins.items) || []; const shownIns = state.insightOpen ? insItems : insItems.slice(0, 4); const insHtml = insItems.length ? ` @@ -229,6 +253,7 @@ async function renderApps(silent) {
运行容器
${h.running}/${h.containers}
镜像 ${h.images} 个
+ ${topHtml} ${insHtml}
@@ -244,6 +269,7 @@ async function renderApps(silent) {
`; $$('#view .chip').forEach(b => b.onclick = () => { state.filter = b.dataset.filter; render(); }); + $$('#view .top-row').forEach(r => r.onclick = () => openApp(r.dataset.top)); const moreBtn = $('#insightMore'); if (moreBtn) moreBtn.onclick = () => { state.insightOpen = !state.insightOpen; render(); }; $$('#view [data-insight]').forEach(b => b.onclick = async (e) => { diff --git a/public/index.html b/public/index.html index d00af6f..801b396 100644 --- a/public/index.html +++ b/public/index.html @@ -16,7 +16,7 @@ 飞牛docker容器管理增强版