Add Metrics tab with historical server utilization and map capacity

This commit is contained in:
2026-09-20 21:58:08 -04:00
parent 3c8b5b2e40
commit 3a63e6d3ce
9 changed files with 304 additions and 4 deletions
+14
View File
@@ -11,6 +11,8 @@ import { restartSettling } from './restart-rollout.js';
import { classifyHealth } from '../fleet/health.js';
import { isProvisioning } from '../fleet/provisioning.js';
import { STATUS_REFRESH_MS } from '../../server-freshness.js';
import { recordMetrics } from '../fleet/metrics.js';
import { selectedZombieMap } from '../../map-aliases.js';
const TICK_MS = 15_000;
// Cap concurrent UDP RCON calls so a 15-server fleet doesn't blast the
@@ -68,6 +70,7 @@ async function refreshStatus(): Promise<void> {
if (servers.length === 0) return;
const entries: ServerStatusEntry[] = new Array(servers.length);
const capacities = new Map<string, number | null>();
let cursor = 0;
async function pump(): Promise<void> {
@@ -119,6 +122,7 @@ async function refreshStatus(): Promise<void> {
const now = new Date().toISOString();
if (result.ok) {
capacities.set(srv.name, result.status.capacity ?? null);
// Compare against the previously persisted count BEFORE we
// overwrite last_players — occupancy transitions are anchored
// to that boundary.
@@ -203,6 +207,16 @@ async function refreshStatus(): Promise<void> {
}
await Promise.all(Array.from({ length: STATUS_CONCURRENCY }, pump));
try {
recordMetrics(servers.map((srv, i) => ({
server: srv.name,
game: srv.game ?? 'unknown',
map: selectedZombieMap(srv.game, entries[i].map ?? srv.map, srv.map_slug)?.friendly ?? entries[i].map ?? srv.map ?? 'Unknown map',
players: capacities.has(srv.name) ? entries[i].players : null,
capacity: capacities.get(srv.name) ?? null
})));
} catch (err) { console.error('[worker] metrics error:', err); }
emit({ type: 'server-status', entries });
}