110 lines
3.0 KiB
TypeScript
110 lines
3.0 KiB
TypeScript
import Stack from "@mui/material/Stack";
|
|||
|
|
import Typography from "@mui/material/Typography";
|
||
|
|
import { BaseChart, Gauge } from "@/Components/v2/design-elements";
|
||
|
|
|
||
|
|
import { useTranslation } from "react-i18next";
|
||
|
|
import { getGbs, getFrequency } from "@/Utils/InfraUtils";
|
||
|
|
import { useTheme } from "@mui/material";
|
||
|
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||
|
|
import type { CheckSnapshot, GroupedCheck } from "@/Types/Check";
|
||
|
|
import type { HardwareCheckStats } from "@/Types/Monitor";
|
||
|
|
|
||
|
|
const InfraDetailGauge = ({
|
||
|
|
title,
|
||
|
|
progress,
|
||
|
|
upperLabel,
|
||
|
|
upperValue,
|
||
|
|
lowerLabel,
|
||
|
|
lowerValue,
|
||
|
|
}: {
|
||
|
|
title: string;
|
||
|
|
progress: number;
|
||
|
|
upperLabel?: string;
|
||
|
|
upperValue?: string | number;
|
||
|
|
lowerLabel?: string;
|
||
|
|
lowerValue?: string | number;
|
||
|
|
}) => {
|
||
|
|
const theme = useTheme();
|
||
|
|
return (
|
||
|
|
<BaseChart
|
||
|
|
icon={null}
|
||
|
|
title={title}
|
||
|
|
maxWidth={225}
|
||
|
|
>
|
||
|
|
<Stack
|
||
|
|
alignItems={"center"}
|
||
|
|
mb={theme.spacing(4)}
|
||
|
|
gap={theme.spacing(4)}
|
||
|
|
>
|
||
|
|
<Gauge progress={progress} />
|
||
|
|
</Stack>
|
||
|
|
<Stack
|
||
|
|
direction={"row"}
|
||
|
|
justifyContent={"space-between"}
|
||
|
|
>
|
||
|
|
<Typography>{upperLabel}</Typography>
|
||
|
|
<Typography>{upperValue}</Typography>
|
||
|
|
</Stack>
|
||
|
|
<Stack
|
||
|
|
direction={"row"}
|
||
|
|
justifyContent={"space-between"}
|
||
|
|
>
|
||
|
|
<Typography>{lowerLabel}</Typography>
|
||
|
|
<Typography>{lowerValue}</Typography>
|
||
|
|
</Stack>
|
||
|
|
</BaseChart>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export const InfraDetailsGauges = ({
|
||
|
|
snapshot,
|
||
|
|
}: {
|
||
|
|
snapshot: CheckSnapshot | undefined;
|
||
|
|
}) => {
|
||
|
|
const { t } = useTranslation();
|
||
|
|
const theme = useTheme();
|
||
|
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||
|
|
|
||
|
|
if (!snapshot) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<Stack
|
||
|
|
direction={isSmall ? "column" : "row"}
|
||
|
|
spacing={theme.spacing(8)}
|
||
|
|
alignItems={"center"}
|
||
|
|
>
|
||
|
|
<InfraDetailGauge
|
||
|
|
title={t("pages.infrastructure.gauges.memory.title")}
|
||
|
|
progress={(snapshot?.memory?.usage_percent || 0) * 100}
|
||
|
|
upperLabel={t("pages.infrastructure.gauges.memory.upperLabel")}
|
||
|
|
upperValue={getGbs(snapshot?.memory?.used_bytes || 0)}
|
||
|
|
lowerLabel={t("pages.infrastructure.gauges.memory.lowerLabel")}
|
||
|
|
lowerValue={getGbs(snapshot?.memory?.total_bytes || 0)}
|
||
|
|
/>
|
||
|
|
<InfraDetailGauge
|
||
|
|
title={t("pages.infrastructure.gauges.cpu.title")}
|
||
|
|
progress={(snapshot?.cpu?.usage_percent || 0) * 100}
|
||
|
|
upperLabel={t("pages.infrastructure.gauges.cpu.upperLabel")}
|
||
|
|
upperValue={getFrequency(snapshot?.cpu?.current_frequency || 0)}
|
||
|
|
lowerLabel={t("pages.infrastructure.gauges.cpu.lowerLabel")}
|
||
|
|
lowerValue={getFrequency(snapshot?.cpu?.frequency || 0)}
|
||
|
|
/>
|
||
|
|
{snapshot?.disk?.map((disk, idx) => {
|
||
|
|
return (
|
||
|
|
<InfraDetailGauge
|
||
|
|
key={disk?.device || 0 + idx}
|
||
|
|
// title={`Disk ${idx} usage`}
|
||
|
|
title={t("pages.infrastructure.gauges.disk.title", { idx })}
|
||
|
|
progress={(disk.usage_percent || 0) * 100}
|
||
|
|
upperLabel={t("pages.infrastructure.gauges.disk.upperLabel")}
|
||
|
|
upperValue={getGbs(disk?.used_bytes || 0)}
|
||
|
|
lowerLabel={t("pages.infrastructure.gauges.disk.lowerLabel")}
|
||
|
|
lowerValue={getGbs(disk?.total_bytes || 0)}
|
||
|
|
/>
|
||
|
|
);
|
||
|
|
})}
|
||
|
|
</Stack>
|
||
|
|
);
|
||
|
|
};
|