SPB Git

Repository Public

endurance.ts 4.7 KB 82 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Vision8 * File             : server/src/cli/endurance.ts9 * Module           : cli10 * Repository       : https://git.spboucher.ai/maclustr-vision11 * Project Website  : https://camera.spboucher.ai12 * Created          : 2026-11-3013 * Last Modified    : 2026-11-3014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Rapport d'endurance à partir des données réellement enregistrées (catalogue + métriques).43// Usage : endurance.ts [heures=24]   — n'invente rien : si la fenêtre est plus courte, il le dit.44import { listCameras, loadRegistry } from '../cameras.ts';45import { coverage } from '../catalog.ts';46import { loadConfig } from '../config.ts';47import { openDb } from '../db.ts';4849const cfg = loadConfig();50const db = openDb(cfg.dbPath);51const hours = Number(process.argv[2] || 24);52const to = Date.now();53const from = to - hours * 3600000;54const first = (db.prepare("SELECT MIN(start_ms) AS m FROM segments").get() as { m: number | null }).m;55const effFrom = Math.max(from, first || to);56const fmt = (ms: number) => new Date(ms).toISOString().slice(0, 19) + 'Z';57console.log(`# Rapport d'endurance MacLustr Vision\n`);58console.log(`Fenêtre demandée : ${hours} h · fenêtre réellement couverte par des données : ${((to - effFrom) / 3600000).toFixed(2)} h (${fmt(effFrom)} → ${fmt(to)})\n`);59const stat = (key: string) => {60  const r = db.prepare('SELECT COUNT(*) AS n, AVG(value) AS avg, MIN(value) AS min, MAX(value) AS max FROM metrics WHERE key = ? AND ts_ms BETWEEN ? AND ?').get(key, effFrom, to) as Record<string, number>;61  return r.n ? `moy. ${r.avg.toFixed(2)} · min ${r.min.toFixed(2)} · max ${r.max.toFixed(2)} (${r.n} mesures)` : 'aucune mesure';62};63console.log('| Caméra | Segments | Durée enregistrée | Couverture | Trous | Durée perdue | Taille | Débit moyen |');64console.log('|---|---|---|---|---|---|---|---|');65for (const cam of listCameras(db, loadRegistry(cfg))) {66  const c = coverage(db, cam.id, effFrom, to);67  const rec = c.ranges.reduce((a, r) => a + Math.min(r.endMs, to) - Math.max(r.startMs, effFrom), 0);68  const lost = c.gaps.reduce((a, g) => a + (g.endMs - g.startMs), 0);69  const span = c.ranges.length ? c.ranges[c.ranges.length - 1].endMs - c.ranges[0].startMs : 0;70  console.log(`| ${cam.id} | ${c.segments} | ${(rec / 3600000).toFixed(2)} h | ${span ? ((1 - lost / span) * 100).toFixed(3) : '0'} % | ${c.gaps.length} | ${(lost / 1000).toFixed(1)} s | ${(c.bytes / 1e9).toFixed(2)} Go | ${rec ? ((c.bytes * 8) / (rec / 1000) / 1e6).toFixed(2) : '0'} Mbit/s |`);71}72console.log(`\n- CPU du nœud (%) : ${stat('cpu_pct')}`);73console.log(`- CPU de Vision (% d'un cœur, tous processus) : ${stat('vision_cpu_pct')}`);74console.log(`- Mémoire de Vision (Mo RSS) : ${stat('vision_rss_mb')}`);75console.log(`- Débit enregistré total (bit/s) : ${stat('bitrate_bps')}`);76console.log(`- Archive (Go) : ${stat('archive_gb')}`);77const ev = db.prepare("SELECT type, COUNT(*) AS n FROM events WHERE ts_ms BETWEEN ? AND ? AND severity != 'info' GROUP BY type").all(effFrom, to) as { type: string; n: number }[];78console.log(`- Avertissements : ${ev.length ? ev.map((e) => `${e.type} ×${e.n}`).join(', ') : 'aucun'}`);79const rs = db.prepare('SELECT camera_id, recorder_restarts FROM camera_state').all() as { camera_id: string; recorder_restarts: number }[];80console.log(`- Relances d'enregistreur depuis le dernier démarrage du service : ${rs.map((r) => `${r.camera_id}=${r.recorder_restarts}`).join(', ')}`);81db.close();82
Files main
Menu

Theme