2024-08-30 15:56:55 +02:00
|
|
|
import { CombinedStorageGraph } from "@/components/graph/CombinedStorageGraph";
|
2024-05-29 20:05:39 +02:00
|
|
|
import { StorageGraph } from "@/components/graph/StorageGraph";
|
2024-04-04 18:24:23 +02:00
|
|
|
import { FrigateStats } from "@/types/stats";
|
|
|
|
import { useMemo } from "react";
|
2024-09-28 15:24:14 +02:00
|
|
|
import {
|
|
|
|
Popover,
|
|
|
|
PopoverContent,
|
|
|
|
PopoverTrigger,
|
|
|
|
} from "@/components/ui/popover";
|
2024-04-04 18:24:23 +02:00
|
|
|
import useSWR from "swr";
|
2024-09-28 15:24:14 +02:00
|
|
|
import { LuAlertCircle } from "react-icons/lu";
|
2024-04-04 18:24:23 +02:00
|
|
|
|
|
|
|
type CameraStorage = {
|
|
|
|
[key: string]: {
|
|
|
|
bandwidth: number;
|
|
|
|
usage: number;
|
|
|
|
usage_percent: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
type StorageMetricsProps = {
|
|
|
|
setLastUpdated: (last: number) => void;
|
|
|
|
};
|
|
|
|
export default function StorageMetrics({
|
|
|
|
setLastUpdated,
|
|
|
|
}: StorageMetricsProps) {
|
|
|
|
const { data: cameraStorage } = useSWR<CameraStorage>("recordings/storage");
|
|
|
|
const { data: stats } = useSWR<FrigateStats>("stats");
|
|
|
|
|
|
|
|
const totalStorage = useMemo(() => {
|
|
|
|
if (!cameraStorage || !stats) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const totalStorage = {
|
|
|
|
used: 0,
|
|
|
|
total: stats.service.storage["/media/frigate/recordings"]["total"],
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.values(cameraStorage).forEach(
|
|
|
|
(cam) => (totalStorage.used += cam.usage),
|
|
|
|
);
|
|
|
|
setLastUpdated(Date.now() / 1000);
|
|
|
|
return totalStorage;
|
|
|
|
}, [cameraStorage, stats, setLastUpdated]);
|
|
|
|
|
|
|
|
if (!cameraStorage || !stats || !totalStorage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-06-03 20:43:30 +02:00
|
|
|
<div className="scrollbar-container mt-4 flex size-full flex-col overflow-y-auto">
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="text-sm font-medium text-muted-foreground">Overview</div>
|
|
|
|
<div className="mt-4 grid grid-cols-1 gap-2 sm:grid-cols-3">
|
|
|
|
<div className="flex-col rounded-lg bg-background_alt p-2.5 md:rounded-2xl">
|
2024-09-28 15:24:14 +02:00
|
|
|
<div className="mb-5 flex flex-row items-center justify-between">
|
|
|
|
Recordings
|
|
|
|
<Popover>
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
<button
|
|
|
|
className="focus:outline-none"
|
|
|
|
aria-label="Unused Storage Information"
|
|
|
|
>
|
|
|
|
<LuAlertCircle
|
|
|
|
className="size-5"
|
|
|
|
aria-label="Unused Storage Information"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<PopoverContent className="w-80">
|
|
|
|
<div className="space-y-2">
|
|
|
|
This value represents the total storage used by the recordings
|
|
|
|
in Frigate's database. Frigate does not track storage usage
|
|
|
|
for all files on your disk.
|
|
|
|
</div>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
</div>
|
2024-04-04 18:24:23 +02:00
|
|
|
<StorageGraph
|
|
|
|
graphId="general-recordings"
|
|
|
|
used={totalStorage.used}
|
|
|
|
total={totalStorage.total}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="flex-col rounded-lg bg-background_alt p-2.5 md:rounded-2xl">
|
2024-04-04 18:24:23 +02:00
|
|
|
<div className="mb-5">/tmp/cache</div>
|
|
|
|
<StorageGraph
|
|
|
|
graphId="general-cache"
|
|
|
|
used={stats.service.storage["/tmp/cache"]["used"]}
|
|
|
|
total={stats.service.storage["/tmp/cache"]["total"]}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="flex-col rounded-lg bg-background_alt p-2.5 md:rounded-2xl">
|
2024-04-04 18:24:23 +02:00
|
|
|
<div className="mb-5">/dev/shm</div>
|
|
|
|
<StorageGraph
|
|
|
|
graphId="general-shared-memory"
|
|
|
|
used={stats.service.storage["/dev/shm"]["used"]}
|
|
|
|
total={stats.service.storage["/dev/shm"]["total"]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-05-14 17:06:44 +02:00
|
|
|
<div className="mt-4 text-sm font-medium text-muted-foreground">
|
2024-04-04 18:24:23 +02:00
|
|
|
Camera Storage
|
|
|
|
</div>
|
2024-08-30 15:56:55 +02:00
|
|
|
<div className="mt-4 bg-background_alt p-2.5 md:rounded-2xl">
|
|
|
|
<CombinedStorageGraph
|
|
|
|
graphId={`single-storage`}
|
|
|
|
cameraStorage={cameraStorage}
|
|
|
|
totalStorage={totalStorage}
|
|
|
|
/>
|
2024-04-04 18:24:23 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|