From a49078682746e15076538a99d24fd5a1ac48d5d5 Mon Sep 17 00:00:00 2001
From: Reditus <33814724+ReditusDraco@users.noreply.github.com>
Date: Fri, 4 Dec 2026 09:35:24 +0000
Subject: [PATCH] Sync local changes 2026-12-04
---
.gitignore | 9 +++
app/routes/api.py | 13 +++-
static/style.css | 71 ++++++++++++++++++++
templates/base.html | 151 +++++++++++++++++++++++++++++++++++++++++-
templates/server.html | 118 ++++++++++++++++++++++++++++-----
5 files changed, 342 insertions(+), 20 deletions(-)
diff --git a/.gitignore b/.gitignore
index c6d1e9b..18402e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,6 +83,9 @@ instance/
*.tmp
*.bak
+# Pre-change rollback backups (restorable copies of edited files)
+rollback/
+
# PowerShell profiles
Microsoft.PowerShell_profile.ps1
@@ -125,3 +128,9 @@ node_modules/
package-lock.json
yarn.lock
pnpm-lock.yaml
+
+# Local browser automation artifacts
+.playwright-mcp/
+
+# Shared AI docs copies (top-level AI_DOCS has its own repo)
+AI_DOCS/
diff --git a/app/routes/api.py b/app/routes/api.py
index 756df45..934daec 100644
--- a/app/routes/api.py
+++ b/app/routes/api.py
@@ -137,8 +137,17 @@ def register_api_routes(app, services, settings):
def server_metrics():
metrics = k8s.get_node_metrics()
if metrics:
- return jsonify(metrics)
- return jsonify({'cpu': 'N/A', 'memory': 'N/A'})
+ 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)
# Battlegroup
@app.route('/server/battlegroup/status')
diff --git a/static/style.css b/static/style.css
index 0ad4892..8c8a6be 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1490,3 +1490,74 @@ body[data-nav-layout="vertical"] .theme-dropdown::after {
top: auto;
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;
+}
diff --git a/templates/base.html b/templates/base.html
index 3ac0bdd..7a0f83b 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -47,6 +47,16 @@
{% endfor %}
+
+ – online
+ CPU –
+ RAM –
+
+
+
–players online
+
CPU–
+
RAM–
+
@@ -173,6 +183,7 @@
const next = current === 'horizontal' ? 'vertical' : 'horizontal';
body.setAttribute('data-nav-layout', next);
localStorage.setItem('dune-nav-layout', next);
+ if (typeof applyNavStatsLayout === 'function') applyNavStatsLayout();
}
function initNavLayout() {
@@ -190,8 +201,9 @@
const isMobile = window.innerWidth <= 768;
const current = document.body.getAttribute('data-nav-layout');
if (isMobile && current !== 'vertical') {
- document.body.setAttribute('data-nav-layout', 'vertical');
+ document.body.setAttribute('data-nav-layout', current);
}
+ if (typeof applyNavStatsLayout === 'function') applyNavStatsLayout();
});
initTheme();
@@ -489,6 +501,143 @@
refreshUpdateBanner();
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);
{% block scripts %}{% endblock %}