mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
Use types for thresholds
This commit is contained in:
parent
bf8d4adfc5
commit
135ca53113
@ -6,6 +6,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
from multiprocessing.synchronize import Event as MpEvent
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from frigate.comms.inter_process import InterProcessRequestor
|
from frigate.comms.inter_process import InterProcessRequestor
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
@ -47,14 +48,27 @@ class StatsEmitter(threading.Thread):
|
|||||||
self.stats_history.append(stats)
|
self.stats_history.append(stats)
|
||||||
return 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."""
|
"""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:
|
def run(self) -> None:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
for counter in itertools.cycle(range(self.config.record.expire_interval)):
|
for counter in itertools.cycle(range(self.config.record.expire_interval)):
|
||||||
if self.stop_event.wait(5):
|
if self.stop_event.wait(10):
|
||||||
break
|
break
|
||||||
|
|
||||||
logger.debug("Starting stats collection")
|
logger.debug("Starting stats collection")
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import {
|
||||||
|
CameraDetectThreshold,
|
||||||
|
CameraFfmpegThreshold,
|
||||||
|
InferenceThreshold,
|
||||||
|
} from "@/types/graph";
|
||||||
import { FrigateStats, PotentialProblem } from "@/types/stats";
|
import { FrigateStats, PotentialProblem } from "@/types/stats";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
@ -15,12 +20,12 @@ export default function useStats(stats: FrigateStats | undefined) {
|
|||||||
|
|
||||||
// check detectors for high inference speeds
|
// check detectors for high inference speeds
|
||||||
Object.entries(stats["detectors"]).forEach(([key, det]) => {
|
Object.entries(stats["detectors"]).forEach(([key, det]) => {
|
||||||
if (det["inference_speed"] > 100) {
|
if (det["inference_speed"] > InferenceThreshold.error) {
|
||||||
problems.push({
|
problems.push({
|
||||||
text: `${key} is very slow (${det["inference_speed"]} ms)`,
|
text: `${key} is very slow (${det["inference_speed"]} ms)`,
|
||||||
color: "text-danger",
|
color: "text-danger",
|
||||||
});
|
});
|
||||||
} else if (det["inference_speed"] > 50) {
|
} else if (det["inference_speed"] > InferenceThreshold.warning) {
|
||||||
problems.push({
|
problems.push({
|
||||||
text: `${key} is slow (${det["inference_speed"]} ms)`,
|
text: `${key} is slow (${det["inference_speed"]} ms)`,
|
||||||
color: "text-orange-400",
|
color: "text-orange-400",
|
||||||
@ -51,14 +56,14 @@ export default function useStats(stats: FrigateStats | undefined) {
|
|||||||
stats["cpu_usages"][cam["pid"]]?.cpu_average,
|
stats["cpu_usages"][cam["pid"]]?.cpu_average,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isNaN(ffmpegAvg) && ffmpegAvg >= 20.0) {
|
if (!isNaN(ffmpegAvg) && ffmpegAvg >= CameraFfmpegThreshold.error) {
|
||||||
problems.push({
|
problems.push({
|
||||||
text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`,
|
text: `${name.replaceAll("_", " ")} has high FFMPEG CPU usage (${ffmpegAvg}%)`,
|
||||||
color: "text-danger",
|
color: "text-danger",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNaN(detectAvg) && detectAvg >= 40.0) {
|
if (!isNaN(detectAvg) && detectAvg >= CameraDetectThreshold.error) {
|
||||||
problems.push({
|
problems.push({
|
||||||
text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`,
|
text: `${name.replaceAll("_", " ")} has high detect CPU usage (${detectAvg}%)`,
|
||||||
color: "text-danger",
|
color: "text-danger",
|
||||||
|
|||||||
@ -27,3 +27,13 @@ export const DetectorMemThreshold = {
|
|||||||
warning: 20,
|
warning: 20,
|
||||||
error: 50,
|
error: 50,
|
||||||
} as Threshold;
|
} as Threshold;
|
||||||
|
|
||||||
|
export const CameraFfmpegThreshold = {
|
||||||
|
warning: 20,
|
||||||
|
error: 20,
|
||||||
|
} as Threshold;
|
||||||
|
|
||||||
|
export const CameraDetectThreshold = {
|
||||||
|
warning: 20,
|
||||||
|
error: 40,
|
||||||
|
} as Threshold;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user