Show the server's public IP with click to copy, and VPS network graphs
Cards show the VPS's public IP (PUBLIC_IP, else the default route's source address) instead of the page's hostname; clicking the address copies it. VPS resources gets stacked download/upload graphs of the last 5 minutes, kept server side. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cb9a6d1970
commit
3ae03160e8
4 changed files with 93 additions and 5 deletions
|
|
@ -89,7 +89,28 @@ function renderHost() {
|
|||
setBar('#b-swap', h.swap_total ? (100 * h.swap_used) / h.swap_total : 0);
|
||||
$('#m-disk').textContent = `${fmtBytes(h.disk_used)} / ${fmtBytes(h.disk_total)}`;
|
||||
setBar('#b-disk', (100 * h.disk_used) / h.disk_total);
|
||||
$('#m-net').textContent = `Network: ↓ ${fmtRate(h.net_rx_rate)} ↑ ${fmtRate(h.net_tx_rate)}`;
|
||||
$('#m-rx').textContent = fmtRate(h.net_rx_rate);
|
||||
$('#m-tx').textContent = fmtRate(h.net_tx_rate);
|
||||
const hist = h.net_history || [];
|
||||
drawGraph('#g-rx', hist.map((x) => x[0]));
|
||||
drawGraph('#g-tx', hist.map((x) => x[1]));
|
||||
}
|
||||
|
||||
// Area graph of the last NET_HISTORY samples (app.py), right-aligned so it fills in from the right after a
|
||||
// restart. Each graph scales to its own peak, shown in the tooltip.
|
||||
const GRAPH_POINTS = 100;
|
||||
function drawGraph(id, vals) {
|
||||
const svg = $(id);
|
||||
const peak = Math.max(1, ...vals);
|
||||
const step = 100 / (GRAPH_POINTS - 1);
|
||||
const x0 = 100 - (vals.length - 1) * step;
|
||||
const pts = vals.map((v, i) => `${(x0 + i * step).toFixed(2)},${(24 - (22 * v) / peak).toFixed(2)}`);
|
||||
const line = pts.length > 1 ? `M${pts.join('L')}` : '';
|
||||
svg.querySelector('.line').setAttribute('d', line);
|
||||
svg.querySelector('.area').setAttribute('d', line && `${line}L100,24L${x0.toFixed(2)},24Z`);
|
||||
let title = svg.querySelector('title');
|
||||
if (!title) title = svg.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'title'));
|
||||
title.textContent = `Peak ${fmtRate(peak)} in the last ${(GRAPH_POINTS * 3) / 60} minutes`;
|
||||
}
|
||||
|
||||
function fmtDuration(sec) {
|
||||
|
|
@ -149,11 +170,27 @@ function timeAgo(iso) {
|
|||
return `on ${t.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })}`;
|
||||
}
|
||||
|
||||
// The server address on each card copies itself when clicked. Cards re-render every poll, so the
|
||||
// "Copied!" state is kept here rather than on the element.
|
||||
let copied = { addr: null, text: '' };
|
||||
let copiedTimer = null;
|
||||
const copyAddr = (addr) => `<button type="button" class="copy-addr" data-addr="${esc(addr)}" data-tip="${
|
||||
copied.addr === addr ? esc(copied.text) : 'Click to copy'}">${esc(addr)}</button>`;
|
||||
|
||||
async function copyToClipboard(addr) {
|
||||
let text = 'Copied!';
|
||||
try { await navigator.clipboard.writeText(addr); } catch { text = 'Copy failed'; }
|
||||
copied = { addr, text };
|
||||
renderServers();
|
||||
clearTimeout(copiedTimer);
|
||||
copiedTimer = setTimeout(() => { copied = { addr: null, text: '' }; renderServers(); }, 1500);
|
||||
}
|
||||
|
||||
const STATE_LABEL = { online: 'Online', starting: 'Starting…', exited: 'Stopped', created: 'Stopped', restarting: 'Restarting…' };
|
||||
|
||||
function renderServers() {
|
||||
$('#empty-msg').classList.toggle('hidden', servers.length > 0);
|
||||
const host = location.hostname;
|
||||
const host = stats.host.public_ip || location.hostname;
|
||||
$('#server-list').innerHTML = servers.map((s) => {
|
||||
const st = stats.servers[s.id];
|
||||
const running = s.state === 'online' || s.state === 'starting';
|
||||
|
|
@ -167,7 +204,7 @@ function renderServers() {
|
|||
<div class="server-top">
|
||||
<div>
|
||||
<div class="server-name">${esc(s.server_name)}<span class="badge ${badgeCls}">${isBusy ? 'Working…' : s.busy ? esc(s.busy) : STATE_LABEL[s.state] || esc(s.state)}</span></div>
|
||||
<div class="server-meta">${esc(s.game_name)} · ${s.summary ? esc(s.summary) : `world <b>${esc(s.world)}</b>`} · connect to <b>${esc(host)}:${s.port}</b></div>
|
||||
<div class="server-meta">${esc(s.game_name)} · ${s.summary ? esc(s.summary) : `world <b>${esc(s.world)}</b>`} · connect to ${copyAddr(`${host}:${s.port}`)}</div>
|
||||
${running ? playersLine(st) : s.last_online ? `<div class="server-last-online" title="${esc(new Date(s.last_online).toLocaleString())}">Last online ${esc(timeAgo(s.last_online))}</div>` : ''}
|
||||
</div>
|
||||
<div class="server-actions">
|
||||
|
|
@ -190,6 +227,8 @@ function renderServers() {
|
|||
}
|
||||
|
||||
$('#server-list').addEventListener('click', async (e) => {
|
||||
const addr = e.target.closest('.copy-addr');
|
||||
if (addr) return copyToClipboard(addr.dataset.addr);
|
||||
const btn = e.target.closest('button[data-act]');
|
||||
if (!btn) return;
|
||||
const card = btn.closest('.server');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue