Compare commits
8
Commits
Experimental
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518dd45f6d | ||
|
|
cd00f984c5 | ||
|
|
aa0e5ec4e7 | ||
|
|
d7ce2a8caf | ||
|
|
bb5b17ef2a | ||
|
|
2c63aca276 | ||
|
|
3b0bffe464 | ||
|
|
901c485c65 |
No files matched your search
@@ -83,9 +83,6 @@ instance/
|
|||||||
*.tmp
|
*.tmp
|
||||||
*.bak
|
*.bak
|
||||||
|
|
||||||
# Pre-change rollback backups (restorable copies of edited files)
|
|
||||||
rollback/
|
|
||||||
|
|
||||||
# PowerShell profiles
|
# PowerShell profiles
|
||||||
Microsoft.PowerShell_profile.ps1
|
Microsoft.PowerShell_profile.ps1
|
||||||
|
|
||||||
@@ -128,9 +125,3 @@ node_modules/
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
|
||||||
# Local browser automation artifacts
|
|
||||||
.playwright-mcp/
|
|
||||||
|
|
||||||
# Shared AI docs copies (top-level AI_DOCS has its own repo)
|
|
||||||
AI_DOCS/
|
|
||||||
+1
-10
@@ -137,17 +137,8 @@ def register_api_routes(app, services, settings):
|
|||||||
def server_metrics():
|
def server_metrics():
|
||||||
metrics = k8s.get_node_metrics()
|
metrics = k8s.get_node_metrics()
|
||||||
if metrics:
|
if metrics:
|
||||||
pass
|
|
||||||
else:
|
|
||||||
metrics = {'cpu': 'N/A', 'memory': 'N/A'}
|
|
||||||
try:
|
|
||||||
row = db.query(
|
|
||||||
"SELECT COUNT(*) AS c FROM dune.player_state "
|
|
||||||
"WHERE online_status::text = 'Online'", one=True) or {}
|
|
||||||
metrics['online'] = int(row.get('c') or 0)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return jsonify(metrics)
|
return jsonify(metrics)
|
||||||
|
return jsonify({'cpu': 'N/A', 'memory': 'N/A'})
|
||||||
|
|
||||||
# Battlegroup
|
# Battlegroup
|
||||||
@app.route('/server/battlegroup/status')
|
@app.route('/server/battlegroup/status')
|
||||||
|
|||||||
@@ -1490,74 +1490,3 @@ body[data-nav-layout="vertical"] .theme-dropdown::after {
|
|||||||
top: auto;
|
top: auto;
|
||||||
bottom: 100%;
|
bottom: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nav live stats: CPU/RAM sparklines + online count. Compact strip in the
|
|
||||||
horizontal top bar, stacked block in the vertical sidebar. */
|
|
||||||
.nav-stats-h {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 12px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--nav-text);
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
.nav-stats-h .ns-item {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
}
|
|
||||||
.nav-stats-h canvas {
|
|
||||||
width: 64px;
|
|
||||||
height: 18px;
|
|
||||||
}
|
|
||||||
.nav-stats-h canvas,
|
|
||||||
.nav-stats-v canvas {
|
|
||||||
border: 1px solid rgba(128,128,128,0.35);
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
.nav-stats-v {
|
|
||||||
padding: 10px 8px;
|
|
||||||
border-top: 1px solid rgba(255,255,255,0.08);
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--nav-text);
|
|
||||||
}
|
|
||||||
.nav-stats-v .ns-vrow {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 6px;
|
|
||||||
margin-bottom: 6px;
|
|
||||||
}
|
|
||||||
.nav-stats-v .ns-vrow:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
.nav-stats-v .ns-vlabel {
|
|
||||||
opacity: 0.7;
|
|
||||||
font-size: 11px;
|
|
||||||
}
|
|
||||||
.nav-stats-v canvas {
|
|
||||||
flex: 1;
|
|
||||||
height: 28px;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
/* Graph rows share one grid template so both canvases are pixel-identical
|
|
||||||
regardless of label/value text widths. */
|
|
||||||
.nav-stats-v .ns-vgraph {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 34px 1fr 64px;
|
|
||||||
align-items: center;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
.nav-stats-v .ns-vgraph canvas {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
/* Fixed-width value column so CPU and RAM graphs align regardless of
|
|
||||||
label length ("10%" vs "17947Mi"); values sit left, against the graphs. */
|
|
||||||
.nav-stats-v .ns-vrow > span:last-child {
|
|
||||||
min-width: 64px;
|
|
||||||
text-align: left;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
.nav-stats-v strong {
|
|
||||||
font-size: 15px;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
+1
-150
@@ -47,16 +47,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<div class="nav-stats-h" id="nav-stats-h" style="display:none;">
|
|
||||||
<span class="ns-item"><span class="conn-dot" id="ns-dot-h"></span><strong id="ns-online-h">–</strong> online</span>
|
|
||||||
<span class="ns-item">CPU <canvas id="ns-cpu-h" width="64" height="18"></canvas> <span id="ns-cpuv-h">–</span></span>
|
|
||||||
<span class="ns-item">RAM <canvas id="ns-mem-h" width="64" height="18"></canvas> <span id="ns-memv-h">–</span></span>
|
|
||||||
</div>
|
|
||||||
<div class="nav-stats-v" id="nav-stats-v" style="display:none;">
|
|
||||||
<div class="ns-vrow"><span class="conn-dot" id="ns-dot-v"></span><strong id="ns-online-v">–</strong><span class="ns-vlabel">players online</span></div>
|
|
||||||
<div class="ns-vrow ns-vgraph"><span class="ns-vlabel">CPU</span><canvas id="ns-cpu-v" width="168" height="28"></canvas><span id="ns-cpuv-v">–</span></div>
|
|
||||||
<div class="ns-vrow ns-vgraph"><span class="ns-vlabel">RAM</span><canvas id="ns-mem-v" width="168" height="28"></canvas><span id="ns-memv-v">–</span></div>
|
|
||||||
</div>
|
|
||||||
<div class="nav-tools">
|
<div class="nav-tools">
|
||||||
<div class="theme-dropdown">
|
<div class="theme-dropdown">
|
||||||
<button class="theme-btn" title="Theme">🎨</button>
|
<button class="theme-btn" title="Theme">🎨</button>
|
||||||
@@ -183,7 +173,6 @@
|
|||||||
const next = current === 'horizontal' ? 'vertical' : 'horizontal';
|
const next = current === 'horizontal' ? 'vertical' : 'horizontal';
|
||||||
body.setAttribute('data-nav-layout', next);
|
body.setAttribute('data-nav-layout', next);
|
||||||
localStorage.setItem('dune-nav-layout', next);
|
localStorage.setItem('dune-nav-layout', next);
|
||||||
if (typeof applyNavStatsLayout === 'function') applyNavStatsLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initNavLayout() {
|
function initNavLayout() {
|
||||||
@@ -201,9 +190,8 @@
|
|||||||
const isMobile = window.innerWidth <= 768;
|
const isMobile = window.innerWidth <= 768;
|
||||||
const current = document.body.getAttribute('data-nav-layout');
|
const current = document.body.getAttribute('data-nav-layout');
|
||||||
if (isMobile && current !== 'vertical') {
|
if (isMobile && current !== 'vertical') {
|
||||||
document.body.setAttribute('data-nav-layout', current);
|
document.body.setAttribute('data-nav-layout', 'vertical');
|
||||||
}
|
}
|
||||||
if (typeof applyNavStatsLayout === 'function') applyNavStatsLayout();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
initTheme();
|
initTheme();
|
||||||
@@ -501,143 +489,6 @@
|
|||||||
|
|
||||||
refreshUpdateBanner();
|
refreshUpdateBanner();
|
||||||
setInterval(refreshUpdateBanner, 10 * 60 * 1000);
|
setInterval(refreshUpdateBanner, 10 * 60 * 1000);
|
||||||
|
|
||||||
// Sidebar/topbar live stats: CPU + RAM sparklines and online count.
|
|
||||||
// History persists across page changes in localStorage (30 points,
|
|
||||||
// roughly 5 minutes at the 10s poll rate) and doubles as seed data
|
|
||||||
// for the big Server charts.
|
|
||||||
const NS_MAX = 30;
|
|
||||||
const NS_INTERVAL = 10000;
|
|
||||||
function nsLoad(key) {
|
|
||||||
try {
|
|
||||||
const arr = JSON.parse(localStorage.getItem(key) || '[]');
|
|
||||||
if (!Array.isArray(arr)) return [];
|
|
||||||
// Same freshness rule as the big charts: drop anything older
|
|
||||||
// than 6 minutes so a restart/refresh starts clean instead of
|
|
||||||
// replaying stale history the big graphs have discarded.
|
|
||||||
const cutoff = Date.now() - 6 * 60 * 1000;
|
|
||||||
return arr.filter(p => p && typeof p.v === 'number'
|
|
||||||
&& typeof p.t === 'number' && p.t >= cutoff).slice(-NS_MAX);
|
|
||||||
} catch (e) { return []; }
|
|
||||||
}
|
|
||||||
let nsCpu = nsLoad('dune-metrics-cpu');
|
|
||||||
let nsMem = nsLoad('dune-metrics-mem');
|
|
||||||
function nsSave() {
|
|
||||||
try {
|
|
||||||
localStorage.setItem('dune-metrics-cpu', JSON.stringify(nsCpu.slice(-NS_MAX)));
|
|
||||||
localStorage.setItem('dune-metrics-mem', JSON.stringify(nsMem.slice(-NS_MAX)));
|
|
||||||
} catch (e) { /* storage full or unavailable - keep memory-only */ }
|
|
||||||
}
|
|
||||||
function nsCssVar(name, fallback) {
|
|
||||||
const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
||||||
return v || fallback;
|
|
||||||
}
|
|
||||||
// Memory total (GiB), latched once like the big charts so the scale
|
|
||||||
// never moves. Persisted so minis open correctly scaled on load.
|
|
||||||
let nsMemTotal = parseFloat(localStorage.getItem('dune-mem-total') || '0') || 0;
|
|
||||||
function drawSpark(canvas, values, color, ymax) {
|
|
||||||
if (!canvas) return;
|
|
||||||
const dpr = window.devicePixelRatio || 1;
|
|
||||||
const w = canvas.clientWidth || canvas.width, h = canvas.clientHeight || canvas.height;
|
|
||||||
if (!w || !h) return;
|
|
||||||
canvas.width = w * dpr;
|
|
||||||
canvas.height = h * dpr;
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
ctx.scale(dpr, dpr);
|
|
||||||
ctx.clearRect(0, 0, w, h);
|
|
||||||
if (!values.length) return;
|
|
||||||
const min = 0, max = (ymax > 0) ? ymax : 100;
|
|
||||||
const step = values.length > 1 ? w / (NS_MAX - 1) : 0;
|
|
||||||
const x0 = w - step * (values.length - 1);
|
|
||||||
ctx.beginPath();
|
|
||||||
values.forEach((p, i) => {
|
|
||||||
const v = (typeof p === 'number') ? p : p.v;
|
|
||||||
const x = x0 + step * i;
|
|
||||||
const y = h - 2 - ((Math.min(Math.max(v, min), max) - min) / (max - min)) * (h - 4);
|
|
||||||
if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y);
|
|
||||||
});
|
|
||||||
ctx.strokeStyle = color;
|
|
||||||
ctx.lineWidth = 1.5;
|
|
||||||
ctx.stroke();
|
|
||||||
ctx.lineTo(x0 + step * (values.length - 1), h);
|
|
||||||
ctx.lineTo(x0, h);
|
|
||||||
ctx.closePath();
|
|
||||||
ctx.fillStyle = color + '33';
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
// Last known values so layout switches re-render instantly
|
|
||||||
// instead of waiting for the next poll.
|
|
||||||
let nsLast = { cpu: '–', mem: '–', online: null };
|
|
||||||
function applyNavStatsLayout() {
|
|
||||||
const h = document.getElementById('nav-stats-h');
|
|
||||||
const v = document.getElementById('nav-stats-v');
|
|
||||||
const layout = document.body.getAttribute('data-nav-layout') || 'horizontal';
|
|
||||||
if (h) h.style.display = (layout === 'horizontal') ? '' : 'none';
|
|
||||||
if (v) v.style.display = (layout === 'vertical') ? '' : 'none';
|
|
||||||
}
|
|
||||||
function renderNavStats(cpuStr, memStr, online) {
|
|
||||||
nsLast = { cpu: cpuStr, mem: memStr, online: online };
|
|
||||||
const onlineTxt = (online === null || online === undefined) ? '–' : String(online);
|
|
||||||
const cpuColor = nsCssVar('--primary', '#c9a24e');
|
|
||||||
const memColor = nsCssVar('--success', '#27ae60');
|
|
||||||
[['h'], ['v']].forEach(([sfx]) => {
|
|
||||||
const on = document.getElementById('ns-online-' + sfx);
|
|
||||||
const cv = document.getElementById('ns-cpuv-' + sfx);
|
|
||||||
const mv = document.getElementById('ns-memv-' + sfx);
|
|
||||||
if (on) on.textContent = onlineTxt;
|
|
||||||
if (cv) cv.textContent = cpuStr;
|
|
||||||
if (mv) mv.textContent = memStr;
|
|
||||||
const dot = document.getElementById('ns-dot-' + sfx);
|
|
||||||
if (dot) dot.className = 'conn-dot ' + ((online > 0) ? 'online' : 'offline');
|
|
||||||
drawSpark(document.getElementById('ns-cpu-' + sfx), nsCpu.map(p => p.v), cpuColor, 100);
|
|
||||||
// Pre-GiB entries have no g: skip them rather than plotting
|
|
||||||
// percent values on a GiB scale.
|
|
||||||
drawSpark(document.getElementById('ns-mem-' + sfx),
|
|
||||||
nsMem.filter(p => typeof p.g === 'number').map(p => p.g), memColor,
|
|
||||||
nsMemTotal > 0 ? Math.ceil(nsMemTotal) : 100);
|
|
||||||
});
|
|
||||||
applyNavStatsLayout();
|
|
||||||
}
|
|
||||||
async function pollNavStats() {
|
|
||||||
if (document.hidden) return; // save the server while tab is backgrounded
|
|
||||||
try {
|
|
||||||
const resp = await fetch('/server/metrics');
|
|
||||||
const data = await resp.json();
|
|
||||||
const now = Date.now();
|
|
||||||
if (typeof data.cpu_num === 'number') {
|
|
||||||
nsCpu.push({ t: now, v: data.cpu_num });
|
|
||||||
nsCpu = nsCpu.slice(-NS_MAX);
|
|
||||||
}
|
|
||||||
// Percent only for the graph scale; GiB rides along so the big
|
|
||||||
// Server charts can seed from this same history.
|
|
||||||
if (typeof data.memory_pct_num === 'number') {
|
|
||||||
const gib = (typeof data.memory_gib === 'number') ? data.memory_gib : null;
|
|
||||||
nsMem.push({ t: now, v: data.memory_pct_num, g: gib });
|
|
||||||
nsMem = nsMem.slice(-NS_MAX);
|
|
||||||
// Latch the RAM total once, then only re-latch when the
|
|
||||||
// machine itself actually changed (implied total moved
|
|
||||||
// >5%): per-sample rounding wobble never moves the ruler.
|
|
||||||
if (data.memory_pct_num > 0 && gib > 0) {
|
|
||||||
const implied = gib / (data.memory_pct_num / 100);
|
|
||||||
if (!nsMemTotal || Math.abs(implied - nsMemTotal) / nsMemTotal > 0.05) {
|
|
||||||
nsMemTotal = implied;
|
|
||||||
try { localStorage.setItem('dune-mem-total', String(nsMemTotal)); } catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Drop stale points on every poll (not just at load) so a
|
|
||||||
// wake-from-sleep recovers on the next poll instead of
|
|
||||||
// replaying old history for minutes.
|
|
||||||
const freshCutoff = Date.now() - 6 * 60 * 1000;
|
|
||||||
nsCpu = nsCpu.filter(p => p && p.t >= freshCutoff);
|
|
||||||
nsMem = nsMem.filter(p => p && p.t >= freshCutoff);
|
|
||||||
nsSave();
|
|
||||||
renderNavStats(data.cpu || '–', data.memory || '–',
|
|
||||||
(data.online === null || data.online === undefined) ? null : data.online);
|
|
||||||
} catch (e) { /* keep last values on failure */ }
|
|
||||||
}
|
|
||||||
pollNavStats();
|
|
||||||
setInterval(pollNavStats, NS_INTERVAL);
|
|
||||||
</script>
|
</script>
|
||||||
{% block scripts %}{% endblock %}
|
{% block scripts %}{% endblock %}
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
+9
-93
@@ -576,7 +576,7 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
// ── Node resource charts ──────────────────────────────────────────────
|
// ── Node resource charts ──────────────────────────────────────────────
|
||||||
const MAX_POINTS = 60; // 5 minutes at 5s intervals
|
const MAX_POINTS = 720; // 1 hour at 5s intervals
|
||||||
const SPARKLINE_POINTS = 60; // 5 min for sparkline
|
const SPARKLINE_POINTS = 60; // 5 min for sparkline
|
||||||
let metricsHistory = []; // [{cpu_num, memory_gib, memory_pct_num, memory, cpu, ts}]
|
let metricsHistory = []; // [{cpu_num, memory_gib, memory_pct_num, memory, cpu, ts}]
|
||||||
|
|
||||||
@@ -585,10 +585,6 @@ function parseCSSVar(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function drawCharts(history) {
|
function drawCharts(history) {
|
||||||
// Memory plots GiB on a fixed 0-to-total scale set once from the first
|
|
||||||
// good sample - never rescaled after, exactly like CPU's fixed 0-100.
|
|
||||||
// The total is latched in fetchMetrics/seedMetricsHistory, so the mem
|
|
||||||
// chart is only created once it is known (no autoscale window ever).
|
|
||||||
const cpuVals = history.map(p => p.cpu_num);
|
const cpuVals = history.map(p => p.cpu_num);
|
||||||
const memVals = history.map(p => p.memory_gib);
|
const memVals = history.map(p => p.memory_gib);
|
||||||
const primaryColor = parseCSSVar('--primary') || '#c9a24e';
|
const primaryColor = parseCSSVar('--primary') || '#c9a24e';
|
||||||
@@ -615,42 +611,29 @@ function drawCharts(history) {
|
|||||||
data: { labels: [], datasets: [{ label: 'CPU %', data: [], borderColor: primaryColor, backgroundColor: primaryColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
data: { labels: [], datasets: [{ label: 'CPU %', data: [], borderColor: primaryColor, backgroundColor: primaryColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
||||||
options: { ...commonOpts, scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, min: 0, max: 100, title: { display: true, text: 'CPU %', color: textColor, font: { size: 11 } } } } }
|
options: { ...commonOpts, scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, min: 0, max: 100, title: { display: true, text: 'CPU %', color: textColor, font: { size: 11 } } } } }
|
||||||
});
|
});
|
||||||
if (window._totalMemGib > 0 && !window._memChart) {
|
const memMax = window._totalMemGib ? Math.ceil(window._totalMemGib) : undefined;
|
||||||
const memMax = Math.ceil(window._totalMemGib);
|
|
||||||
window._memChart = new Chart(chartMem, {
|
window._memChart = new Chart(chartMem, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: { labels: [], datasets: [{ label: 'Memory GiB', data: [], borderColor: successColor, backgroundColor: successColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
data: { labels: [], datasets: [{ label: 'Memory GiB', data: [], borderColor: successColor, backgroundColor: successColor + '20', fill: true, pointRadius: 0, borderWidth: 2, tension: 0.3 }] },
|
||||||
options: { ...commonOpts,
|
options: { ...commonOpts, scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, beginAtZero: true, max: memMax, title: { display: true, text: 'GiB', color: textColor, font: { size: 11 } } } } }
|
||||||
plugins: { legend: { display: false },
|
|
||||||
tooltip: { callbacks: { label: (c) => {
|
|
||||||
const p = history[c.dataIndex] || {};
|
|
||||||
const pct = (typeof p.memory_pct_num === 'number') ? ` (${p.memory_pct_num.toFixed(0)}%)` : '';
|
|
||||||
return ` ${c.parsed.y.toFixed(1)} GiB${pct}`;
|
|
||||||
} } } },
|
|
||||||
scales: { ...commonOpts.scales, y: { ...commonOpts.scales.y, min: 0, max: memMax, title: { display: true, text: 'GiB', color: textColor, font: { size: 11 } } } } }
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Full-window labels (60 slots = 5 min at 5s each), filled from the
|
|
||||||
// left: the trace starts at the left edge on first sample and grows
|
|
||||||
// right as history accumulates. A category axis clamps min/max to the
|
|
||||||
// data, so padding (not min/max) is what holds the window open.
|
|
||||||
const labels = history.map(p => p.ts);
|
const labels = history.map(p => p.ts);
|
||||||
while (labels.length < MAX_POINTS) labels.push('');
|
|
||||||
window._cpuChart.data.labels = labels;
|
window._cpuChart.data.labels = labels;
|
||||||
window._cpuChart.data.datasets[0].data = cpuVals;
|
window._cpuChart.data.datasets[0].data = cpuVals;
|
||||||
window._cpuChart.data.datasets[0].borderColor = primaryColor;
|
window._cpuChart.data.datasets[0].borderColor = primaryColor;
|
||||||
window._cpuChart.data.datasets[0].backgroundColor = primaryColor + '20';
|
window._cpuChart.data.datasets[0].backgroundColor = primaryColor + '20';
|
||||||
window._cpuChart.update('none');
|
window._cpuChart.update('none');
|
||||||
|
|
||||||
if (window._memChart) {
|
|
||||||
window._memChart.data.labels = labels;
|
window._memChart.data.labels = labels;
|
||||||
window._memChart.data.datasets[0].data = memVals;
|
window._memChart.data.datasets[0].data = memVals;
|
||||||
window._memChart.data.datasets[0].borderColor = successColor;
|
window._memChart.data.datasets[0].borderColor = successColor;
|
||||||
window._memChart.data.datasets[0].backgroundColor = successColor + '20';
|
window._memChart.data.datasets[0].backgroundColor = successColor + '20';
|
||||||
window._memChart.update('none');
|
if (window._totalMemGib) {
|
||||||
|
window._memChart.options.scales.y.max = Math.ceil(window._totalMemGib);
|
||||||
}
|
}
|
||||||
|
window._memChart.update('none');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchMetrics() {
|
async function fetchMetrics() {
|
||||||
@@ -662,30 +645,16 @@ async function fetchMetrics() {
|
|||||||
|
|
||||||
const memPctNum = data.memory_pct_num || 0;
|
const memPctNum = data.memory_pct_num || 0;
|
||||||
const memGib = data.memory_gib || 0;
|
const memGib = data.memory_gib || 0;
|
||||||
// Latch once; re-latch only on a real machine change (>5%),
|
if (!window._totalMemGib && memPctNum > 0) {
|
||||||
// so rounding wobble never moves the ruler but a RAM
|
window._totalMemGib = memGib / (memPctNum / 100);
|
||||||
// upgrade/replacement is picked up within one poll.
|
|
||||||
if (memPctNum > 0 && memGib > 0) {
|
|
||||||
const implied = memGib / (memPctNum / 100);
|
|
||||||
if (!window._totalMemGib ||
|
|
||||||
Math.abs(implied - window._totalMemGib) / window._totalMemGib > 0.05) {
|
|
||||||
window._totalMemGib = implied;
|
|
||||||
if (window._memChart) {
|
|
||||||
window._memChart.options.scales.y.max = Math.ceil(implied);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
document.getElementById('node-mem').textContent = data.memory;
|
document.getElementById('node-mem').textContent = data.memory;
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const ts = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') + ':' + now.getSeconds().toString().padStart(2, '0');
|
const ts = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') + ':' + now.getSeconds().toString().padStart(2, '0');
|
||||||
const point = { t: now.getTime(), cpu_num: data.cpu_num || 0, memory_gib: memGib, memory_pct_num: memPctNum, memory: data.memory, cpu: data.cpu, ts: ts };
|
const point = { cpu_num: data.cpu_num || 0, memory_gib: memGib, memory_pct_num: memPctNum, memory: data.memory, cpu: data.cpu, ts: ts };
|
||||||
metricsHistory.push(point);
|
metricsHistory.push(point);
|
||||||
if (metricsHistory.length > MAX_POINTS) metricsHistory.shift();
|
if (metricsHistory.length > MAX_POINTS) metricsHistory.shift();
|
||||||
// Same freshness rule as the sidebar: drop stale points on every
|
|
||||||
// poll so a wake-from-sleep recovers immediately.
|
|
||||||
const freshCutoff = Date.now() - 6 * 60 * 1000;
|
|
||||||
metricsHistory = metricsHistory.filter(p => p && typeof p.t === 'number' && p.t >= freshCutoff);
|
|
||||||
|
|
||||||
drawCharts(metricsHistory);
|
drawCharts(metricsHistory);
|
||||||
}
|
}
|
||||||
@@ -701,59 +670,6 @@ function loadChartJS(src) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmtClock(ms) {
|
|
||||||
const d = new Date(ms);
|
|
||||||
return d.getHours().toString().padStart(2, '0') + ':' + d.getMinutes().toString().padStart(2, '0') + ':' + d.getSeconds().toString().padStart(2, '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seed the big charts from the sidebar's stored history (same 10s samples
|
|
||||||
// the nav widget collects on every page). Skipped when stale so yesterday
|
|
||||||
// is never plotted as now; live polling takes over seamlessly after.
|
|
||||||
function seedMetricsHistory() {
|
|
||||||
try {
|
|
||||||
const cpu = JSON.parse(localStorage.getItem('dune-metrics-cpu') || '[]');
|
|
||||||
const mem = JSON.parse(localStorage.getItem('dune-metrics-mem') || '[]');
|
|
||||||
if (!Array.isArray(cpu) || !cpu.length) return;
|
|
||||||
// Drop every stale point, not just check the newest: a buffer mixing
|
|
||||||
// an old cluster with fresh points would otherwise plot a span far
|
|
||||||
// wider than the 5-minute window. 6 minutes keeps a full window plus
|
|
||||||
// margin for slow polls.
|
|
||||||
const cutoff = Date.now() - 6 * 60 * 1000;
|
|
||||||
const fresh = cpu.filter(p => p && typeof p.t === 'number'
|
|
||||||
&& typeof p.v === 'number' && p.t >= cutoff);
|
|
||||||
if (!fresh.length) return;
|
|
||||||
const memByT = {};
|
|
||||||
mem.forEach(p => { if (p && typeof p.t === 'number') memByT[p.t] = p; });
|
|
||||||
// Derive total RAM once so GiB-less points can be backfilled.
|
|
||||||
let total = window._totalMemGib || 0;
|
|
||||||
if (!total) {
|
|
||||||
for (let i = fresh.length - 1; i >= 0; i--) {
|
|
||||||
const m = memByT[fresh[i].t];
|
|
||||||
if (m && typeof m.g === 'number' && m.g > 0 && m.v > 0) {
|
|
||||||
total = m.g / (m.v / 100);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (total > 0) window._totalMemGib = total;
|
|
||||||
}
|
|
||||||
const pts = [];
|
|
||||||
fresh.slice(-MAX_POINTS).forEach(p => {
|
|
||||||
const m = memByT[p.t] || {};
|
|
||||||
let gib = (typeof m.g === 'number') ? m.g : 0;
|
|
||||||
const pct = (typeof m.v === 'number') ? m.v : 0;
|
|
||||||
if (!gib && pct > 0 && total > 0) gib = pct / 100 * total;
|
|
||||||
if (!gib && !pct) return;
|
|
||||||
pts.push({
|
|
||||||
t: p.t, cpu_num: p.v, memory_gib: gib, memory_pct_num: pct,
|
|
||||||
memory: '', cpu: '', ts: fmtClock(p.t)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (pts.length) metricsHistory = pts;
|
|
||||||
} catch (e) { /* start empty on any problem */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
seedMetricsHistory();
|
|
||||||
|
|
||||||
loadChartJS('https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js').then(() => {
|
loadChartJS('https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js').then(() => {
|
||||||
fetchMetrics();
|
fetchMetrics();
|
||||||
setInterval(fetchMetrics, 5000);
|
setInterval(fetchMetrics, 5000);
|
||||||
|
|||||||
Reference in new issue
Block a user