fromHealthz static method
- String? body
null for anything but an ObservANT camera's /healthz that carries stats.
Implementation
static ServerStats? fromHealthz(String? body) {
final json = decodeJsonObject(body);
final stats = json?['stats'];
if (json == null || stats is! Map<String, dynamic>) {
return null;
}
double? number(Object? v) => v is num ? v.toDouble() : null;
int? whole(Object? v) => v is int ? v : null;
final frame = json['frame'];
final uptime = whole(stats['uptime_s']);
return ServerStats(
captureFps: number(stats['capture_fps']),
configuredFps: frame is Map<String, dynamic> ? whole(frame['fps']) : null,
modelMs: number(stats['model_ms']),
modelRunsPerSecond: number(stats['model_runs_per_s']),
cpuPercent: number(stats['cpu_percent']),
cores: whole(stats['cores']),
rssMb: number(stats['rss_mb']),
load1m: number(stats['load_1m']),
temperatureC: number(stats['temperature_c']),
uptime: uptime == null ? null : Duration(seconds: uptime),
viewers: whole(json['viewers']),
);
}