2024-02-22 03:27:02 +01:00
|
|
|
import { useFrigateStats } from "@/api/ws";
|
2024-03-30 19:45:13 +01:00
|
|
|
import useStats from "@/hooks/use-stats";
|
2024-02-22 03:27:02 +01:00
|
|
|
import { FrigateStats } from "@/types/stats";
|
|
|
|
import { useMemo } from "react";
|
2024-03-30 19:45:13 +01:00
|
|
|
import { IoIosWarning } from "react-icons/io";
|
2024-02-22 03:27:02 +01:00
|
|
|
import { MdCircle } from "react-icons/md";
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
2024-02-28 23:23:56 +01:00
|
|
|
export default function Statusbar() {
|
2024-02-22 03:27:02 +01:00
|
|
|
const { data: initialStats } = useSWR<FrigateStats>("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]);
|
|
|
|
|
2024-03-30 19:45:13 +01:00
|
|
|
const { potentialProblems } = useStats(stats);
|
2024-02-22 03:27:02 +01:00
|
|
|
|
2024-03-30 19:45:13 +01:00
|
|
|
return (
|
2024-04-10 00:49:14 +02:00
|
|
|
<div className="absolute left-0 bottom-0 right-0 w-full h-8 flex justify-between items-center px-4 bg-background_alt z-10 dark:text-secondary-foreground border-t border-secondary-highlight">
|
2024-03-30 19:45:13 +01:00
|
|
|
<div className="h-full flex items-center gap-2">
|
|
|
|
{cpuPercent && (
|
|
|
|
<div className="flex items-center text-sm gap-2">
|
2024-02-22 03:27:02 +01:00
|
|
|
<MdCircle
|
2024-03-30 19:45:13 +01:00
|
|
|
className={`size-2 ${
|
|
|
|
cpuPercent < 50
|
|
|
|
? "text-success"
|
|
|
|
: cpuPercent < 80
|
2024-02-22 03:27:02 +01:00
|
|
|
? "text-orange-400"
|
|
|
|
: "text-danger"
|
|
|
|
}`}
|
|
|
|
/>
|
2024-03-30 19:45:13 +01:00
|
|
|
CPU {cpuPercent}%
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{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 (
|
|
|
|
<div key={gpuTitle} className="flex items-center text-sm gap-2">
|
|
|
|
<MdCircle
|
|
|
|
className={`size-2 ${
|
|
|
|
gpu < 50
|
|
|
|
? "text-success"
|
|
|
|
: gpu < 80
|
|
|
|
? "text-orange-400"
|
|
|
|
: "text-danger"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
{gpuTitle} {gpu}%
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<div className="h-full flex items-center gap-2">
|
|
|
|
{potentialProblems.map((prob) => (
|
2024-04-03 18:56:04 +02:00
|
|
|
<div
|
|
|
|
key={prob.text}
|
|
|
|
className="flex items-center text-sm gap-2 capitalize"
|
|
|
|
>
|
2024-03-30 19:45:13 +01:00
|
|
|
<IoIosWarning className={`size-5 ${prob.color}`} />
|
|
|
|
{prob.text}
|
2024-02-22 03:27:02 +01:00
|
|
|
</div>
|
2024-03-30 19:45:13 +01:00
|
|
|
))}
|
|
|
|
</div>
|
2024-02-22 03:27:02 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|