import { useEmbeddingsReindexProgress } from "@/api/ws"; import { StatusBarMessagesContext, StatusMessage, } from "@/context/statusbar-provider"; import useStats, { useAutoFrigateStats } from "@/hooks/use-stats"; import { useContext, useEffect, useMemo } from "react"; import { FaCheck } from "react-icons/fa"; import { IoIosWarning } from "react-icons/io"; import { MdCircle } from "react-icons/md"; import { Link } from "react-router-dom"; export default function Statusbar() { const { messages, addMessage, clearMessages } = useContext( StatusBarMessagesContext, )!; const stats = useAutoFrigateStats(); 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); useEffect(() => { clearMessages("stats"); potentialProblems.forEach((problem) => { addMessage( "stats", problem.text, problem.color, undefined, problem.relevantLink, ); }); }, [potentialProblems, addMessage, clearMessages]); const { payload: reindexState } = useEmbeddingsReindexProgress(); useEffect(() => { if (reindexState) { if (reindexState.status == "indexing") { clearMessages("embeddings-reindex"); addMessage( "embeddings-reindex", `Reindexing embeddings (${Math.floor((reindexState.processed_objects / reindexState.total_objects) * 100)}% complete)`, ); } if (reindexState.status === "completed") { clearMessages("embeddings-reindex"); } } }, [reindexState, addMessage, clearMessages]); 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); if (isNaN(gpu)) { return; } return ( {" "}
{gpuTitle} {gpu}%
); })}
{Object.entries(messages).length === 0 ? (
System is healthy
) : ( Object.entries(messages).map(([key, messageArray]) => (
{messageArray.map(({ text, color, link }: StatusMessage) => { const message = (
{text}
); if (link) { return ( {message} ); } else { return message; } })}
)) )}
); }