Merge pull request #1678 from bluewave-labs/fix/fe/infra-details-refactor
fix: fe/infra details refactor
This commit is contained in:
21 files changed
+839
-809
No files matched your search
@@ -4,15 +4,21 @@ import SkeletonLayout from "./skeleton";
|
|||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
const StatusBoxes = ({ shouldRender, children }) => {
|
const StatusBoxes = ({ shouldRender, flexWrap = "nowrap", children }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
if (!shouldRender) {
|
if (!shouldRender) {
|
||||||
return <SkeletonLayout numBoxes={children?.length ?? 1} />;
|
return (
|
||||||
|
<SkeletonLayout
|
||||||
|
numBoxes={children?.length ?? 1}
|
||||||
|
flexWrap={flexWrap}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
flexWrap={flexWrap}
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
import { Stack, Skeleton } from "@mui/material";
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
const SkeletonLayout = ({ numBoxes }) => {
|
const SkeletonLayout = ({ numBoxes, flexWrap }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
flexWrap={flexWrap}
|
||||||
gap={theme.spacing(4)}
|
gap={theme.spacing(4)}
|
||||||
mt={theme.spacing(4)}
|
mt={theme.spacing(4)}
|
||||||
>
|
>
|
||||||
{Array.from({ length: numBoxes }).map((_, index) => {
|
{Array.from({ length: numBoxes }).map((_, index) => {
|
||||||
const width = `${100 / numBoxes}%`;
|
const width = `${200 / numBoxes}%`;
|
||||||
return (
|
return (
|
||||||
<Skeleton
|
<Skeleton
|
||||||
variant="rounded"
|
variant="rounded"
|
||||||
width={width}
|
width={width}
|
||||||
height={50}
|
height={100}
|
||||||
key={index}
|
key={index}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -25,6 +26,7 @@ const SkeletonLayout = ({ numBoxes }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SkeletonLayout.propTypes = {
|
SkeletonLayout.propTypes = {
|
||||||
|
flexWrap: PropTypes.string,
|
||||||
numBoxes: PropTypes.number,
|
numBoxes: PropTypes.number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ CustomThreshold.propTypes = {
|
|||||||
fieldName: PropTypes.string,
|
fieldName: PropTypes.string,
|
||||||
fieldValue: PropTypes.string.isRequired,
|
fieldValue: PropTypes.string.isRequired,
|
||||||
onFieldChange: PropTypes.func.isRequired,
|
onFieldChange: PropTypes.func.isRequired,
|
||||||
onFieldBlur: PropTypes.func.isRequired,
|
onFieldBlur: PropTypes.func,
|
||||||
alertUnit: PropTypes.string.isRequired,
|
alertUnit: PropTypes.string.isRequired,
|
||||||
infrastructureMonitor: PropTypes.object.isRequired,
|
infrastructureMonitor: PropTypes.object.isRequired,
|
||||||
errors: PropTypes.object.isRequired,
|
errors: PropTypes.object.isRequired,
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Components
|
||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import BaseContainer from "../BaseContainer";
|
||||||
|
import AreaChart from "../../../../../Components/Charts/AreaChart";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useHardwareUtils } from "../../Hooks/useHardwareUtils";
|
||||||
|
const InfraAreaChart = ({ config }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { getDimensions } = useHardwareUtils();
|
||||||
|
return (
|
||||||
|
<BaseContainer>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
padding={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
{config.heading}
|
||||||
|
</Typography>
|
||||||
|
<AreaChart
|
||||||
|
height={getDimensions().areaChartHeight}
|
||||||
|
data={config.data}
|
||||||
|
dataKeys={config.dataKeys}
|
||||||
|
xKey="_id"
|
||||||
|
yDomain={config.yDomain}
|
||||||
|
customTooltip={config.toolTip}
|
||||||
|
xTick={config.xTick}
|
||||||
|
yTick={config.yTick}
|
||||||
|
strokeColor={config.strokeColor}
|
||||||
|
gradient={true}
|
||||||
|
gradientStartColor={config.gradientStartColor}
|
||||||
|
gradientEndColor="#ffffff"
|
||||||
|
/>
|
||||||
|
</BaseContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InfraAreaChart;
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import InfraAreaChart from "./InfraAreaChart";
|
||||||
|
import SkeletonLayout from "./skeleton";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import {
|
||||||
|
PercentTick,
|
||||||
|
TzTick,
|
||||||
|
InfrastructureTooltip,
|
||||||
|
TemperatureTooltip,
|
||||||
|
} from "../../../../../Components/Charts/Utils/chartUtils";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useHardwareUtils } from "../../Hooks/useHardwareUtils";
|
||||||
|
const AreaChartBoxes = ({ shouldRender, monitor, dateRange }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { buildTemps } = useHardwareUtils();
|
||||||
|
|
||||||
|
if (!shouldRender) {
|
||||||
|
return <SkeletonLayout />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { stats } = monitor ?? {};
|
||||||
|
const { checks } = stats;
|
||||||
|
|
||||||
|
let latestCheck = checks[0];
|
||||||
|
const { temps, tempKeys } = buildTemps(checks);
|
||||||
|
|
||||||
|
const configs = [
|
||||||
|
{
|
||||||
|
type: "memory",
|
||||||
|
data: checks,
|
||||||
|
dataKeys: ["avgMemoryUsage"],
|
||||||
|
heading: "Memory usage",
|
||||||
|
strokeColor: theme.palette.accent.main, // CAIO_REVIEW
|
||||||
|
gradientStartColor: theme.palette.accent.main, // CAIO_REVIEW
|
||||||
|
yLabel: "Memory usage",
|
||||||
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.primary.main}
|
||||||
|
yKey={"avgMemoryUsage"}
|
||||||
|
yLabel={"Memory usage"}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "cpu",
|
||||||
|
data: checks,
|
||||||
|
dataKeys: ["avgCpuUsage"],
|
||||||
|
heading: "CPU usage",
|
||||||
|
strokeColor: theme.palette.success.main,
|
||||||
|
gradientStartColor: theme.palette.success.main,
|
||||||
|
yLabel: "CPU usage",
|
||||||
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.success.main}
|
||||||
|
yKey={"avgCpuUsage"}
|
||||||
|
yLabel={"CPU usage"}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "temperature",
|
||||||
|
data: temps,
|
||||||
|
dataKeys: tempKeys,
|
||||||
|
strokeColor: theme.palette.error.main,
|
||||||
|
gradientStartColor: theme.palette.error.main,
|
||||||
|
heading: "CPU Temperature",
|
||||||
|
yLabel: "Temperature",
|
||||||
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
|
yDomain: [
|
||||||
|
0,
|
||||||
|
Math.max(Math.max(...temps.flatMap((t) => tempKeys.map((k) => t[k]))) * 1.1, 200),
|
||||||
|
],
|
||||||
|
toolTip: (
|
||||||
|
<TemperatureTooltip
|
||||||
|
keys={tempKeys}
|
||||||
|
dotColor={theme.palette.error.main}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
...(latestCheck?.disks?.map((disk, idx) => ({
|
||||||
|
type: "disk",
|
||||||
|
data: checks,
|
||||||
|
diskIndex: idx,
|
||||||
|
dataKeys: [`disks[${idx}].usagePercent`],
|
||||||
|
heading: `Disk${idx} usage`,
|
||||||
|
strokeColor: theme.palette.warning.main,
|
||||||
|
gradientStartColor: theme.palette.warning.main,
|
||||||
|
yLabel: "Disk Usage",
|
||||||
|
yDomain: [0, 1],
|
||||||
|
yTick: <PercentTick />,
|
||||||
|
xTick: <TzTick dateRange={dateRange} />,
|
||||||
|
toolTip: (
|
||||||
|
<InfrastructureTooltip
|
||||||
|
dotColor={theme.palette.warning.main}
|
||||||
|
yKey={`disks.usagePercent`}
|
||||||
|
yLabel={"Disc usage"}
|
||||||
|
yIdx={idx}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
})) || []),
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction={"row"}
|
||||||
|
// height={chartContainerHeight} // FE team HELP! Possibly no longer needed?
|
||||||
|
gap={theme.spacing(8)} // FE team HELP!
|
||||||
|
flexWrap="wrap" // //FE team HELP! Better way to do this?
|
||||||
|
sx={{
|
||||||
|
"& > *": {
|
||||||
|
flexBasis: `calc(50% - ${theme.spacing(8)})`,
|
||||||
|
maxWidth: `calc(50% - ${theme.spacing(8)})`,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{configs.map((config) => (
|
||||||
|
<InfraAreaChart
|
||||||
|
key={`${config.type}-${config.diskIndex ?? ""}`}
|
||||||
|
config={config}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AreaChartBoxes;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
flexWrap="wrap"
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
<Skeleton
|
||||||
|
height={"33vh"}
|
||||||
|
sx={{
|
||||||
|
flex: 1,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
height={"33vh"}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Renders a base box with consistent styling
|
||||||
|
* @param {Object} props - Component properties
|
||||||
|
* @param {React.ReactNode} props.children - Child components to render inside the box
|
||||||
|
* @param {Object} props.sx - Additional styling for the box
|
||||||
|
* @returns {React.ReactElement} Styled box component
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import { Box } from "@mui/material";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useHardwareUtils } from "../../Hooks/useHardwareUtils";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const BaseContainer = ({ children, sx = {} }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { getDimensions } = useHardwareUtils();
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
padding: `${theme.spacing(getDimensions().baseBoxPaddingVertical)} ${theme.spacing(getDimensions().baseBoxPaddingHorizontal)}`,
|
||||||
|
minWidth: 200,
|
||||||
|
width: 225,
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
border: 1,
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
|
...sx,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
BaseContainer.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
sx: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BaseContainer;
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Components
|
||||||
|
import CustomGauge from "../../../../../Components/Charts/CustomGauge";
|
||||||
|
import BaseContainer from "../BaseContainer";
|
||||||
|
import { Stack, Typography, Box } from "@mui/material";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const Gauge = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseContainer>
|
||||||
|
<Stack
|
||||||
|
direction="column"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
alignItems="center"
|
||||||
|
>
|
||||||
|
<CustomGauge
|
||||||
|
progress={value}
|
||||||
|
radius={100}
|
||||||
|
color={theme.palette.primary.main}
|
||||||
|
/>
|
||||||
|
<Typography component="h2">{heading}</Typography>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
borderTop: `1px solid ${theme.palette.primary.lowContrast}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
justifyContent={"space-between"}
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Typography>{metricOne}</Typography>
|
||||||
|
<Typography>{valueOne}</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
justifyContent={"space-between"}
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Typography>{metricTwo}</Typography>
|
||||||
|
<Typography>{valueTwo}</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</BaseContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Gauge.propTypes = {
|
||||||
|
value: PropTypes.number,
|
||||||
|
heading: PropTypes.string,
|
||||||
|
metricOne: PropTypes.string,
|
||||||
|
valueOne: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
|
metricTwo: PropTypes.string,
|
||||||
|
valueTwo: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Gauge;
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import Gauge from "./Gauge";
|
||||||
|
import SkeletonLayout from "./skeleton";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useHardwareUtils } from "../../Hooks/useHardwareUtils";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
const Gauges = ({ shouldRender, monitor }) => {
|
||||||
|
const { decimalToPercentage, formatBytes } = useHardwareUtils();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
if (!shouldRender) {
|
||||||
|
return <SkeletonLayout />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { stats } = monitor ?? {};
|
||||||
|
let latestCheck = stats?.aggregateData?.latestCheck;
|
||||||
|
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? 0;
|
||||||
|
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? 0;
|
||||||
|
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
||||||
|
const cpuUsagePercent = latestCheck?.cpu?.usage_percent ?? 0;
|
||||||
|
const cpuPhysicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
||||||
|
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
||||||
|
|
||||||
|
const gauges = [
|
||||||
|
{
|
||||||
|
type: "memory",
|
||||||
|
value: decimalToPercentage(memoryUsagePercent),
|
||||||
|
heading: "Memory usage",
|
||||||
|
metricOne: "Used",
|
||||||
|
valueOne: formatBytes(memoryUsedBytes, true),
|
||||||
|
metricTwo: "Total",
|
||||||
|
valueTwo: formatBytes(memoryTotalBytes, true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "cpu",
|
||||||
|
value: decimalToPercentage(cpuUsagePercent),
|
||||||
|
heading: "CPU usage",
|
||||||
|
metricOne: "Cores",
|
||||||
|
valueOne: cpuPhysicalCores ?? 0,
|
||||||
|
metricTwo: "Frequency",
|
||||||
|
valueTwo: `${(cpuFrequency / 1000).toFixed(2)} Ghz`,
|
||||||
|
},
|
||||||
|
...(latestCheck?.disk ?? []).map((disk, idx) => ({
|
||||||
|
type: "disk",
|
||||||
|
diskIndex: idx,
|
||||||
|
value: decimalToPercentage(disk.usage_percent),
|
||||||
|
heading: `Disk${idx} usage`,
|
||||||
|
metricOne: "Used",
|
||||||
|
valueOne: formatBytes(disk.total_bytes - disk.free_bytes, true),
|
||||||
|
metricTwo: "Total",
|
||||||
|
valueTwo: formatBytes(disk.total_bytes, true),
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
{gauges.map((gauge) => {
|
||||||
|
return (
|
||||||
|
<Gauge
|
||||||
|
key={`${gauge.type}-${gauge.diskIndex ?? ""}`}
|
||||||
|
value={gauge.value}
|
||||||
|
heading={gauge.heading}
|
||||||
|
metricOne={gauge.metricOne}
|
||||||
|
valueOne={gauge.valueOne}
|
||||||
|
metricTwo={gauge.metricTwo}
|
||||||
|
valueTwo={gauge.valueTwo}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Gauges;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
{Array.from({ length: 3 }).map((_, idx) => {
|
||||||
|
return (
|
||||||
|
<Skeleton
|
||||||
|
key={`gauge-${idx}`}
|
||||||
|
variant="rectangular"
|
||||||
|
width={200}
|
||||||
|
height={200}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack, Typography } from "@mui/material";
|
||||||
|
import StatusBoxes from "../../../../../Components/StatusBoxes";
|
||||||
|
import StatBox from "../../../../../Components/StatBox";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import useUtils from "../../../../../Pages/Uptime/Monitors/Hooks/useUtils";
|
||||||
|
import { useHardwareUtils } from "../../Hooks/useHardwareUtils";
|
||||||
|
|
||||||
|
const InfraStatBoxes = ({ shouldRender, monitor }) => {
|
||||||
|
// Utils
|
||||||
|
const { formatBytes } = useHardwareUtils();
|
||||||
|
const { statusStyles, determineState } = useUtils();
|
||||||
|
|
||||||
|
const { stats, uptimePercentage } = monitor ?? {};
|
||||||
|
const latestCheck = stats?.aggregateData?.latestCheck;
|
||||||
|
|
||||||
|
// Get data from latest check
|
||||||
|
const physicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
||||||
|
const logicalCores = latestCheck?.cpu?.logical_core ?? 0;
|
||||||
|
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
||||||
|
const cpuTemperature =
|
||||||
|
latestCheck?.cpu?.temperature?.length > 0
|
||||||
|
? latestCheck.cpu.temperature.reduce((acc, curr) => acc + curr, 0) /
|
||||||
|
latestCheck.cpu.temperature.length
|
||||||
|
: 0;
|
||||||
|
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
||||||
|
const diskTotalBytes = latestCheck?.disk[0]?.total_bytes ?? 0;
|
||||||
|
const os = latestCheck?.host?.os ?? undefined;
|
||||||
|
const platform = latestCheck?.host?.platform ?? undefined;
|
||||||
|
const osPlatform =
|
||||||
|
typeof os === "undefined" && typeof platform === "undefined"
|
||||||
|
? undefined
|
||||||
|
: `${os} ${platform}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StatusBoxes
|
||||||
|
shouldRender={shouldRender}
|
||||||
|
flexWrap="wrap"
|
||||||
|
>
|
||||||
|
<StatBox
|
||||||
|
sx={statusStyles[determineState(monitor)]}
|
||||||
|
heading="Status"
|
||||||
|
subHeading={determineState(monitor)}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="CPU (Physical)"
|
||||||
|
subHeading={
|
||||||
|
<>
|
||||||
|
{physicalCores}
|
||||||
|
<Typography component="span">cores</Typography>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
key={2}
|
||||||
|
heading="CPU (Logical)"
|
||||||
|
subHeading={
|
||||||
|
<>
|
||||||
|
{logicalCores}
|
||||||
|
<Typography component="span">cores</Typography>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="CPU Frequency"
|
||||||
|
subHeading={
|
||||||
|
<>
|
||||||
|
{(cpuFrequency / 1000).toFixed(2)}
|
||||||
|
<Typography component="span">Ghz</Typography>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="Average CPU Temperature"
|
||||||
|
subHeading={
|
||||||
|
<>
|
||||||
|
{cpuTemperature.toFixed(2)}
|
||||||
|
<Typography component="span">C</Typography>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="Memory"
|
||||||
|
subHeading={formatBytes(memoryTotalBytes)}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="Disk"
|
||||||
|
subHeading={formatBytes(diskTotalBytes)}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
heading="Uptime"
|
||||||
|
subHeading={
|
||||||
|
<>
|
||||||
|
{(uptimePercentage * 100).toFixed(2)}
|
||||||
|
<Typography component="span">%</Typography>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<StatBox
|
||||||
|
key={8}
|
||||||
|
heading="OS"
|
||||||
|
subHeading={osPlatform}
|
||||||
|
/>
|
||||||
|
</StatusBoxes>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InfraStatBoxes;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { networkService } from "../../../../main";
|
||||||
|
|
||||||
|
const useHardwareMonitorsFetch = ({ monitorId, dateRange }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
|
||||||
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
const response = await networkService.getHardwareDetailsByMonitorId({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorId: monitorId,
|
||||||
|
dateRange: dateRange,
|
||||||
|
});
|
||||||
|
response.data.data;
|
||||||
|
setMonitor(response.data.data);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
|
}, [monitorId, dateRange, authToken]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isLoading,
|
||||||
|
networkError,
|
||||||
|
monitor,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useHardwareMonitorsFetch };
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const BASE_BOX_PADDING_VERTICAL = 4;
|
||||||
|
const BASE_BOX_PADDING_HORIZONTAL = 8;
|
||||||
|
const TYPOGRAPHY_PADDING = 8;
|
||||||
|
const CHART_CONTAINER_HEIGHT = 300;
|
||||||
|
|
||||||
|
const useHardwareUtils = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const getDimensions = () => {
|
||||||
|
const totalTypographyPadding = parseInt(theme.spacing(TYPOGRAPHY_PADDING), 10) * 2;
|
||||||
|
const totalChartContainerPadding =
|
||||||
|
parseInt(theme.spacing(BASE_BOX_PADDING_VERTICAL), 10) * 2;
|
||||||
|
return {
|
||||||
|
baseBoxPaddingVertical: BASE_BOX_PADDING_VERTICAL,
|
||||||
|
baseBoxPaddingHorizontal: BASE_BOX_PADDING_HORIZONTAL,
|
||||||
|
totalContainerPadding: parseInt(theme.spacing(BASE_BOX_PADDING_VERTICAL), 10) * 2,
|
||||||
|
areaChartHeight:
|
||||||
|
CHART_CONTAINER_HEIGHT - totalChartContainerPadding - totalTypographyPadding,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatBytes = (bytes, space = false) => {
|
||||||
|
if (bytes === undefined || bytes === null)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{0}
|
||||||
|
{space ? " " : ""}
|
||||||
|
<Typography component="span">GB</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
if (typeof bytes !== "number")
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{0}
|
||||||
|
{space ? " " : ""}
|
||||||
|
<Typography component="span">GB</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
if (bytes === 0)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{0}
|
||||||
|
{space ? " " : ""}
|
||||||
|
<Typography component="span">GB</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const GB = bytes / (1024 * 1024 * 1024);
|
||||||
|
const MB = bytes / (1024 * 1024);
|
||||||
|
|
||||||
|
if (GB >= 1) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Number(GB.toFixed(0))}
|
||||||
|
{space ? " " : ""}
|
||||||
|
<Typography component="span">GB</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Number(MB.toFixed(0))}
|
||||||
|
<Typography component="span">MB</Typography>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a decimal value to a percentage
|
||||||
|
*
|
||||||
|
* @function decimalToPercentage
|
||||||
|
* @param {number} value - Decimal value to convert
|
||||||
|
* @returns {number} Percentage representation
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* decimalToPercentage(0.75) // Returns 75
|
||||||
|
* decimalToPercentage(null) // Returns 0
|
||||||
|
*/
|
||||||
|
const decimalToPercentage = (value) => {
|
||||||
|
if (value === null || value === undefined) return 0;
|
||||||
|
return value * 100;
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildTemps = (checks) => {
|
||||||
|
let numCores = 1;
|
||||||
|
if (checks === null) return { temps: [], tempKeys: [] };
|
||||||
|
|
||||||
|
for (const check of checks) {
|
||||||
|
if (check?.avgTemperature?.length > numCores) {
|
||||||
|
numCores = check.avgTemperature.length;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const temps = checks.map((check) => {
|
||||||
|
// If there's no data, set the temperature to 0
|
||||||
|
if (
|
||||||
|
check?.avgTemperature?.length === 0 ||
|
||||||
|
check?.avgTemperature === undefined ||
|
||||||
|
check?.avgTemperature === null
|
||||||
|
) {
|
||||||
|
check.avgTemperature = Array(numCores).fill(0);
|
||||||
|
}
|
||||||
|
const res = check?.avgTemperature?.reduce(
|
||||||
|
(acc, cur, idx) => {
|
||||||
|
acc[`core${idx + 1}`] = cur;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_id: check._id,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
if (temps.length === 0 || !temps[0]) {
|
||||||
|
return { temps: [], tempKeys: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
tempKeys: Object.keys(temps[0] || {}).filter((key) => key !== "_id"),
|
||||||
|
temps,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
formatBytes,
|
||||||
|
decimalToPercentage,
|
||||||
|
buildTemps,
|
||||||
|
getDimensions,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useHardwareUtils };
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react";
|
|
||||||
import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react";
|
|
||||||
import { Box, Typography, Stack } from "@mui/material";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
const Empty = ({ styles }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
|
||||||
return (
|
|
||||||
<Box sx={{ ...styles, marginTop: theme.spacing(24) }}>
|
|
||||||
<Stack
|
|
||||||
direction="column"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
alignItems="center"
|
|
||||||
>
|
|
||||||
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
|
||||||
|
|
||||||
<Typography variant="h2">Your infrastructure dashboard will show here</Typography>
|
|
||||||
<Typography
|
|
||||||
textAlign="center"
|
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
|
||||||
>
|
|
||||||
Hang tight! Data is loading
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Empty.propTypes = {
|
|
||||||
styles: PropTypes.object,
|
|
||||||
mode: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Empty;
|
|
||||||
@@ -1,681 +1,100 @@
|
|||||||
import { useParams } from "react-router-dom";
|
// Components
|
||||||
import { useEffect, useState } from "react";
|
import { Stack, Typography } from "@mui/material";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import { Button, ButtonGroup, Stack, Box, Typography } from "@mui/material";
|
import MonitorStatusHeader from "../../../Components/MonitorStatusHeader";
|
||||||
|
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
|
||||||
|
import StatusBoxes from "./Components/StatusBoxes";
|
||||||
|
import GaugeBoxes from "./Components/GaugeBoxes";
|
||||||
|
import AreaChartBoxes from "./Components/AreaChartBoxes";
|
||||||
|
import GenericFallback from "../../../Components/GenericFallback";
|
||||||
|
|
||||||
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import CustomGauge from "../../../Components/Charts/CustomGauge";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import AreaChart from "../../../Components/Charts/AreaChart";
|
import { useHardwareMonitorsFetch } from "./Hooks/useHardwareMonitorsFetch";
|
||||||
import { useSelector } from "react-redux";
|
import { useState } from "react";
|
||||||
import { networkService } from "../../../main";
|
import { useParams } from "react-router-dom";
|
||||||
import PulseDot from "../../../Components/Animated/PulseDot";
|
|
||||||
import useUtils from "../../Uptime/Monitors/Hooks/useUtils";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import Empty from "./empty";
|
|
||||||
import { logger } from "../../../Utils/Logger";
|
|
||||||
import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils";
|
|
||||||
import { TzTick, PercentTick } from "../../../Components/Charts/Utils/chartUtils";
|
|
||||||
import {
|
|
||||||
InfrastructureTooltip,
|
|
||||||
TemperatureTooltip,
|
|
||||||
} from "../../../Components/Charts/Utils/chartUtils";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import StatBox from "../../../Components/StatBox";
|
|
||||||
|
|
||||||
const BASE_BOX_PADDING_VERTICAL = 4;
|
// Constants
|
||||||
const BASE_BOX_PADDING_HORIZONTAL = 8;
|
const BREADCRUMBS = [
|
||||||
const TYPOGRAPHY_PADDING = 8;
|
{ name: "infrastructure monitors", path: "/infrastructure" },
|
||||||
/**
|
{ name: "details", path: "" },
|
||||||
* Converts bytes to gigabytes
|
];
|
||||||
* @param {number} bytes - Number of bytes to convert
|
const InfrastructureDetails = () => {
|
||||||
* @returns {number} Converted value in gigabytes
|
// Redux state
|
||||||
*/
|
|
||||||
const formatBytes = (bytes, space = false) => {
|
|
||||||
if (bytes === undefined || bytes === null)
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{0}
|
|
||||||
{space ? " " : ""}
|
|
||||||
<Typography component="span">GB</Typography>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
if (typeof bytes !== "number")
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{0}
|
|
||||||
{space ? " " : ""}
|
|
||||||
<Typography component="span">GB</Typography>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
if (bytes === 0)
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{0}
|
|
||||||
{space ? " " : ""}
|
|
||||||
<Typography component="span">GB</Typography>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const GB = bytes / (1024 * 1024 * 1024);
|
// Local state
|
||||||
const MB = bytes / (1024 * 1024);
|
const [dateRange, setDateRange] = useState("day");
|
||||||
|
|
||||||
if (GB >= 1) {
|
// Utils
|
||||||
|
const theme = useTheme();
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
|
const { monitorId } = useParams();
|
||||||
|
|
||||||
|
const { isLoading, networkError, monitor } = useHardwareMonitorsFetch({
|
||||||
|
monitorId,
|
||||||
|
dateRange,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (networkError === true) {
|
||||||
return (
|
return (
|
||||||
<>
|
<GenericFallback>
|
||||||
{Number(GB.toFixed(0))}
|
<Typography
|
||||||
{space ? " " : ""}
|
variant="h1"
|
||||||
<Typography component="span">GB</Typography>
|
marginY={theme.spacing(4)}
|
||||||
</>
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
);
|
>
|
||||||
} else {
|
Network error
|
||||||
return (
|
</Typography>
|
||||||
<>
|
<Typography>Please check your connection</Typography>
|
||||||
{Number(MB.toFixed(0))}
|
</GenericFallback>
|
||||||
<Typography component="span">MB</Typography>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
// if (!isLoading && monitor?.stats?.checks?.length === 0) {
|
||||||
* Converts a decimal value to a percentage
|
// return (
|
||||||
*
|
// <Stack gap={theme.spacing(10)}>
|
||||||
* @function decimalToPercentage
|
// <Breadcrumbs list={BREADCRUMBS} />
|
||||||
* @param {number} value - Decimal value to convert
|
// <MonitorStatusHeader
|
||||||
* @returns {number} Percentage representation
|
// path={"infrastructure"}
|
||||||
*
|
// isAdmin={false}
|
||||||
* @example
|
// shouldRender={!isLoading}
|
||||||
* decimalToPercentage(0.75) // Returns 75
|
// monitor={monitor}
|
||||||
* decimalToPercentage(null) // Returns 0
|
// />
|
||||||
*/
|
// <GenericFallback>
|
||||||
const decimalToPercentage = (value) => {
|
// <Typography>No data found for this monitor</Typography>
|
||||||
if (value === null || value === undefined) return 0;
|
// </GenericFallback>
|
||||||
return value * 100;
|
// </Stack>
|
||||||
};
|
// );
|
||||||
|
// }
|
||||||
/**
|
|
||||||
* Renders a base box with consistent styling
|
|
||||||
* @param {Object} props - Component properties
|
|
||||||
* @param {React.ReactNode} props.children - Child components to render inside the box
|
|
||||||
* @param {Object} props.sx - Additional styling for the box
|
|
||||||
* @returns {React.ReactElement} Styled box component
|
|
||||||
*/
|
|
||||||
const BaseBox = ({ children, sx = {} }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
height: "100%",
|
|
||||||
padding: `${theme.spacing(BASE_BOX_PADDING_VERTICAL)} ${theme.spacing(BASE_BOX_PADDING_HORIZONTAL)}`,
|
|
||||||
minWidth: 200,
|
|
||||||
width: 225,
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
border: 1,
|
|
||||||
borderStyle: "solid",
|
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
|
||||||
...sx,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseBox.propTypes = {
|
|
||||||
children: PropTypes.node.isRequired,
|
|
||||||
sx: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a gauge box with usage visualization
|
|
||||||
* @param {Object} props - Component properties
|
|
||||||
* @param {number} props.value - Percentage value for gauge
|
|
||||||
* @param {string} props.heading - Box heading
|
|
||||||
* @param {string} props.metricOne - First metric label
|
|
||||||
* @param {string} props.valueOne - First metric value
|
|
||||||
* @param {string} props.metricTwo - Second metric label
|
|
||||||
* @param {string} props.valueTwo - Second metric value
|
|
||||||
* @returns {React.ReactElement} Gauge box component
|
|
||||||
*/
|
|
||||||
const GaugeBox = ({ value, heading, metricOne, valueOne, metricTwo, valueTwo }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseBox>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Stack
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
direction="column"
|
<MonitorStatusHeader
|
||||||
gap={theme.spacing(2)}
|
path={"infrastructure"}
|
||||||
alignItems="center"
|
isAdmin={false}
|
||||||
>
|
shouldRender={!isLoading}
|
||||||
<CustomGauge
|
monitor={monitor}
|
||||||
progress={value}
|
/>
|
||||||
radius={100}
|
<StatusBoxes
|
||||||
color={theme.palette.primary.main}
|
shouldRender={!isLoading}
|
||||||
/>
|
monitor={monitor}
|
||||||
<Typography component="h2">{heading}</Typography>
|
/>
|
||||||
<Box
|
<GaugeBoxes
|
||||||
sx={{
|
shouldRender={!isLoading}
|
||||||
width: "100%",
|
monitor={monitor}
|
||||||
borderTop: `1px solid ${theme.palette.primary.lowContrast}`,
|
/>
|
||||||
}}
|
<MonitorTimeFrameHeader
|
||||||
>
|
shouldRender={!isLoading}
|
||||||
<Stack
|
dateRange={dateRange}
|
||||||
justifyContent={"space-between"}
|
setDateRange={setDateRange}
|
||||||
direction="row"
|
/>
|
||||||
gap={theme.spacing(2)}
|
<AreaChartBoxes
|
||||||
>
|
shouldRender={!isLoading}
|
||||||
<Typography>{metricOne}</Typography>
|
monitor={monitor}
|
||||||
<Typography>{valueOne}</Typography>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
|
||||||
justifyContent={"space-between"}
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Typography>{metricTwo}</Typography>
|
|
||||||
<Typography>{valueTwo}</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</BaseBox>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GaugeBox.propTypes = {
|
|
||||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
||||||
heading: PropTypes.string.isRequired,
|
|
||||||
metricOne: PropTypes.string.isRequired,
|
|
||||||
valueOne: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element])
|
|
||||||
.isRequired,
|
|
||||||
metricTwo: PropTypes.string.isRequired,
|
|
||||||
valueTwo: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.element])
|
|
||||||
.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the infrastructure details page
|
|
||||||
* @returns {React.ReactElement} Infrastructure details page component
|
|
||||||
*/
|
|
||||||
const InfrastructureDetails = () => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const theme = useTheme();
|
|
||||||
const { monitorId } = useParams();
|
|
||||||
const navList = [
|
|
||||||
{ name: "infrastructure monitors", path: "/infrastructure" },
|
|
||||||
{ name: "details", path: `/infrastructure/${monitorId}` },
|
|
||||||
];
|
|
||||||
const [monitor, setMonitor] = useState(null);
|
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
|
||||||
const [dateRange, setDateRange] = useState("day");
|
|
||||||
const { statusColor, statusStyles, determineState } = useUtils();
|
|
||||||
// These calculations are needed because ResponsiveContainer
|
|
||||||
// doesn't take padding of parent/siblings into account
|
|
||||||
// when calculating height.
|
|
||||||
const chartContainerHeight = 300;
|
|
||||||
const totalChartContainerPadding =
|
|
||||||
parseInt(theme.spacing(BASE_BOX_PADDING_VERTICAL), 10) * 2;
|
|
||||||
const totalTypographyPadding = parseInt(theme.spacing(TYPOGRAPHY_PADDING), 10) * 2;
|
|
||||||
const areaChartHeight =
|
|
||||||
(chartContainerHeight - totalChartContainerPadding - totalTypographyPadding) * 0.95;
|
|
||||||
// end height calculations
|
|
||||||
|
|
||||||
const buildStatBoxes = (stats, uptime) => {
|
|
||||||
if (Object.keys(stats).length === 0) return [];
|
|
||||||
let latestCheck = stats?.aggregateData?.latestCheck ?? null;
|
|
||||||
if (latestCheck === null) return [];
|
|
||||||
|
|
||||||
// Extract values from latest check
|
|
||||||
const physicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
|
||||||
const logicalCores = latestCheck?.cpu?.logical_core ?? 0;
|
|
||||||
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
|
||||||
const cpuTemperature =
|
|
||||||
latestCheck?.cpu?.temperature?.length > 0
|
|
||||||
? latestCheck.cpu.temperature.reduce((acc, curr) => acc + curr, 0) /
|
|
||||||
latestCheck.cpu.temperature.length
|
|
||||||
: 0;
|
|
||||||
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
|
||||||
const diskTotalBytes = latestCheck?.disk[0]?.total_bytes ?? 0;
|
|
||||||
const os = latestCheck?.host?.os ?? null;
|
|
||||||
const platform = latestCheck?.host?.platform ?? null;
|
|
||||||
const osPlatform = os === null && platform === null ? null : `${os} ${platform}`;
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: 7,
|
|
||||||
sx: statusStyles[determineState(monitor)],
|
|
||||||
heading: "Status",
|
|
||||||
subHeading: monitor?.status === true ? "Active" : "Inactive",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 0,
|
|
||||||
heading: "CPU (Physical)",
|
|
||||||
subHeading: (
|
|
||||||
<>
|
|
||||||
{physicalCores}
|
|
||||||
<Typography component="span">cores</Typography>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
heading: "CPU (Logical)",
|
|
||||||
subHeading: (
|
|
||||||
<>
|
|
||||||
{logicalCores}
|
|
||||||
<Typography component="span">cores</Typography>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
heading: "CPU Frequency",
|
|
||||||
subHeading: (
|
|
||||||
<>
|
|
||||||
{(cpuFrequency / 1000).toFixed(2)}
|
|
||||||
<Typography component="span">Ghz</Typography>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
heading: "Average CPU Temperature",
|
|
||||||
subHeading: (
|
|
||||||
<>
|
|
||||||
{cpuTemperature.toFixed(2)}
|
|
||||||
<Typography component="span">C</Typography>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
heading: "Memory",
|
|
||||||
subHeading: formatBytes(memoryTotalBytes),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
heading: "Disk",
|
|
||||||
subHeading: formatBytes(diskTotalBytes),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 6,
|
|
||||||
heading: "Uptime",
|
|
||||||
subHeading: (
|
|
||||||
<>
|
|
||||||
{(uptime * 100).toFixed(2)}
|
|
||||||
<Typography component="span">%</Typography>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
id: 8,
|
|
||||||
heading: "OS",
|
|
||||||
subHeading: osPlatform,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildGaugeBoxConfigs = (stats) => {
|
|
||||||
if (Object.keys(stats).length === 0) return [];
|
|
||||||
|
|
||||||
let latestCheck = stats?.aggregateData?.latestCheck ?? null;
|
|
||||||
if (latestCheck === null) return [];
|
|
||||||
|
|
||||||
// Extract values from latest check
|
|
||||||
const memoryUsagePercent = latestCheck?.memory?.usage_percent ?? 0;
|
|
||||||
const memoryUsedBytes = latestCheck?.memory?.used_bytes ?? 0;
|
|
||||||
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
|
|
||||||
const cpuUsagePercent = latestCheck?.cpu?.usage_percent ?? 0;
|
|
||||||
const cpuPhysicalCores = latestCheck?.cpu?.physical_core ?? 0;
|
|
||||||
const cpuFrequency = latestCheck?.cpu?.frequency ?? 0;
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
type: "memory",
|
|
||||||
value: decimalToPercentage(memoryUsagePercent),
|
|
||||||
heading: "Memory usage",
|
|
||||||
metricOne: "Used",
|
|
||||||
valueOne: formatBytes(memoryUsedBytes, true),
|
|
||||||
metricTwo: "Total",
|
|
||||||
valueTwo: formatBytes(memoryTotalBytes, true),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "cpu",
|
|
||||||
value: decimalToPercentage(cpuUsagePercent),
|
|
||||||
heading: "CPU usage",
|
|
||||||
metricOne: "Cores",
|
|
||||||
valueOne: cpuPhysicalCores ?? 0,
|
|
||||||
metricTwo: "Frequency",
|
|
||||||
valueTwo: `${(cpuFrequency / 1000).toFixed(2)} Ghz`,
|
|
||||||
},
|
|
||||||
...(latestCheck?.disk ?? []).map((disk, idx) => ({
|
|
||||||
type: "disk",
|
|
||||||
diskIndex: idx,
|
|
||||||
value: decimalToPercentage(disk.usage_percent),
|
|
||||||
heading: `Disk${idx} usage`,
|
|
||||||
metricOne: "Used",
|
|
||||||
valueOne: formatBytes(disk.total_bytes - disk.free_bytes, true),
|
|
||||||
metricTwo: "Total",
|
|
||||||
valueTwo: formatBytes(disk.total_bytes, true),
|
|
||||||
})),
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildTemps = (checks) => {
|
|
||||||
let numCores = 1;
|
|
||||||
if (checks === null) return { temps: [], tempKeys: [] };
|
|
||||||
|
|
||||||
for (const check of checks) {
|
|
||||||
if (check?.avgTemperature?.length > numCores) {
|
|
||||||
numCores = check.avgTemperature.length;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const temps = checks.map((check) => {
|
|
||||||
// If there's no data, set the temperature to 0
|
|
||||||
if (
|
|
||||||
check?.avgTemperature?.length === 0 ||
|
|
||||||
check?.avgTemperature === undefined ||
|
|
||||||
check?.avgTemperature === null
|
|
||||||
) {
|
|
||||||
check.avgTemperature = Array(numCores).fill(0);
|
|
||||||
}
|
|
||||||
const res = check?.avgTemperature?.reduce(
|
|
||||||
(acc, cur, idx) => {
|
|
||||||
acc[`core${idx + 1}`] = cur;
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
_id: check._id,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return res;
|
|
||||||
});
|
|
||||||
if (temps.length === 0 || !temps[0]) {
|
|
||||||
return { temps: [], tempKeys: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
tempKeys: Object.keys(temps[0] || {}).filter((key) => key !== "_id"),
|
|
||||||
temps,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildAreaChartConfigs = (checks) => {
|
|
||||||
let latestCheck = checks[0] ?? null;
|
|
||||||
if (latestCheck === null) return [];
|
|
||||||
const { temps, tempKeys } = buildTemps(checks);
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
type: "memory",
|
|
||||||
data: checks,
|
|
||||||
dataKeys: ["avgMemoryUsage"],
|
|
||||||
heading: "Memory usage",
|
|
||||||
strokeColor: theme.palette.accent.main, // CAIO_REVIEW
|
|
||||||
gradientStartColor: theme.palette.accent.main, // CAIO_REVIEW
|
|
||||||
yLabel: "Memory usage",
|
|
||||||
yDomain: [0, 1],
|
|
||||||
yTick: <PercentTick />,
|
|
||||||
xTick: <TzTick dateRange={dateRange} />,
|
|
||||||
toolTip: (
|
|
||||||
<InfrastructureTooltip
|
|
||||||
dotColor={theme.palette.primary.main}
|
|
||||||
yKey={"avgMemoryUsage"}
|
|
||||||
yLabel={"Memory usage"}
|
|
||||||
dateRange={dateRange}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "cpu",
|
|
||||||
data: checks,
|
|
||||||
dataKeys: ["avgCpuUsage"],
|
|
||||||
heading: "CPU usage",
|
|
||||||
strokeColor: theme.palette.success.main,
|
|
||||||
gradientStartColor: theme.palette.success.main,
|
|
||||||
yLabel: "CPU usage",
|
|
||||||
yDomain: [0, 1],
|
|
||||||
yTick: <PercentTick />,
|
|
||||||
xTick: <TzTick dateRange={dateRange} />,
|
|
||||||
toolTip: (
|
|
||||||
<InfrastructureTooltip
|
|
||||||
dotColor={theme.palette.success.main}
|
|
||||||
yKey={"avgCpuUsage"}
|
|
||||||
yLabel={"CPU usage"}
|
|
||||||
dateRange={dateRange}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "temperature",
|
|
||||||
data: temps,
|
|
||||||
dataKeys: tempKeys,
|
|
||||||
strokeColor: theme.palette.error.main,
|
|
||||||
gradientStartColor: theme.palette.error.main,
|
|
||||||
heading: "CPU Temperature",
|
|
||||||
yLabel: "Temperature",
|
|
||||||
xTick: <TzTick dateRange={dateRange} />,
|
|
||||||
yDomain: [
|
|
||||||
0,
|
|
||||||
Math.max(
|
|
||||||
Math.max(...temps.flatMap((t) => tempKeys.map((k) => t[k]))) * 1.1,
|
|
||||||
200
|
|
||||||
),
|
|
||||||
],
|
|
||||||
toolTip: (
|
|
||||||
<TemperatureTooltip
|
|
||||||
keys={tempKeys}
|
|
||||||
dotColor={theme.palette.error.main}
|
|
||||||
dateRange={dateRange}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
...(latestCheck?.disks?.map((disk, idx) => ({
|
|
||||||
type: "disk",
|
|
||||||
data: checks,
|
|
||||||
diskIndex: idx,
|
|
||||||
dataKeys: [`disks[${idx}].usagePercent`],
|
|
||||||
heading: `Disk${idx} usage`,
|
|
||||||
strokeColor: theme.palette.warning.main,
|
|
||||||
gradientStartColor: theme.palette.warning.main,
|
|
||||||
yLabel: "Disk Usage",
|
|
||||||
yDomain: [0, 1],
|
|
||||||
yTick: <PercentTick />,
|
|
||||||
xTick: <TzTick dateRange={dateRange} />,
|
|
||||||
toolTip: (
|
|
||||||
<InfrastructureTooltip
|
|
||||||
dotColor={theme.palette.warning.main}
|
|
||||||
yKey={`disks.usagePercent`}
|
|
||||||
yLabel={"Disc usage"}
|
|
||||||
yIdx={idx}
|
|
||||||
dateRange={dateRange}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
})) || []),
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fetch data
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
const response = await networkService.getHardwareDetailsByMonitorId({
|
|
||||||
authToken: authToken,
|
|
||||||
monitorId: monitorId,
|
|
||||||
dateRange: dateRange,
|
|
||||||
});
|
|
||||||
response.data.data;
|
|
||||||
setMonitor(response.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
navigate("/not-found", { replace: true });
|
|
||||||
logger.error(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchData();
|
|
||||||
}, [authToken, monitorId, dateRange, navigate]);
|
|
||||||
|
|
||||||
const statBoxConfigs = buildStatBoxes(
|
|
||||||
monitor?.stats ?? {},
|
|
||||||
monitor?.uptimePercentage ?? "Unknown"
|
|
||||||
);
|
|
||||||
const gaugeBoxConfigs = buildGaugeBoxConfigs(monitor?.stats ?? {});
|
|
||||||
const areaChartConfigs = buildAreaChartConfigs(monitor?.stats?.checks ?? []);
|
|
||||||
const lastChecked =
|
|
||||||
Date.now() - new Date(monitor?.stats?.aggregateData?.latestCheck?.createdAt);
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Breadcrumbs list={navList} />
|
|
||||||
{monitor?.stats.checks?.length > 0 ? (
|
|
||||||
<Stack
|
|
||||||
direction="column"
|
|
||||||
gap={theme.spacing(10)}
|
|
||||||
mt={theme.spacing(10)}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<PulseDot color={statusColor[determineState(monitor)]} />
|
|
||||||
</Box>
|
|
||||||
<Typography
|
|
||||||
alignSelf="end"
|
|
||||||
component="h1"
|
|
||||||
variant="h1"
|
|
||||||
>
|
|
||||||
{monitor.name}
|
|
||||||
</Typography>
|
|
||||||
<Typography alignSelf="end">{monitor.url || "..."}</Typography>
|
|
||||||
<Box sx={{ flexGrow: 1 }} />
|
|
||||||
<Typography alignSelf="end">
|
|
||||||
Checking every {formatDurationRounded(monitor?.interval)}
|
|
||||||
</Typography>
|
|
||||||
<Typography alignSelf="end">
|
|
||||||
Last checked {formatDurationSplit(lastChecked).time}{" "}
|
|
||||||
{formatDurationSplit(lastChecked).format} ago
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
flexWrap="wrap"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
{statBoxConfigs.map((statBox) => (
|
|
||||||
<StatBox
|
|
||||||
key={statBox.id}
|
|
||||||
{...statBox}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
{gaugeBoxConfigs.map((config) => {
|
|
||||||
return (
|
|
||||||
<GaugeBox
|
|
||||||
key={`${config.type}-${config.diskIndex ?? ""}`}
|
|
||||||
value={config.value}
|
|
||||||
heading={config.heading}
|
|
||||||
metricOne={config.metricOne}
|
|
||||||
valueOne={config.valueOne}
|
|
||||||
metricTwo={config.metricTwo}
|
|
||||||
valueTwo={config.valueTwo}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
alignItems="flex-end"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
mb={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
<Typography variant="body2">
|
|
||||||
Showing statistics for past{" "}
|
|
||||||
{dateRange === "day"
|
|
||||||
? "24 hours"
|
|
||||||
: dateRange === "week"
|
|
||||||
? "7 days"
|
|
||||||
: "30 days"}
|
|
||||||
.
|
|
||||||
</Typography>
|
|
||||||
<ButtonGroup sx={{ height: 32 }}>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={(dateRange === "day").toString()}
|
|
||||||
onClick={() => setDateRange("day")}
|
|
||||||
>
|
|
||||||
Day
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={(dateRange === "week").toString()}
|
|
||||||
onClick={() => setDateRange("week")}
|
|
||||||
>
|
|
||||||
Week
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="group"
|
|
||||||
filled={(dateRange === "month").toString()}
|
|
||||||
onClick={() => setDateRange("month")}
|
|
||||||
>
|
|
||||||
Month
|
|
||||||
</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction={"row"}
|
|
||||||
// height={chartContainerHeight} // FE team HELP! Possibly no longer needed?
|
|
||||||
gap={theme.spacing(8)} // FE team HELP!
|
|
||||||
flexWrap="wrap" // //FE team HELP! Better way to do this?
|
|
||||||
sx={{
|
|
||||||
"& > *": {
|
|
||||||
flexBasis: `calc(50% - ${theme.spacing(8)})`,
|
|
||||||
maxWidth: `calc(50% - ${theme.spacing(8)})`,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{areaChartConfigs.map((config) => {
|
|
||||||
return (
|
|
||||||
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
padding={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
{config.heading}
|
|
||||||
</Typography>
|
|
||||||
<AreaChart
|
|
||||||
height={areaChartHeight}
|
|
||||||
data={config.data}
|
|
||||||
dataKeys={config.dataKeys}
|
|
||||||
xKey="_id"
|
|
||||||
yDomain={config.yDomain}
|
|
||||||
customTooltip={config.toolTip}
|
|
||||||
xTick={config.xTick}
|
|
||||||
yTick={config.yTick}
|
|
||||||
strokeColor={config.strokeColor}
|
|
||||||
gradient={true}
|
|
||||||
gradientStartColor={config.gradientStartColor}
|
|
||||||
gradientEndColor="#ffffff"
|
|
||||||
/>
|
|
||||||
</BaseBox>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
) : (
|
|
||||||
<Empty
|
|
||||||
styles={{
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
p: theme.spacing(30),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ const InfrastructureMonitors = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(isLoading);
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
import { Box, Skeleton, Stack } from "@mui/material";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a skeleton layout.
|
|
||||||
*
|
|
||||||
* @returns {JSX.Element}
|
|
||||||
*/
|
|
||||||
const SkeletonLayout = () => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack gap={theme.spacing(2)}>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
mb={theme.spacing(12)}
|
|
||||||
>
|
|
||||||
<Box width="80%">
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="25%"
|
|
||||||
height={24}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="50%"
|
|
||||||
height={19.5}
|
|
||||||
sx={{ mt: theme.spacing(2) }}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="20%"
|
|
||||||
height={34}
|
|
||||||
sx={{ alignSelf: "flex-end" }}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
flexWrap="wrap"
|
|
||||||
gap={theme.spacing(12)}
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="100%"
|
|
||||||
height={120}
|
|
||||||
sx={{ flex: "35%" }}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="100%"
|
|
||||||
height={120}
|
|
||||||
sx={{ flex: "35%" }}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="100%"
|
|
||||||
height={120}
|
|
||||||
sx={{ flex: "35%" }}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="rounded"
|
|
||||||
width="100%"
|
|
||||||
height={120}
|
|
||||||
sx={{ flex: "35%" }}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SkeletonLayout;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { networkService } from "../../../../main";
|
import { networkService } from "../../../../main";
|
||||||
import { logger } from "../../../../Utils/Logger";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
const useMonitorFetch = ({ authToken, monitorId }) => {
|
const useMonitorFetch = ({ authToken, monitorId }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -8,10 +8,10 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
|
|||||||
const [monitor, setMonitor] = useState(undefined);
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
const [audits, setAudits] = useState(undefined);
|
const [audits, setAudits] = useState(undefined);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getStatsByMonitorId({
|
const res = await networkService.getStatsByMonitorId({
|
||||||
authToken: authToken,
|
authToken: authToken,
|
||||||
monitorId: monitorId,
|
monitorId: monitorId,
|
||||||
@@ -24,8 +24,8 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
|
|||||||
setMonitor(res?.data?.data ?? undefined);
|
setMonitor(res?.data?.data ?? undefined);
|
||||||
setAudits(res?.data?.data?.checks?.[0]?.audits ?? undefined);
|
setAudits(res?.data?.data?.checks?.[0]?.audits ?? undefined);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(logger);
|
setNetworkError(true);
|
||||||
navigate("/not-found", { replace: true });
|
createToast({ body: error.message });
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const PageSpeedDetails = () => {
|
|||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
const { monitor, audits, isLoading } = useMonitorFetch({
|
const { monitor, audits, isLoading, networkError } = useMonitorFetch({
|
||||||
authToken,
|
authToken,
|
||||||
monitorId,
|
monitorId,
|
||||||
});
|
});
|
||||||
@@ -39,10 +39,26 @@ const PageSpeedDetails = () => {
|
|||||||
seo: true,
|
seo: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handlers
|
||||||
const handleMetrics = (id) => {
|
const handleMetrics = (id) => {
|
||||||
setMetrics((prev) => ({ ...prev, [id]: !prev[id] }));
|
setMetrics((prev) => ({ ...prev, [id]: !prev[id] }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (networkError === true) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<Typography
|
||||||
|
variant="h1"
|
||||||
|
marginY={theme.spacing(4)}
|
||||||
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
|
>
|
||||||
|
Network error
|
||||||
|
</Typography>
|
||||||
|
<Typography>Please check your connection</Typography>
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Empty view, displayed when loading is complete and there are no checks
|
// Empty view, displayed when loading is complete and there are no checks
|
||||||
if (!isLoading && monitor?.checks?.length === 0) {
|
if (!isLoading && monitor?.checks?.length === 0) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const ChartBoxes = ({
|
|||||||
header="Uptime"
|
header="Uptime"
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
|
width={"100%"}
|
||||||
justifyContent="space-between"
|
justifyContent="space-between"
|
||||||
direction="row"
|
direction="row"
|
||||||
>
|
>
|
||||||
@@ -93,26 +94,28 @@ const ChartBoxes = ({
|
|||||||
icon={<IncidentsIcon />}
|
icon={<IncidentsIcon />}
|
||||||
header="Incidents"
|
header="Incidents"
|
||||||
>
|
>
|
||||||
<Box position="relative">
|
<Stack width={"100%"}>
|
||||||
<Typography component="span">
|
<Box position="relative">
|
||||||
{hoveredIncidentsData !== null
|
<Typography component="span">
|
||||||
? hoveredIncidentsData.totalChecks
|
{hoveredIncidentsData !== null
|
||||||
: (monitor?.groupedDownChecks?.reduce((count, checkGroup) => {
|
? hoveredIncidentsData.totalChecks
|
||||||
return count + checkGroup.totalChecks;
|
: (monitor?.groupedDownChecks?.reduce((count, checkGroup) => {
|
||||||
}, 0) ?? 0)}
|
return count + checkGroup.totalChecks;
|
||||||
</Typography>
|
}, 0) ?? 0)}
|
||||||
{hoveredIncidentsData !== null && hoveredIncidentsData.time !== null && (
|
|
||||||
<Typography
|
|
||||||
component="h5"
|
|
||||||
position="absolute"
|
|
||||||
top="100%"
|
|
||||||
fontSize={11}
|
|
||||||
color={theme.palette.primary.contrastTextTertiary}
|
|
||||||
>
|
|
||||||
{formatDateWithTz(hoveredIncidentsData._id, dateFormat, uiTimezone)}
|
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
{hoveredIncidentsData !== null && hoveredIncidentsData.time !== null && (
|
||||||
</Box>
|
<Typography
|
||||||
|
component="h5"
|
||||||
|
position="absolute"
|
||||||
|
top="100%"
|
||||||
|
fontSize={11}
|
||||||
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
|
>
|
||||||
|
{formatDateWithTz(hoveredIncidentsData._id, dateFormat, uiTimezone)}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
<DownBarChart
|
<DownBarChart
|
||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
type={dateRange}
|
type={dateRange}
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import { logger } from "../../../../Utils/Logger";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
|
export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
|
||||||
const [monitorIsLoading, setMonitorsIsLoading] = useState(false);
|
const [monitorIsLoading, setMonitorsIsLoading] = useState(true);
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
try {
|
try {
|
||||||
setMonitorsIsLoading(true);
|
|
||||||
const res = await networkService.getUptimeDetailsById({
|
const res = await networkService.getUptimeDetailsById({
|
||||||
authToken: authToken,
|
authToken: authToken,
|
||||||
monitorId: monitorId,
|
monitorId: monitorId,
|
||||||
|
|||||||
Reference in new issue
Block a user