Files
electric-cherry/src/lib/capacity.ts
T

75 lines
2.2 KiB
TypeScript

import type { CapacityCalibration, HostReadiness } from './hosts.js';
export type CapacityRange = '1h' | '24h' | '7d';
export type CapacityGame = 'all' | 't5' | 't6';
export interface CapacityQuery {
range: CapacityRange;
hostId: string | null;
game: CapacityGame;
}
export function parseCapacityQuery(params: URLSearchParams): CapacityQuery {
const range = params.get('range');
const game = params.get('game');
return {
range: range === '1h' || range === '7d' ? range : '24h',
game: game === 't5' || game === 't6' ? game : 'all',
hostId: params.get('host')?.trim().slice(0, 100) || null
};
}
export interface CapacityHistoryPoint {
at: number;
cpuCoresAvailable: number | null;
memoryBytesAvailable: number | null;
reportingHosts: number;
expectedHosts: number;
}
export interface CapacityHistory {
range: CapacityRange;
startAt: number;
endAt: number;
bucketMs: number;
points: CapacityHistoryPoint[];
}
export interface CapacityHost {
id: string;
name: string;
readiness: HostReadiness;
connected: boolean;
updatedAt: string | null;
eligible: boolean;
games: ('t5' | 't6')[];
reasons: string[];
cpuCoresAvailable: number | null;
memoryBytesAvailable: number | null;
portsAvailable: number;
totalPorts: number;
estimatedServers: number | null;
limits: { cpu: number | null; memory: number | null; ports: number };
limitingResource: 'CPU' | 'Memory' | 'Ports' | null;
calibration: CapacityCalibration;
}
export interface CapacityCurrent {
updatedAt: string | null;
summary: {
estimatedServers: number | null;
cpuCoresAvailable: number | null;
memoryBytesAvailable: number | null;
portsAvailable: number | null;
eligibleHosts: number;
totalHosts: number;
startupSlots: number | null;
startupLimit: number | null;
activeStartups: number | null;
queued: number | null;
};
hosts: CapacityHost[];
hostOptions: { id: string; name: string }[];
warnings: string[];
}
export interface CapacityData {
query: CapacityQuery;
current: CapacityCurrent;
history: CapacityHistory;
}