import { useWs } from "@/api/ws"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import Heading from "@/components/ui/heading"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { useMemo } from "react"; import { LuAlertCircle } from "react-icons/lu"; import useSWR from "swr"; type CameraStorage = { [key: string]: { bandwidth: number; usage: number; usage_percent: number; }; }; const emptyObject = Object.freeze({}); function Storage() { const { data: storage } = useSWR("recordings/storage"); const { value: { payload: stats }, } = useWs("stats", ""); const { data: initialStats } = useSWR("stats"); const { service } = stats || initialStats || emptyObject; const hasSeparateMedia = useMemo(() => { return ( service && service["storage"]["/media/frigate/recordings"]["total"] != service["storage"]["/media/frigate/clips"]["total"] ); }, [service]); const getUnitSize = (MB: number) => { if (isNaN(MB) || MB < 0) return "Invalid number"; if (MB < 1024) return `${MB} MiB`; if (MB < 1048576) return `${(MB / 1024).toFixed(2)} GiB`; return `${(MB / 1048576).toFixed(2)} TiB`; }; if (!service || !storage) { return ; } return ( <> Storage Overview
Data

Overview of total used storage and total capacity of the drives that hold the recordings and snapshots directories.

Location Used Total {hasSeparateMedia ? "Recordings" : "Recordings & Snapshots"} {getUnitSize( service["storage"]["/media/frigate/recordings"]["used"], )} {getUnitSize( service["storage"]["/media/frigate/recordings"]["total"], )} {hasSeparateMedia && ( Snapshots {getUnitSize( service["storage"]["/media/frigate/clips"]["used"], )} {getUnitSize( service["storage"]["/media/frigate/clips"]["total"], )} )}
Memory

Overview of used and total memory in frigate process.

Location Used Total /dev/shm {getUnitSize(service["storage"]["/dev/shm"]["used"])} {getUnitSize(service["storage"]["/dev/shm"]["total"])} /tmp/cache {getUnitSize(service["storage"]["/tmp/cache"]["used"])} {getUnitSize(service["storage"]["/tmp/cache"]["total"])}
Cameras

Overview of per-camera storage usage and bandwidth.

{Object.entries(storage).map(([name, camera]) => (
Usage Stream Bandwidth {Math.round(camera["usage_percent"] ?? 0)}% {camera["bandwidth"] ? `${getUnitSize(camera["bandwidth"])}/hr` : "Calculating..."}
))}
); } export default Storage;