Files
Checkmate/client/src/Pages/Logs/Diagnostics/components/gauges/index.jsx
T

109 lines
2.5 KiB
React
Raw Normal View History

2025-07-10 16:08:04 -07:00
import Stack from "@mui/material/Stack";
import Gauge from "../../../../../Components/Charts/CustomGauge";
import Typography from "@mui/material/Typography";
// Utils
import { useTheme } from "@emotion/react";
import PropTypes from "prop-types";
2025-07-11 11:23:50 -07:00
import { getPercentage } from "../../utils/utils";
import { useTranslation } from "react-i18next";
2025-07-10 16:08:04 -07:00
const GaugeBox = ({ title, subtitle, children }) => {
const theme = useTheme();
return (
<Stack
alignItems="center"
p={theme.spacing(2)}
2025-07-11 11:23:50 -07:00
maxWidth={150}
width={150}
2025-07-10 16:08:04 -07:00
>
{children}
<Typography variant="h2">{title}</Typography>
<Typography variant="body2">{subtitle}</Typography>
</Stack>
);
};
2025-07-11 11:23:50 -07:00
GaugeBox.propTypes = {
title: PropTypes.string.isRequired,
subtitle: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
};
const Gauges = ({ diagnostics, isLoading }) => {
2025-07-10 16:08:04 -07:00
const heapTotalSize = getPercentage(
2025-07-11 11:23:50 -07:00
diagnostics?.v8HeapStats?.totalHeapSizeBytes,
diagnostics?.v8HeapStats?.heapSizeLimitBytes
2025-07-10 16:08:04 -07:00
);
const heapUsedSize = getPercentage(
2025-07-11 11:23:50 -07:00
diagnostics?.v8HeapStats?.usedHeapSizeBytes,
diagnostics?.v8HeapStats?.heapSizeLimitBytes
2025-07-10 16:08:04 -07:00
);
const actualHeapUsed = getPercentage(
2025-07-11 11:23:50 -07:00
diagnostics?.v8HeapStats?.usedHeapSizeBytes,
diagnostics?.v8HeapStats?.totalHeapSizeBytes
2025-07-10 16:08:04 -07:00
);
2025-07-11 11:23:50 -07:00
2025-07-10 16:08:04 -07:00
const theme = useTheme();
2025-07-11 11:23:50 -07:00
const { t } = useTranslation();
2025-07-10 16:08:04 -07:00
return (
<Stack
direction="row"
spacing={theme.spacing(4)}
2025-07-11 11:23:50 -07:00
flexWrap="wrap"
2025-07-10 16:08:04 -07:00
>
<GaugeBox
2025-07-11 11:23:50 -07:00
title={t("diagnosticsPage.gauges.heapAllocationTitle")}
subtitle={t("diagnosticsPage.gauges.heapAllocationSubtitle")}
>
<Gauge
isLoading={isLoading}
radius={100}
progress={heapTotalSize}
/>
</GaugeBox>
<GaugeBox
title={t("diagnosticsPage.gauges.heapUsageTitle")}
subtitle={t("diagnosticsPage.gauges.heapUsageSubtitle")}
2025-07-10 16:08:04 -07:00
>
2025-07-11 11:23:50 -07:00
<Gauge
isLoading={isLoading}
radius={100}
progress={heapUsedSize}
/>
2025-07-10 16:08:04 -07:00
</GaugeBox>
<GaugeBox
2025-07-11 11:23:50 -07:00
title={t("diagnosticsPage.gauges.heapUtilizationTitle")}
subtitle={t("diagnosticsPage.gauges.heapUtilizationSubtitle")}
2025-07-10 16:08:04 -07:00
>
2025-07-11 11:23:50 -07:00
<Gauge
isLoading={isLoading}
radius={100}
progress={actualHeapUsed}
/>
2025-07-10 16:08:04 -07:00
</GaugeBox>
<GaugeBox
2025-07-11 11:23:50 -07:00
title={t("diagnosticsPage.gauges.instantCpuUsageTitle")}
subtitle={t("diagnosticsPage.gauges.instantCpuUsageSubtitle")}
2025-07-10 16:08:04 -07:00
>
2025-07-11 11:23:50 -07:00
<Gauge
isLoading={isLoading}
radius={100}
progress={diagnostics?.cpuUsage?.usagePercentage}
precision={2}
/>
2025-07-10 16:08:04 -07:00
</GaugeBox>
</Stack>
);
};
Gauges.propTypes = {
2025-07-11 11:23:50 -07:00
diagnostics: PropTypes.object,
isLoading: PropTypes.bool,
2025-07-10 16:08:04 -07:00
};
export default Gauges;