feat: socle BDD (tâche 1.9 Phase 1-2) + moteur APT (tâche 2 SJ-0→3) + WIP capabilities/auth/Rust
Checkpoint multi-chantiers (arbre vert : tsc 0 erreur, 70 tests, build OK). - tâche 1.9 Phase 1 : schéma socle (machine_state/events/reports/raw_artifacts/ hardware/metrics + colonnes étendues) + wiring refresh/execute. Migration 0002. - tâche 1.9 Phase 2 : machine_credentials + machine_host_keys (non destructif, dual-read + backfill). Migration 0003. Fix séquence journal de migration. - tâche 2 : SJ-0 (types étendus rétro-compatibles, réducteur Docker, resolveTemplate), SJ-1 (update-analyze enrichi), SJ-2 (apply + diff dpkg + timeout inactivité SSH), SJ-3 (reboot vérifié boot_id). - WIP parallèle inclus : /api/capabilities, auth/apiTokens/apiClients, system metrics, scaffold app_rust, ajustements frontend. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// server/services/system.ts
|
||||
import os from "node:os";
|
||||
import type { SystemMetrics, SystemStatus } from "@shared/types.js";
|
||||
|
||||
const APP_VERSION = "0.1.0";
|
||||
const MB = 1024 * 1024;
|
||||
|
||||
function round2(value: number): number {
|
||||
return Math.round(value * 100) / 100;
|
||||
}
|
||||
|
||||
export function getSystemStatus(now = new Date()): SystemStatus {
|
||||
return {
|
||||
app: "system_update",
|
||||
version: APP_VERSION,
|
||||
apiVersion: "1",
|
||||
serverTime: now.toISOString(),
|
||||
uptimeSeconds: Math.round(process.uptime()),
|
||||
};
|
||||
}
|
||||
|
||||
export function getSystemMetrics(now = new Date()): SystemMetrics {
|
||||
const memory = process.memoryUsage();
|
||||
const load = os.loadavg();
|
||||
|
||||
return {
|
||||
collectedAt: now.toISOString(),
|
||||
process: {
|
||||
uptimeSeconds: Math.round(process.uptime()),
|
||||
rssMb: round2(memory.rss / MB),
|
||||
heapUsedMb: round2(memory.heapUsed / MB),
|
||||
heapTotalMb: round2(memory.heapTotal / MB),
|
||||
},
|
||||
host: {
|
||||
loadAverage1m: round2(load[0] ?? 0),
|
||||
loadAverage5m: round2(load[1] ?? 0),
|
||||
loadAverage15m: round2(load[2] ?? 0),
|
||||
totalMemoryMb: round2(os.totalmem() / MB),
|
||||
freeMemoryMb: round2(os.freemem() / MB),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const systemInternals = { round2 };
|
||||
Reference in New Issue
Block a user