refactor(health): share health snapshot computation

This commit is contained in:
2026-04-21 13:36:07 +00:00
parent 9022c8dbf3
commit 405fff91af
3 changed files with 64 additions and 74 deletions
+7 -35
View File
@@ -22,6 +22,7 @@ import { VERSION } from '../constants.ts';
import type { ContainerManager } from '../containers/container-manager.ts';
import type { ClusterManager } from '../cluster/cluster-manager.ts';
import { GpuDetector } from '../hardware/gpu-detector.ts';
import { buildHealthSnapshot } from '../helpers/health.ts';
interface IBundledFile {
path: string;
@@ -150,42 +151,13 @@ export class UiServer {
const models = await this.containerManager.getAllAvailableModels();
const gpus = await this.gpuDetector.detectGpus();
let status: 'ok' | 'degraded' | 'error' = 'ok';
const reasons = new Set<'unhealthy_container' | 'no_models_available' | 'gpu_detection_failed'>();
const containerHealth: Record<string, 'healthy' | 'unhealthy'> = {};
const gpuStatus: Record<string, 'available' | 'in_use' | 'error'> = {};
for (const [id, s] of statuses) {
if (s.running && s.health === 'healthy') {
containerHealth[id] = 'healthy';
} else {
containerHealth[id] = 'unhealthy';
status = 'degraded';
reasons.add('unhealthy_container');
}
}
for (const gpu of gpus) {
gpuStatus[gpu.id] = 'available';
}
if (models.size === 0) {
status = 'degraded';
reasons.add('no_models_available');
}
const health: IHealthResponse = {
status,
reasons: Array.from(reasons),
const health: IHealthResponse = buildHealthSnapshot({
statuses,
modelCount: models.size,
gpus,
startTime: this.startTime,
version: VERSION,
uptime: Math.floor((Date.now() - this.startTime) / 1000),
containers: statuses.size,
models: models.size,
gpus: gpus.length,
details: {
containers: containerHealth,
gpus: gpuStatus,
},
};
});
const clusterConfig = this.clusterManager.getConfig();