Skip to content

Storage Graphs #10826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Suspense, lazy } from "react";
const Live = lazy(() => import("@/pages/Live"));
const Events = lazy(() => import("@/pages/Events"));
const Export = lazy(() => import("@/pages/Export"));
const Storage = lazy(() => import("@/pages/Storage"));
const SubmitPlus = lazy(() => import("@/pages/SubmitPlus"));
const ConfigEditor = lazy(() => import("@/pages/ConfigEditor"));
const System = lazy(() => import("@/pages/System"));
Expand All @@ -38,7 +37,6 @@ function App() {
<Route path="/" element={<Live />} />
<Route path="/events" element={<Events />} />
<Route path="/export" element={<Export />} />
<Route path="/storage" element={<Storage />} />
<Route path="/plus" element={<SubmitPlus />} />
<Route path="/system" element={<System />} />
<Route path="/settings" element={<Settings />} />
Expand Down
116 changes: 112 additions & 4 deletions web/src/components/graph/SystemGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { useCallback, useEffect, useMemo } from "react";
import Chart from "react-apexcharts";
import useSWR from "swr";

type SystemGraphProps = {
type ThresholdBarGraphProps = {
graphId: string;
name: string;
unit: string;
threshold: Threshold;
updateTimes: number[];
data: ApexAxisChartSeries;
};
export default function SystemGraph({
export function ThresholdBarGraph({
graphId,
name,
unit,
threshold,
updateTimes,
data,
}: SystemGraphProps) {
}: ThresholdBarGraphProps) {
const { data: config } = useSWR<FrigateConfig>("config", {
revalidateOnFocus: false,
});
Expand Down Expand Up @@ -88,7 +88,8 @@ export default function SystemGraph({
theme: systemTheme || theme,
},
xaxis: {
tickAmount: 6,
tickAmount: 4,
tickPlacement: "on",
labels: {
formatter: formatTime,
},
Expand Down Expand Up @@ -124,3 +125,110 @@ export default function SystemGraph({
</div>
);
}

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`;
};

type StorageGraphProps = {
graphId: string;
used: number;
total: number;
};
export function StorageGraph({ graphId, used, total }: StorageGraphProps) {
const { theme, systemTheme } = useTheme();

const options = useMemo(() => {
return {
chart: {
id: graphId,
background: (systemTheme || theme) == "dark" ? "#404040" : "#E5E5E5",
selection: {
enabled: false,
},
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
grid: {
show: false,
padding: {
bottom: -40,
top: -60,
left: -20,
right: 0,
},
},
legend: {
show: false,
},
dataLabels: {
enabled: false,
},
plotOptions: {
bar: {
horizontal: true,
},
},
tooltip: {
theme: systemTheme || theme,
},
xaxis: {
axisBorder: {
show: false,
},
axisTicks: {
show: false,
},
labels: {
show: false,
},
},
yaxis: {
show: false,
min: 0,
max: 100,
},
};
}, [graphId, systemTheme, theme]);

useEffect(() => {
ApexCharts.exec(graphId, "updateOptions", options, true, true);
}, [graphId, options]);

return (
<div className="w-full flex flex-col gap-2.5">
<div className="w-full flex justify-between items-center gap-1">
<div className="flex items-center gap-1">
<div className="text-xs text-primary-foreground">
{getUnitSize(used)}
</div>
<div className="text-xs text-primary-foreground">/</div>
<div className="text-xs text-muted-foreground">
{getUnitSize(total)}
</div>
</div>
<div className="text-xs text-primary-foreground">
{Math.round((used / total) * 100)}%
</div>
</div>
<div className="h-5 rounded-md overflow-hidden">
<Chart
type="bar"
options={options}
series={[
{ data: [{ x: "storage", y: Math.round((used / total) * 100) }] },
]}
height="100%"
/>
</div>
</div>
);
}
13 changes: 0 additions & 13 deletions web/src/components/settings/GeneralSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
LuActivity,
LuGithub,
LuHardDrive,
LuLifeBuoy,
LuList,
LuMoon,
Expand Down Expand Up @@ -138,18 +137,6 @@ export default function GeneralSettings({ className }: GeneralSettings) {
<DropdownMenuLabel>System</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup className={isDesktop ? "" : "flex flex-col"}>
<Link to="/storage">
<MenuItem
className={
isDesktop
? "cursor-pointer"
: "p-2 flex items-center text-sm"
}
>
<LuHardDrive className="mr-2 size-4" />
<span>Storage</span>
</MenuItem>
</Link>
<Link to="/system">
<MenuItem
className={
Expand Down
Loading