diff --git a/web/src/hooks/use-stats.ts b/web/src/hooks/use-stats.ts index b5e0407a6..9c6ec40b9 100644 --- a/web/src/hooks/use-stats.ts +++ b/web/src/hooks/use-stats.ts @@ -36,21 +36,33 @@ export default function useStats(stats: FrigateStats | undefined) { // check camera cpu usages Object.entries(stats["cameras"]).forEach(([name, cam]) => { - const ffmpegAvg = parseFloat( - stats["cpu_usages"][cam["ffmpeg_pid"]].cpu_average, - ); - const detectAvg = parseFloat(stats["cpu_usages"][cam["pid"]].cpu_average); + if ( + stats["cpu_usages"][cam["ffmpeg_pid"]] && + stats["cpu_usages"][cam["pid"]] + ) { + const ffmpegAvg = parseFloat( + stats["cpu_usages"][cam["ffmpeg_pid"]].cpu_average, + ); + const detectAvg = parseFloat( + stats["cpu_usages"][cam["pid"]].cpu_average, + ); - if (!isNaN(ffmpegAvg) && ffmpegAvg >= 20.0) { - problems.push({ - text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`, - color: "text-danger", - }); - } + if (!isNaN(ffmpegAvg) && ffmpegAvg >= 20.0) { + problems.push({ + text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`, + color: "text-danger", + }); + } - if (!isNaN(detectAvg) && detectAvg >= 40.0) { + if (!isNaN(detectAvg) && detectAvg >= 40.0) { + problems.push({ + text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`, + color: "text-danger", + }); + } + } else { problems.push({ - text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`, + text: `${name.replaceAll("_", " ")} is offline.`, color: "text-danger", }); }