diff --git a/frigate/stats/emitter.py b/frigate/stats/emitter.py index f914770fa..5b76a7e6f 100644 --- a/frigate/stats/emitter.py +++ b/frigate/stats/emitter.py @@ -6,6 +6,7 @@ import logging import threading import time from multiprocessing.synchronize import Event as MpEvent +from typing import Optional from frigate.comms.inter_process import InterProcessRequestor from frigate.config import FrigateConfig @@ -47,14 +48,27 @@ class StatsEmitter(threading.Thread): self.stats_history.append(stats) return stats - def get_stats_history(self) -> list[dict[str, any]]: + def get_stats_history(self, keys: Optional[list[str]] = None) -> list[dict[str, any]]: """Get stats history.""" - return self.stats_history + if not keys: + return self.stats_history + + selected_stats: list[dict[str, any]] = [] + + for s in self.stats_history: + selected = {} + + for k in keys: + selected[k] = selected_stats[k] + + selected_stats.append(selected) + + return selected_stats def run(self) -> None: time.sleep(10) for counter in itertools.cycle(range(self.config.record.expire_interval)): - if self.stop_event.wait(5): + if self.stop_event.wait(10): break logger.debug("Starting stats collection") diff --git a/web/src/hooks/use-stats.ts b/web/src/hooks/use-stats.ts index 18346538d..3a5c6e9ab 100644 --- a/web/src/hooks/use-stats.ts +++ b/web/src/hooks/use-stats.ts @@ -1,4 +1,9 @@ import { FrigateConfig } from "@/types/frigateConfig"; +import { + CameraDetectThreshold, + CameraFfmpegThreshold, + InferenceThreshold, +} from "@/types/graph"; import { FrigateStats, PotentialProblem } from "@/types/stats"; import { useMemo } from "react"; import useSWR from "swr"; @@ -15,12 +20,12 @@ export default function useStats(stats: FrigateStats | undefined) { // check detectors for high inference speeds Object.entries(stats["detectors"]).forEach(([key, det]) => { - if (det["inference_speed"] > 100) { + if (det["inference_speed"] > InferenceThreshold.error) { problems.push({ text: `${key} is very slow (${det["inference_speed"]} ms)`, color: "text-danger", }); - } else if (det["inference_speed"] > 50) { + } else if (det["inference_speed"] > InferenceThreshold.warning) { problems.push({ text: `${key} is slow (${det["inference_speed"]} ms)`, color: "text-orange-400", @@ -51,14 +56,14 @@ export default function useStats(stats: FrigateStats | undefined) { stats["cpu_usages"][cam["pid"]]?.cpu_average, ); - if (!isNaN(ffmpegAvg) && ffmpegAvg >= 20.0) { + if (!isNaN(ffmpegAvg) && ffmpegAvg >= CameraFfmpegThreshold.error) { problems.push({ text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`, color: "text-danger", }); } - if (!isNaN(detectAvg) && detectAvg >= 40.0) { + if (!isNaN(detectAvg) && detectAvg >= CameraDetectThreshold.error) { problems.push({ text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`, color: "text-danger", diff --git a/web/src/types/graph.ts b/web/src/types/graph.ts index fe9db843f..cff87f6f3 100644 --- a/web/src/types/graph.ts +++ b/web/src/types/graph.ts @@ -27,3 +27,13 @@ export const DetectorMemThreshold = { warning: 20, error: 50, } as Threshold; + +export const CameraFfmpegThreshold = { + warning: 20, + error: 20, +} as Threshold; + +export const CameraDetectThreshold = { + warning: 20, + error: 40, +} as Threshold;