Skip to content

Commit

Permalink
Add camera bandwidth back in storage metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye217 committed Aug 30, 2024
1 parent cf77181 commit 24506fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 1 addition & 8 deletions web/src/components/graph/StorageGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { useTheme } from "@/context/theme-provider";
import { useEffect, useMemo } from "react";
import Chart from "react-apexcharts";

const getUnitSize = (MB: number) => {
if (MB === null || isNaN(MB) || MB < 0) return "Invalid number";
if (MB < 1024) return `${MB.toFixed(2)} MiB`;
if (MB < 1048576) return `${(MB / 1024).toFixed(2)} GiB`;

return `${(MB / 1048576).toFixed(2)} TiB`;
};
import { getUnitSize } from "@/utils/storageUtil";

type StorageGraphProps = {
graphId: string;
Expand Down
7 changes: 7 additions & 0 deletions web/src/utils/storageUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getUnitSize = (MB: number) => {
if (MB === null || isNaN(MB) || MB < 0) return "Invalid number";
if (MB < 1024) return `${MB.toFixed(2)} MiB`;
if (MB < 1048576) return `${(MB / 1024).toFixed(2)} GiB`;

return `${(MB / 1048576).toFixed(2)} TiB`;
};
8 changes: 7 additions & 1 deletion web/src/views/system/StorageMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StorageGraph } from "@/components/graph/StorageGraph";
import { FrigateStats } from "@/types/stats";
import { getUnitSize } from "@/utils/storageUtil";
import { useMemo } from "react";
import useSWR from "swr";

Expand Down Expand Up @@ -76,7 +77,12 @@ export default function StorageMetrics({
<div className="mt-4 grid grid-cols-1 gap-2 sm:grid-cols-3">
{Object.keys(cameraStorage).map((camera) => (
<div className="flex-col rounded-lg bg-background_alt p-2.5 md:rounded-2xl">
<div className="mb-5 capitalize">{camera.replaceAll("_", " ")}</div>
<div className="mb-5 flex flex-row items-center justify-between">
<div className="capitalize">{camera.replaceAll("_", " ")}</div>
<div className="text-xs text-muted-foreground">
{getUnitSize(cameraStorage[camera].bandwidth)} / hour
</div>
</div>
<StorageGraph
graphId={`${camera}-storage`}
used={cameraStorage[camera].usage}
Expand Down

0 comments on commit 24506fb

Please sign in to comment.