Replace unused server metrics with a count (Refs #139)
CI / checks (push) Successful in 4m51s
CI / checks (push) Successful in 4m51s
This commit is contained in:
+2
-7
@@ -50,12 +50,6 @@ export interface Utilization {
|
||||
playerHours: number;
|
||||
}
|
||||
|
||||
export interface ServerMetrics extends Utilization {
|
||||
server: string;
|
||||
/** A current registration with this name exists; historical identity may differ. */
|
||||
currentRegistered: boolean;
|
||||
}
|
||||
|
||||
export interface MatchMetrics {
|
||||
/** Retained matches whose recorded start is within the selected window. */
|
||||
started: number;
|
||||
@@ -153,7 +147,8 @@ export interface MetricsData {
|
||||
scopeLatestSampleAt: number | null;
|
||||
summary: Utilization;
|
||||
running: RunningMetrics;
|
||||
servers: ServerMetrics[];
|
||||
/** Distinct recorded names sampled in this scope/window, including zero elapsed time. */
|
||||
sampledServerCount: number;
|
||||
matches: MatchMetrics;
|
||||
maps: MapMetrics[];
|
||||
points: MetricPoint[];
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -63,6 +63,8 @@ function validReport(value: unknown): value is MetricsData {
|
||||
return false;
|
||||
if (
|
||||
!numeric(value.registeredServerCount) ||
|
||||
!nonnegative(value.sampledServerCount) ||
|
||||
!Number.isInteger(value.sampledServerCount) ||
|
||||
typeof value.autoscalingPaused !== 'boolean' ||
|
||||
![
|
||||
'firstRetainedSampleAt',
|
||||
@@ -107,17 +109,6 @@ function validReport(value: unknown): value is MetricsData {
|
||||
)
|
||||
)
|
||||
return false;
|
||||
if (
|
||||
!Array.isArray(value.servers) ||
|
||||
!value.servers.every(
|
||||
(item) =>
|
||||
record(item) &&
|
||||
totals(item) &&
|
||||
typeof item.server === 'string' &&
|
||||
typeof item.currentRegistered === 'boolean'
|
||||
)
|
||||
)
|
||||
return false;
|
||||
if (
|
||||
!record(value.previous) ||
|
||||
!totals(value.previous.summary) ||
|
||||
|
||||
@@ -257,14 +257,14 @@
|
||||
<EmptyState
|
||||
title={report.latestSampleAt === null
|
||||
? 'No retained observations yet'
|
||||
: report.servers.length > 0
|
||||
: report.sampledServerCount > 0
|
||||
? 'Waiting for observed time'
|
||||
: 'No captured time in this scope'}
|
||||
description={report.latestSampleAt === null
|
||||
? report.registeredServerCount > 0
|
||||
? 'Leave the manager running to collect server status and build a history.'
|
||||
: 'Register a server to begin collecting utilization history.'
|
||||
: report.servers.length > 0
|
||||
: report.sampledServerCount > 0
|
||||
? 'Captured samples have no elapsed time in this window. Time builds between status checks.'
|
||||
: 'There are no elapsed observations for the selected game, map, and time window. Try another scope or a wider range.'}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user