Use types for thresholds

This commit is contained in:
Nicolas Mowen 2024-04-01 07:19:59 -06:00
parent bf8d4adfc5
commit 135ca53113
3 changed files with 36 additions and 7 deletions

View File

@ -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."""
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")

View File

@ -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",

View File

@ -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;