Files
Checkmate/client/src/Pages/Logs/components/StatGauges.tsx
T

88 lines
2.7 KiB
TypeScript
Raw Normal View History

2026-04-25 23:27:35 -04:00
import Box from "@mui/material/Box";
2026-02-20 18:13:39 +00:00
import { DetailGauge } from "@/Components/design-elements";
2026-02-06 18:46:06 +00:00
2026-02-06 19:25:53 +00:00
import { getPercentage, formatPercentageFromWhole } from "@/Utils/FormatUtils";
2026-02-06 18:46:06 +00:00
import prettyBytes from "pretty-bytes";
import { useTranslation } from "react-i18next";
import { useTheme } from "@mui/material";
import type { Diagnostics } from "@/Types/Diagnostics";
interface StatGaugesProps {
diagnostics: Diagnostics | null;
}
2026-04-25 23:27:35 -04:00
const PLACEHOLDER = "—";
2026-02-06 18:46:06 +00:00
export const StatGauges = ({ diagnostics }: StatGaugesProps) => {
const theme = useTheme();
const { t } = useTranslation();
2026-04-25 23:27:35 -04:00
const heapTotalSize = diagnostics
? getPercentage(
diagnostics.v8HeapStats?.totalHeapSizeBytes,
diagnostics.v8HeapStats?.heapSizeLimitBytes
)
: 0;
const heapUsedSize = diagnostics
? getPercentage(
diagnostics.v8HeapStats?.usedHeapSizeBytes,
diagnostics.v8HeapStats?.heapSizeLimitBytes
)
: 0;
const actualHeapUsed = diagnostics
? getPercentage(
diagnostics.v8HeapStats?.usedHeapSizeBytes,
diagnostics.v8HeapStats?.totalHeapSizeBytes
)
: 0;
const cpuUsage = diagnostics?.cpuUsage?.usagePercentage ?? 0;
2026-02-06 18:46:06 +00:00
2026-04-25 23:27:35 -04:00
const fmt = (n: number) => (diagnostics ? formatPercentageFromWhole(n) : PLACEHOLDER);
const bytes = (n: number | undefined) =>
diagnostics ? prettyBytes(n ?? 0) : PLACEHOLDER;
2026-02-06 18:46:06 +00:00
return (
2026-04-25 23:27:35 -04:00
<Box
sx={{
display: "grid",
gridTemplateColumns: { xs: "1fr", md: "repeat(4, 1fr)" },
gap: theme.spacing(8),
"& > *": { width: "100% !important" },
}}
2026-02-06 18:46:06 +00:00
>
<DetailGauge
2026-04-25 23:27:35 -04:00
maxWidth={9999}
2026-02-06 18:46:06 +00:00
title={t("pages.logs.diagnostics.gauges.heapAllocation")}
progress={heapTotalSize}
2026-04-25 23:27:35 -04:00
upperValue={fmt(heapTotalSize)}
2026-02-06 18:46:06 +00:00
lowerLabel={t("pages.logs.diagnostics.gauges.total")}
2026-04-25 23:27:35 -04:00
lowerValue={bytes(diagnostics?.v8HeapStats?.heapSizeLimitBytes)}
2026-02-06 18:46:06 +00:00
/>
<DetailGauge
2026-04-25 23:27:35 -04:00
maxWidth={9999}
2026-02-06 18:46:06 +00:00
title={t("pages.logs.diagnostics.gauges.heapUsage")}
progress={heapUsedSize}
upperLabel={t("pages.logs.diagnostics.gauges.availableMemoryPercentage")}
2026-04-25 23:27:35 -04:00
upperValue={fmt(heapUsedSize)}
2026-02-06 18:46:06 +00:00
lowerLabel={t("pages.logs.diagnostics.gauges.used")}
2026-04-25 23:27:35 -04:00
lowerValue={bytes(diagnostics?.v8HeapStats?.usedHeapSizeBytes)}
2026-02-06 18:46:06 +00:00
/>
<DetailGauge
2026-04-25 23:27:35 -04:00
maxWidth={9999}
2026-02-06 18:46:06 +00:00
title={t("pages.logs.diagnostics.gauges.heapUtilization")}
progress={actualHeapUsed}
upperLabel={t("pages.logs.diagnostics.gauges.allocatedPercentage")}
2026-04-25 23:27:35 -04:00
upperValue={fmt(actualHeapUsed)}
2026-02-06 18:46:06 +00:00
lowerLabel={t("pages.logs.diagnostics.gauges.total")}
2026-04-25 23:27:35 -04:00
lowerValue={bytes(diagnostics?.v8HeapStats?.usedHeapSizeBytes)}
2026-02-06 18:46:06 +00:00
/>
<DetailGauge
2026-04-25 23:27:35 -04:00
maxWidth={9999}
2026-02-06 18:46:06 +00:00
title={t("pages.logs.diagnostics.gauges.instantCpuUsage")}
2026-04-25 23:27:35 -04:00
progress={cpuUsage}
2026-02-06 18:46:06 +00:00
upperLabel={t("pages.logs.diagnostics.gauges.usedSPercentage")}
2026-04-25 23:27:35 -04:00
upperValue={fmt(cpuUsage)}
2026-02-06 18:46:06 +00:00
/>
2026-04-25 23:27:35 -04:00
</Box>
2026-02-06 18:46:06 +00:00
);
};