feat: 运行时长 Top5,四个榜单并列一行
This commit is contained in:
1 parent
8f248f17d8
commit
743a41c0e7
3 files changed
+33
-7
No files matched your search
@@ -1,5 +1,11 @@
|
||||
# 更新日志
|
||||
|
||||
## 2026-10-26 → ✨ 新增「运行时长 Top 5」,四个榜单并列一行
|
||||
|
||||
- ✨ Top 5 变四列:CPU / 内存 / 网络 / **运行时长**(按连续运行时长降序,显示 `1天5小时` 与 `1/1` 运行容器数,青色进度条)
|
||||
- 🔧 四列后名称被挤压 → 榜单行改为两行结构(名称+数值一行、进度条一行),名称拿到整行宽度,实测 0 处溢出
|
||||
- 🔧 网络榜数值改用紧凑格式(`↓304K/s ↑16.1K/s`),窄列也能完整显示
|
||||
|
||||
## 2026-10-26 → ✨ 新增「网络占用 Top 5」,三个榜单并列一行
|
||||
|
||||
- ✨ Top 5 由两列改三列:CPU / 内存 / **网络**(上下行合计排序,显示 ↓下行 ↑上行)
|
||||
|
||||
+19
-3
@@ -35,6 +35,14 @@ const fmtBytes = (b) => {
|
||||
while (n >= 1024 && i < u.length - 1) { n /= 1024; i++; }
|
||||
return `${n < 10 && i > 0 ? n.toFixed(2) : Math.round(n * 10) / 10} ${u[i]}`;
|
||||
};
|
||||
const fmtRateShort = (b) => {
|
||||
if (!b) return '0';
|
||||
const u = ['B/s', 'K/s', 'M/s', 'G/s'];
|
||||
let i = 0, v = b;
|
||||
while (v >= 1024 && i < u.length - 1) { v /= 1024; i++; }
|
||||
const s = v >= 100 ? String(Math.round(v)) : (Math.round(v * 10) / 10).toString();
|
||||
return s.replace(/\.0$/, '') + u[i];
|
||||
};
|
||||
const fmtRate = (b) => (b > 0 ? fmtBytes(b) + '/s' : '0 B/s');
|
||||
const fmtPct = (n) => (n >= 10 ? n.toFixed(1) : (n || 0).toFixed(2)) + '%';
|
||||
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||||
@@ -237,17 +245,21 @@ async function renderApps(silent) {
|
||||
const topMem = [...allApps].sort((x, y) => (y.mem || 0) - (x.mem || 0)).slice(0, 5);
|
||||
const netOf = (a) => (a.rxBps || 0) + (a.txBps || 0);
|
||||
const topNet = [...allApps].sort((x, y) => netOf(y) - netOf(x)).slice(0, 5);
|
||||
const topRun = [...allApps].filter(a => a.runMs !== null && a.runMs !== undefined).sort((x, y) => y.runMs - x.runMs).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>
|
||||
<div class="tr-line">
|
||||
<span class="nm" title="${esc(a.name)}">${esc(a.name)}</span>
|
||||
<span class="val">${val}</span>
|
||||
</div>
|
||||
<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 maxNet = Math.max(1, ...topNet.map(netOf));
|
||||
const maxRun = Math.max(1, ...topRun.map(a => a.runMs));
|
||||
const topHtml = `
|
||||
<div class="top-grid">
|
||||
<div class="top-box">
|
||||
@@ -260,7 +272,11 @@ async function renderApps(silent) {
|
||||
</div>
|
||||
<div class="top-box">
|
||||
<div class="top-head"><b>网络占用 Top 5</b><span class="muted">上下行合计</span></div>
|
||||
${topNet.map((a, i) => topRow(a, i, `↓${fmtRate(a.rxBps || 0)} <small>↑${fmtRate(a.txBps || 0)}</small>`, (netOf(a) / maxNet) * 100, 'net')).join('') || '<div class="empty sm">暂无数据</div>'}
|
||||
${topNet.map((a, i) => topRow(a, i, `↓${fmtRateShort(a.rxBps || 0)} <small>↑${fmtRateShort(a.txBps || 0)}</small>`, (netOf(a) / maxNet) * 100, 'net')).join('') || '<div class="empty sm">暂无数据</div>'}
|
||||
</div>
|
||||
<div class="top-box">
|
||||
<div class="top-head"><b>运行时长 Top 5</b><span class="muted">连续运行</span></div>
|
||||
${topRun.map((a, i) => topRow(a, i, `${fmtDurCompact(a.runMs)} <small>${a.running}/${a.total}</small>`, (a.runMs / maxRun) * 100, 'run')).join('') || '<div class="empty sm">暂无数据</div>'}
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
|
||||
+8
-4
@@ -271,22 +271,26 @@ table.tb th.num{text-align:right}
|
||||
.build-stamp{font-size:10.5px;color:#9aa4b5;margin-top:6px;letter-spacing:.2px}
|
||||
|
||||
/* 概览 Top5 */
|
||||
.top-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;margin-bottom:14px}
|
||||
.top-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-bottom:14px}
|
||||
@media(max-width:1180px){.top-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
@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{display:grid;grid-template-columns:14px minmax(0,1fr);align-items:center;gap:4px 8px;padding:7px 12px;border-top:1px solid #f2f5f9;cursor:pointer}
|
||||
.tr-line{display:flex;align-items:baseline;gap:8px;min-width:0}
|
||||
.tbar{grid-column:1 / -1}
|
||||
.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 .nm{font-size:12.5px;color:#26303f;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}
|
||||
.top-row .val{font-size:11.5px;font-weight:600;color:#3d4859;white-space:nowrap;font-variant-numeric:tabular-nums;flex-shrink:0}
|
||||
.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}
|
||||
.tbar.net i{background:#f79009}
|
||||
.tbar.run i{background:#0ba5ec}
|
||||
.empty.sm{padding:16px;font-size:12px;text-align:center;color:#8b95a5}
|
||||
.empty.ok-empty{padding:22px;text-align:center;color:#12a15f;background:#f3fbf6;border:1px dashed #cdebd9;border-radius:12px;font-size:13px}
|
||||
|
||||
|
||||
Reference in new issue
Block a user