Replace unused server metrics with a count (Refs #139)
CI / checks (push) Successful in 4m51s

This commit is contained in:
2026-10-10 16:55:28 -04:00
parent aebfc7a783
commit 0bfda267ec
7 changed files with 80 additions and 88 deletions
+9 -26
View File
@@ -13,7 +13,6 @@ import {
type MetricsQuery,
type PreviousMetrics,
type RunningMetrics,
type ServerMetrics,
type Utilization
} from '../../metrics.js';
@@ -191,17 +190,13 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
);
const globalBounds = evidenceBounds(groups);
const scopedBounds = evidenceBounds(groups.filter(matchesScope));
const registered = new Set(
(
handle.prepare('SELECT name FROM servers WHERE destroyed_at IS NULL').all() as {
name: string;
}[]
).map((server) => server.name)
);
const registered = handle
.prepare('SELECT COUNT(*) AS count FROM servers WHERE destroyed_at IS NULL')
.get() as { count: number };
const metadata = {
firstRetainedSampleAt: globalBounds.first,
latestSampleAt: globalBounds.latest,
registeredServerCount: registered.size,
registeredServerCount: registered.count,
scopeFirstSampleAt: scopedBounds.first,
scopeLatestSampleAt: scopedBounds.latest
};
@@ -236,7 +231,7 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
lastSampleAt: null,
partialHistory: false
};
const serverTotals = new Map<string, ServerMetrics>();
const sampledServers = new Set<string>();
const mapTotals = new Map<string, Map<string, MapMetrics>>();
function mapFor(gameName: string, label: string): MapMetrics {
let game = mapTotals.get(gameName);
@@ -401,8 +396,8 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
for (const sample of samples)
addObservation(previous.summary, sample.players, priorHours);
}
// Preserve current-window zero-duration rows without bringing rows from
// the separate comparison window into the visible server/map tables.
// Preserve current-window zero-duration evidence without bringing samples
// from the separate comparison window into the current count or map table.
if (at < since - ONLINE_MAX_MS) return;
const start = Math.max(at, since);
const hours = Math.max(0, end - start) / 3600_000;
@@ -425,18 +420,9 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
cursor = stop;
}
for (const sample of samples) {
let server = serverTotals.get(sample.server);
if (!server) {
server = {
server: sample.server,
currentRegistered: registered.has(sample.server),
...emptyUtilization()
};
serverTotals.set(sample.server, server);
}
sampledServers.add(sample.server);
const map = mapFor(sample.game, sample.map);
addObservation(summary, sample.players, hours);
addObservation(server, sample.players, hours);
addObservation(map, sample.players, hours);
for (const slice of slices) addObservation(slice.point, sample.players, slice.hours);
if (sample.players === null) counts.unknown++;
@@ -493,9 +479,6 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
}
aggregateBatch(now);
const servers = [...serverTotals.values()].sort(
(a, b) => b.active - a.active || compareText(a.server, b.server)
);
const maps = [...mapTotals.values()]
.flatMap((game) => [...game.values()])
.sort(
@@ -531,7 +514,7 @@ export function readMetrics(input: MetricsDays | MetricsQuery, now = Date.now())
summary,
running,
matches: matchMetrics(totalMatches),
servers,
sampledServerCount: sampledServers.size,
maps,
points,
previous,