import { useFrigateStats } from "@/api/ws"; import useStats from "@/hooks/use-stats"; import { FrigateStats } from "@/types/stats"; import { useMemo } from "react"; import { IoIosWarning } from "react-icons/io"; import { MdCircle } from "react-icons/md"; import useSWR from "swr"; export default function Statusbar() { const { data: initialStats } = useSWR("stats", { revalidateOnFocus: false, }); const { payload: latestStats } = useFrigateStats(); const stats = useMemo(() => { if (latestStats) { return latestStats; } return initialStats; }, [initialStats, latestStats]); const cpuPercent = useMemo(() => { const systemCpu = stats?.cpu_usages["frigate.full_system"]?.cpu; if (!systemCpu || systemCpu == "0.0") { return null; } return parseInt(systemCpu); }, [stats]); const { potentialProblems } = useStats(stats); return (
{cpuPercent && (
CPU {cpuPercent}%
)} {Object.entries(stats?.gpu_usages || {}).map(([name, stats]) => { if (name == "error-gpu") { return; } let gpuTitle; switch (name) { case "amd-vaapi": gpuTitle = "AMD GPU"; break; case "intel-vaapi": case "intel-qsv": gpuTitle = "Intel GPU"; break; default: gpuTitle = name; break; } const gpu = parseInt(stats.gpu); return (
{gpuTitle} {gpu}%
); })}
{potentialProblems.map((prob) => (
{prob.text}
))}
); }