feat: 概览页 Top5 CPU/内存榜,概览徽章去掉
This commit is contained in:
1 parent
623666875d
commit
6817e8c87f
4 files changed
+55
-4
No files matched your search
@@ -1,5 +1,12 @@
|
||||
# 更新日志
|
||||
|
||||
## 2026-10-26 → ✨ 概览页新增 CPU / 内存占用 Top 5
|
||||
|
||||
- ✨ 概览页统计条下方新增两个榜单:**CPU 占用 Top 5**(占整机 %,标注核数)、**内存占用 Top 5**(绝对值 + 占整机比例)
|
||||
- ✨ 每行带排名、应用名、数值与相对进度条,点击任意一行直接进该应用详情
|
||||
- 🔧 左侧菜单「概览」去掉数字徽章(原显示异常应用数)
|
||||
- 🔧 榜单数据取完整应用列表排序,不受当前筛选/排序影响
|
||||
|
||||
## 2026-10-26 → ✨ 侧栏显示构建时间(确认是否最新版)
|
||||
|
||||
- ✨ 侧栏底部显示「构建 10-26 18:01」,等于服务端当前版本时间;页面不是最新版时一眼可辨
|
||||
|
||||
+29
-3
@@ -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) => `<span class="pill ${a.severity === 2 ? 'bad' : a.severity === 1 ? 'warn' : 'ok'}">${a.statusText}</span>`;
|
||||
const chips = [['all', '全部', s.total], ['issues', '有问题', s.critical + s.warning], ['stopped', '已停止', s.stopped], ['high', '高占用', '']];
|
||||
@@ -187,6 +186,31 @@ async function renderApps(silent) {
|
||||
</div>
|
||||
</div>`).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) => `
|
||||
<div class="top-row" data-top="${esc(a.key)}">
|
||||
<span class="rk">${i + 1}</span>
|
||||
<span class="nm" title="${esc(a.name)}">${esc(a.name)}</span>
|
||||
<span class="val">${val}</span>
|
||||
<span class="tbar ${kind}"><i style="width:${Math.max(2, Math.min(100, pct))}%"></i></span>
|
||||
</div>`;
|
||||
const maxCpu = Math.max(1, ...topCpu.map(a => a.cpuPctOfMachine || 0));
|
||||
const maxMem = Math.max(1, ...topMem.map(a => a.mem || 0));
|
||||
const topHtml = `
|
||||
<div class="top-grid">
|
||||
<div class="top-box">
|
||||
<div class="top-head"><b>CPU 占用 Top 5</b><span class="muted">占整机 · ${h.cpus} 核</span></div>
|
||||
${topCpu.map((a, i) => topRow(a, i, fmtPct(a.cpuPctOfMachine || 0), ((a.cpuPctOfMachine || 0) / maxCpu) * 100, 'cpu')).join('') || '<div class="empty sm">暂无数据</div>'}
|
||||
</div>
|
||||
<div class="top-box">
|
||||
<div class="top-head"><b>内存占用 Top 5</b><span class="muted">占整机 ${fmtBytes(memTotal)}</span></div>
|
||||
${topMem.map((a, i) => topRow(a, i, `${fmtBytes(a.mem || 0)} <small>${((a.mem || 0) / memTotal * 100).toFixed(1)}%</small>`, ((a.mem || 0) / maxMem) * 100, 'mem')).join('') || '<div class="empty sm">暂无数据</div>'}
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
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) {
|
||||
<div class="s-card"><div class="k">运行容器</div><div class="v">${h.running}<span class="muted" style="font-size:12px">/${h.containers}</span></div><div class="s">镜像 ${h.images} 个</div></div>
|
||||
</div>
|
||||
|
||||
${topHtml}
|
||||
${insHtml}
|
||||
|
||||
<div class="filters">
|
||||
@@ -244,6 +269,7 @@ async function renderApps(silent) {
|
||||
</div>`;
|
||||
|
||||
$$('#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) => {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
<span class="brand-text">飞牛docker容器管理增强版</span>
|
||||
</div>
|
||||
<nav id="nav">
|
||||
<a data-view="apps" class="active"><i data-ico="grid"></i>概览<span class="nav-badge alert" id="navIssues">-</span></a>
|
||||
<a data-view="apps" class="active"><i data-ico="grid"></i>概览</a>
|
||||
<a data-view="containers"><i data-ico="box"></i><span id="navContainersLabel">运行的容器</span><span class="nav-badge" id="navRunning">-</span></a>
|
||||
<a data-view="stopped"><i data-ico="pause"></i>停止的容器<span class="nav-badge" id="navStopped">-</span></a>
|
||||
<a data-view="images"><i data-ico="disc"></i>本地镜像</a>
|
||||
|
||||
@@ -269,3 +269,21 @@ table.tb th.num{text-align:right}
|
||||
.ok-txt{color:#12a15f}
|
||||
.pend-acts{display:flex;gap:6px;margin-top:2px}
|
||||
.build-stamp{font-size:10.5px;color:#9aa4b5;margin-top:6px;letter-spacing:.2px}
|
||||
|
||||
/* 概览 Top5 */
|
||||
.top-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:14px}
|
||||
@media(max-width:900px){.top-grid{grid-template-columns:1fr}}
|
||||
.top-box{background:var(--panel);border:1px solid var(--line);border-radius:12px;box-shadow:var(--shadow);overflow:hidden}
|
||||
.top-head{display:flex;align-items:baseline;justify-content:space-between;gap:8px;padding:10px 13px;border-bottom:1px solid var(--line);background:#fcfdff;font-size:13px}
|
||||
.top-head .muted{font-size:11.5px}
|
||||
.top-row{display:grid;grid-template-columns:16px minmax(78px,1fr) auto 72px;align-items:center;gap:8px;padding:7px 13px;border-top:1px solid #f2f5f9;cursor:pointer}
|
||||
.top-row:first-of-type{border-top:0}
|
||||
.top-row:hover{background:#f7fafd}
|
||||
.top-row .rk{font-size:11px;color:#9aa4b5;font-variant-numeric:tabular-nums}
|
||||
.top-row .nm{font-size:12.5px;color:#26303f;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.top-row .val{font-size:12px;font-weight:600;color:#3d4859;white-space:nowrap;font-variant-numeric:tabular-nums}
|
||||
.top-row .val small{font-weight:400;color:#8b95a5;margin-left:4px}
|
||||
.tbar{height:5px;border-radius:3px;background:#eef2f7;overflow:hidden;margin-right:2px}
|
||||
.tbar i{display:block;height:100%;border-radius:3px;background:#1a73e8}
|
||||
.tbar.mem i{background:#7a5af8}
|
||||
.empty.sm{padding:16px;font-size:12px;text-align:center;color:#8b95a5}
|
||||
Reference in new issue
Block a user