SPB Git

Repository Public

System.tsx 7.6 KB 178 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Vision8 * File             : web/src/pages/System.tsx9 * Module           : pages10 * 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 */4142import { api } from '../api';43import { useApp, usePoll } from '../ctx';44import { fmtAgo, fmtBitrate, fmtBytes, fmtDateTime, fmtDuration } from '../fmt';4546function Spark({ points }: { points: [number, number][] }) {47  if (points.length < 2) return <div className="faint" style={{ fontSize: 12, height: 44, display: 'flex', alignItems: 'center' }}>Pas encore assez de mesures</div>;48  const xs = points.map((p) => p[0]);49  const ys = points.map((p) => p[1]);50  const x0 = Math.min(...xs);51  const x1 = Math.max(...xs);52  const y1 = Math.max(...ys, 0.0001);53  const pts = points.map(([x, y]) => `${(((x - x0) / (x1 - x0 || 1)) * 100).toFixed(2)},${(40 - (y / y1) * 36).toFixed(2)}`).join(' ');54  return (55    <svg className="spark" viewBox="0 0 100 42" preserveAspectRatio="none" aria-hidden="true">56      <polyline points={pts} />57    </svg>58  );59}6061export function SystemPage() {62  const { cameras } = useApp();63  const { data: s, error } = usePoll(() => api<any>('/api/system/status'), 10000);64  if (!s) return <div className="card empty">{error || 'Chargement…'}</div>;65  const names = new Map(cameras.map((c) => [c.id, c.name]));66  const now = s.serverTimeMs;67  return (68    <>69      <div className="page-head">70        <h1>71          Système72          <span className="sub">73            Nœud {s.node.hostname} · {s.node.cpuModel} · {s.node.cpus} cœurs · {fmtBytes(s.node.totalMemBytes)}74          </span>75        </h1>76      </div>77      <div className="stack">78        {!s.core.alive && <div className="notice bad">Le service d’enregistrement (vision-core) ne donne plus signe de vie depuis {fmtAgo(s.core.lastBeatMs, now)}.</div>}79        <div className="card pad stack">80          <div className="stats">81            <div className="stat">82              <b>{s.current.cpuPct === null ? '—' : `${s.current.cpuPct.toFixed(0)} %`}</b>83              <span>CPU du nœud</span>84            </div>85            <div className="stat">86              <b>{s.current.visionRssMb === null ? '—' : `${Math.round(s.current.visionRssMb)} Mo`}</b>87              <span>mémoire de Vision ({s.current.processes ?? '—'} processus)</span>88            </div>89            <div className="stat">90              <b>{fmtBitrate(s.current.bitrateBps)}</b>91              <span>débit enregistré</span>92            </div>93            <div className="stat">94              <b>{fmtDuration(s.node.uptimeS)}</b>95              <span>depuis le démarrage du nœud</span>96            </div>97          </div>98        </div>99        <div className="grid-2">100          <div className="card pad stack">101            <h2>CPU du nœud — 3 h</h2>102            <Spark points={s.series.cpuPct} />103          </div>104          <div className="card pad stack">105            <h2>Débit enregistré — 3 h</h2>106            <Spark points={s.series.bitrateBps} />107          </div>108        </div>109        <div className="grid-2">110          <div className="card pad stack">111            <h2>Services</h2>112            <dl className="kv">113              <dt>Enregistreur (vision-core)</dt>114              <dd>115                <span className={`dot ${s.core.alive ? 'ok' : 'bad'}`} /> {s.core.alive ? `actif depuis ${fmtDuration((now - s.core.startedMs) / 1000)}` : 'arrêté'}116              </dd>117              <dt>Passerelle vidéo</dt>118              <dd>119                <span className={`dot ${s.core.gateway?.running ? 'ok' : 'bad'}`} /> {s.core.gateway?.running ? `active · ${s.core.gateway.restarts} relance(s)` : 'arrêtée'}120              </dd>121              <dt>API</dt>122              <dd>123                <span className="dot ok" /> active depuis {fmtDuration((now - s.api.startedMs) / 1000)}124              </dd>125              <dt>Spectateurs du direct</dt>126              <dd>{s.api.liveViewers}</dd>127              <dt>Version</dt>128              <dd className="mono">129                {s.api.version}130                {s.api.commit ? ` (${s.api.commit})` : ''} · Node {s.api.node}131              </dd>132              <dt>Charge (1 / 5 / 15 min)</dt>133              <dd className="mono">{s.node.load.map((l: number) => l.toFixed(2)).join(' / ')}</dd>134            </dl>135          </div>136          <div className="card pad stack">137            <h2>Enregistreurs</h2>138            <div className="list">139              {s.workers.map((w: any) => (140                <div key={w.cameraId} className="list-item" style={{ paddingLeft: 0, paddingRight: 0 }}>141                  <span className={`dot ${w.recorderState === 'recording' ? 'ok' : w.recorderState === 'stopped' ? '' : 'warn'}`} />142                  <div className="grow">143                    <div style={{ fontWeight: 550 }}>{names.get(w.cameraId) || w.cameraId}</div>144                    <div className="muted" style={{ fontSize: 13 }}>145                      {({ recording: 'Enregistre', starting: 'Démarrage', backoff: 'Nouvelle tentative', stopped: 'Arrêté', suspended: 'Suspendu' } as any)[w.recorderState] || w.recorderState} · {w.restarts} relance(s) · dernier segment {fmtAgo(w.lastSegmentEndMs, now)}146                    </div>147                  </div>148                  <span className="mono muted">{fmtBitrate(w.bitrateBps)}</span>149                </div>150              ))}151            </div>152          </div>153        </div>154        <div className="card">155          <div style={{ padding: '14px 16px 4px' }}>156            <h2>Avertissements récents</h2>157          </div>158          <div className="list">159            {s.recentErrors.length === 0 && <div className="empty">Aucun avertissement.</div>}160            {s.recentErrors.map((e: any) => (161              <div key={e.id} className="list-item">162                <span className={`dot ${e.severity === 'critical' ? 'bad' : 'warn'}`} />163                <div className="grow">164                  <div>{e.message}</div>165                  <div className="faint mono" style={{ fontSize: 12 }}>166                    {fmtDateTime(e.tsMs)}167                    {e.cameraId ? ` · ${names.get(e.cameraId) || e.cameraId}` : ''}168                  </div>169                </div>170              </div>171            ))}172          </div>173        </div>174      </div>175    </>176  );177}178
Files main
Menu

Theme