mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-12 19:37:35 +03:00
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* debug replay implementation * fix masks after dev rebase * fix squash merge issues * fix * fix * fix * no need to write debug replay camera to config * camera and filter button and dropdown * add filters * add ability to edit motion and object config for debug replay * add debug draw overlay to debug replay * add guard to prevent crash when camera is no longer in camera_states * fix overflow due to radix absolutely positioned elements * increase number of messages * ensure deep_merge replaces existing list values when override is true * add back button * add debug replay to explore and review menus * clean up * clean up * update instructions to prevent exposing exception info * fix typing * refactor output logic * refactor with helper function * move init to function for consistency
172 lines
4.9 KiB
TypeScript
172 lines
4.9 KiB
TypeScript
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";
|
|
import useDeepMemo from "./use-deep-memo";
|
|
import { capitalizeAll, capitalizeFirstLetter } from "@/utils/stringUtil";
|
|
import { isReplayCamera } from "@/utils/cameraUtil";
|
|
import { useFrigateStats } from "@/api/ws";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export default function useStats(stats: FrigateStats | undefined) {
|
|
const { t } = useTranslation(["views/system"]);
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
const { data: debugReplayStatus } = useSWR("debug_replay/status", {
|
|
revalidateOnFocus: false,
|
|
});
|
|
|
|
const memoizedStats = useDeepMemo(stats);
|
|
|
|
const potentialProblems = useMemo<PotentialProblem[]>(() => {
|
|
const problems: PotentialProblem[] = [];
|
|
|
|
if (!memoizedStats) {
|
|
return problems;
|
|
}
|
|
|
|
// if frigate has just started
|
|
// don't look for issues
|
|
if (memoizedStats.service.uptime < 120) {
|
|
return problems;
|
|
}
|
|
|
|
// check shm level
|
|
const shm = memoizedStats.service.storage["/dev/shm"];
|
|
if (shm?.total && shm?.min_shm && shm.total < shm.min_shm) {
|
|
problems.push({
|
|
text: t("stats.shmTooLow", {
|
|
total: shm.total,
|
|
min: shm.min_shm,
|
|
}),
|
|
color: "text-danger",
|
|
relevantLink: "/system#storage",
|
|
});
|
|
}
|
|
|
|
// check detectors for high inference speeds
|
|
Object.entries(memoizedStats["detectors"]).forEach(([key, det]) => {
|
|
if (det["inference_speed"] > InferenceThreshold.error) {
|
|
problems.push({
|
|
text: t("stats.detectIsVerySlow", {
|
|
detect: capitalizeFirstLetter(key),
|
|
speed: det["inference_speed"],
|
|
}),
|
|
color: "text-danger",
|
|
relevantLink: "/system#general",
|
|
});
|
|
} else if (det["inference_speed"] > InferenceThreshold.warning) {
|
|
problems.push({
|
|
text: t("stats.detectIsSlow", {
|
|
detect: capitalizeFirstLetter(key),
|
|
speed: det["inference_speed"],
|
|
}),
|
|
color: "text-orange-400",
|
|
relevantLink: "/system#general",
|
|
});
|
|
}
|
|
});
|
|
|
|
// check for offline cameras
|
|
Object.entries(memoizedStats["cameras"]).forEach(([name, cam]) => {
|
|
if (!config) {
|
|
return;
|
|
}
|
|
|
|
// Skip replay cameras
|
|
if (isReplayCamera(name)) {
|
|
return;
|
|
}
|
|
|
|
const cameraName = config.cameras?.[name]?.friendly_name ?? name;
|
|
if (config.cameras[name].enabled && cam["camera_fps"] == 0) {
|
|
problems.push({
|
|
text: t("stats.cameraIsOffline", {
|
|
camera: capitalizeFirstLetter(capitalizeAll(cameraName)),
|
|
}),
|
|
color: "text-danger",
|
|
relevantLink: "logs",
|
|
});
|
|
}
|
|
});
|
|
|
|
// check camera cpu usages
|
|
Object.entries(memoizedStats["cameras"]).forEach(([name, cam]) => {
|
|
const ffmpegAvg = parseFloat(
|
|
memoizedStats["cpu_usages"][cam["ffmpeg_pid"]]?.cpu_average,
|
|
);
|
|
const detectAvg = parseFloat(
|
|
memoizedStats["cpu_usages"][cam["pid"]]?.cpu_average,
|
|
);
|
|
|
|
const cameraName = config?.cameras?.[name]?.friendly_name ?? name;
|
|
|
|
// Skip ffmpeg warnings for replay cameras when debug replay is active
|
|
if (
|
|
!isNaN(ffmpegAvg) &&
|
|
ffmpegAvg >= CameraFfmpegThreshold.error &&
|
|
!(
|
|
debugReplayStatus?.active && debugReplayStatus?.replay_camera === name
|
|
)
|
|
) {
|
|
problems.push({
|
|
text: t("stats.ffmpegHighCpuUsage", {
|
|
camera: capitalizeFirstLetter(capitalizeAll(cameraName)),
|
|
ffmpegAvg,
|
|
}),
|
|
color: "text-danger",
|
|
relevantLink: "/system#cameras",
|
|
});
|
|
}
|
|
|
|
if (!isNaN(detectAvg) && detectAvg >= CameraDetectThreshold.error) {
|
|
problems.push({
|
|
text: t("stats.detectHighCpuUsage", {
|
|
camera: capitalizeFirstLetter(capitalizeAll(cameraName)),
|
|
detectAvg,
|
|
}),
|
|
color: "text-danger",
|
|
relevantLink: "/system#cameras",
|
|
});
|
|
}
|
|
});
|
|
|
|
// Add message if debug replay is active
|
|
if (debugReplayStatus?.active) {
|
|
problems.push({
|
|
text: t("stats.debugReplayActive", {
|
|
defaultValue: "Debug replay session is active",
|
|
}),
|
|
color: "text-selected",
|
|
relevantLink: "/replay",
|
|
});
|
|
}
|
|
|
|
return problems;
|
|
}, [config, memoizedStats, t, debugReplayStatus]);
|
|
|
|
return { potentialProblems };
|
|
}
|
|
|
|
export function useAutoFrigateStats() {
|
|
const { data: initialStats } = useSWR<FrigateStats>("stats", {
|
|
revalidateOnFocus: false,
|
|
});
|
|
const latestStats = useFrigateStats();
|
|
|
|
const stats = useMemo(() => {
|
|
if (latestStats) {
|
|
return latestStats;
|
|
}
|
|
|
|
return initialStats;
|
|
}, [initialStats, latestStats]);
|
|
|
|
return stats;
|
|
}
|