From d96ee6dbf1e1b5193924f43b3289367a62e5df22 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 1 Apr 2024 08:56:31 -0500 Subject: [PATCH] check for invalid value --- web/src/hooks/use-stats.ts | 40 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/web/src/hooks/use-stats.ts b/web/src/hooks/use-stats.ts index 9c6ec40b9..57461d063 100644 --- a/web/src/hooks/use-stats.ts +++ b/web/src/hooks/use-stats.ts @@ -36,33 +36,23 @@ export default function useStats(stats: FrigateStats | undefined) { // check camera cpu usages Object.entries(stats["cameras"]).forEach(([name, cam]) => { - 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, - ); + 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(detectAvg) && detectAvg >= 40.0) { - problems.push({ - text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`, - color: "text-danger", - }); - } - } else { + if (!isNaN(ffmpegAvg) && ffmpegAvg >= 20.0) { problems.push({ - text: `${name.replaceAll("_", " ")} is offline.`, + text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`, + color: "text-danger", + }); + } + + if (!isNaN(detectAvg) && detectAvg >= 40.0) { + problems.push({ + text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`, color: "text-danger", }); }