feat: adding infrastructure display support to status page
This commit is contained in:
1 parent
7a0e0bccf4
commit
be1ca4ac28
13 files changed
+341
-41
No files matched your search
@@ -0,0 +1,152 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { Gauge } from "@/Components/design-elements";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
|
||||
interface StatusPageMonitor extends Monitor {
|
||||
checks?: Monitor["recentChecks"];
|
||||
infrastructureCPU?: number;
|
||||
infrastructureMemory?: number;
|
||||
infrastructureDisk?: number;
|
||||
}
|
||||
|
||||
interface MetricItemProps {
|
||||
label: string;
|
||||
progress: number;
|
||||
upperLabel?: string;
|
||||
upperValue?: string;
|
||||
lowerLabel?: string;
|
||||
lowerValue?: string;
|
||||
}
|
||||
|
||||
const MetricItem = ({
|
||||
label,
|
||||
progress,
|
||||
upperLabel,
|
||||
upperValue,
|
||||
lowerLabel,
|
||||
lowerValue,
|
||||
}: MetricItemProps) => {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
gap={`${theme.spacing(4)} ${theme.spacing(10)}`}
|
||||
flex={1}
|
||||
>
|
||||
<Stack
|
||||
alignItems="center"
|
||||
spacing={theme.spacing(2)}
|
||||
>
|
||||
<Gauge
|
||||
progress={progress}
|
||||
radius={60}
|
||||
strokeWidth={12}
|
||||
/>
|
||||
<Typography variant="body2">{label}</Typography>
|
||||
</Stack>
|
||||
{(upperLabel || lowerLabel) && (
|
||||
<Stack
|
||||
spacing={theme.spacing(1)}
|
||||
flex={1}
|
||||
paddingBottom={theme.spacing(10)}
|
||||
>
|
||||
{upperLabel && (
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
>
|
||||
{upperLabel}
|
||||
</Typography>
|
||||
<Typography variant="body2">{upperValue}</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
{lowerLabel && (
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
>
|
||||
{lowerLabel}
|
||||
</Typography>
|
||||
<Typography variant="body2">{lowerValue}</Typography>
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
export const InfrastructureMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const latestCheck = monitor.recentChecks?.[0] ?? monitor.checks?.[0];
|
||||
|
||||
if (!latestCheck) {
|
||||
return (
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
>
|
||||
{t("pages.statusPages.monitorsList.noData")}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
const cpuUsage = (latestCheck?.cpu?.usage_percent || 0) * 100;
|
||||
const memoryUsage = (latestCheck?.memory?.usage_percent || 0) * 100;
|
||||
const memoryUsed = latestCheck?.memory?.used_bytes || 0;
|
||||
const memoryTotal = latestCheck?.memory?.total_bytes || 0;
|
||||
|
||||
const disks = latestCheck?.disk ?? [];
|
||||
const totalDiskUsage = disks.reduce((acc, disk) => acc + (disk?.usage_percent || 0), 0);
|
||||
const diskCount = disks.length || 1;
|
||||
const diskUsage = (totalDiskUsage / diskCount) * 100;
|
||||
const diskUsed = disks.reduce((acc, disk) => acc + (disk?.used_bytes || 0), 0);
|
||||
const diskTotal = disks.reduce((acc, disk) => acc + (disk?.total_bytes || 0), 0);
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction={{ xs: "column", sm: "row" }}
|
||||
gap={theme.spacing(10)}
|
||||
columnGap={theme.spacing(15)}
|
||||
padding={theme.spacing(8)}
|
||||
>
|
||||
<MetricItem
|
||||
label={t("pages.statusPages.monitorsList.infrastructure.cpu")}
|
||||
progress={cpuUsage}
|
||||
upperLabel={t("pages.statusPages.monitorsList.infrastructure.usage")}
|
||||
upperValue={`${cpuUsage.toFixed(1)}%`}
|
||||
/>
|
||||
<MetricItem
|
||||
label={t("pages.statusPages.monitorsList.infrastructure.memory")}
|
||||
progress={memoryUsage}
|
||||
upperLabel={t("pages.statusPages.monitorsList.infrastructure.used")}
|
||||
upperValue={prettyBytes(memoryUsed)}
|
||||
lowerLabel={t("pages.statusPages.monitorsList.infrastructure.total")}
|
||||
lowerValue={prettyBytes(memoryTotal)}
|
||||
/>
|
||||
<MetricItem
|
||||
label={t("pages.statusPages.monitorsList.infrastructure.disk")}
|
||||
progress={diskUsage}
|
||||
upperLabel={t("pages.statusPages.monitorsList.infrastructure.used")}
|
||||
upperValue={prettyBytes(diskUsed)}
|
||||
lowerLabel={t("pages.statusPages.monitorsList.infrastructure.total")}
|
||||
lowerValue={prettyBytes(diskTotal)}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography";
|
||||
import { HistogramResponseTime, HeatmapResponseTime } from "@/Components/common";
|
||||
import { StatusLabel, BaseBox } from "@/Components/design-elements";
|
||||
import { SwitchComponent } from "@/Components/inputs";
|
||||
import { InfrastructureMetrics } from "@/Pages/StatusPage/Status/Components/InfrastructureMetrics";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useSelector } from "react-redux";
|
||||
@@ -32,10 +33,11 @@ export const MonitorsList = ({ statusPage, monitors }: MonitorsListProps) => {
|
||||
|
||||
return (
|
||||
<Stack gap={theme.spacing(8)}>
|
||||
{statusPage.showCharts !== false && (
|
||||
{statusPage.showCharts && (
|
||||
<Stack
|
||||
direction={"row"}
|
||||
alignItems={"center"}
|
||||
gap={theme.spacing(2)}
|
||||
>
|
||||
<Typography>{t("pages.statusPages.monitorsList.chartTypeHeatmap")}</Typography>
|
||||
<SwitchComponent
|
||||
@@ -53,30 +55,56 @@ export const MonitorsList = ({ statusPage, monitors }: MonitorsListProps) => {
|
||||
)}
|
||||
|
||||
{monitors?.map((monitor) => {
|
||||
const isInfrastructureMonitor = monitor?.type === "hardware";
|
||||
return (
|
||||
<BaseBox
|
||||
key={monitor.id}
|
||||
padding={theme.spacing(4)}
|
||||
padding={theme.spacing(8)}
|
||||
>
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
gap={theme.spacing(4)}
|
||||
mb={statusPage.showCharts !== false ? theme.spacing(4) : 0}
|
||||
mb={theme.spacing(4)}
|
||||
>
|
||||
<Box sx={{ overflow: "hidden", minWidth: 0, flex: 1 }}>
|
||||
<Typography
|
||||
variant="h6"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
gap={theme.spacing(2)}
|
||||
mb={theme.spacing(1)}
|
||||
>
|
||||
{monitor.name}
|
||||
</Typography>
|
||||
{showURL && (
|
||||
<Typography
|
||||
variant="h6"
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
textOverflow: "ellipsis",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{monitor.name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
backgroundColor:
|
||||
monitor?.type === "hardware"
|
||||
? theme.palette.info.light
|
||||
: theme.palette.success.light,
|
||||
color:
|
||||
monitor?.type === "hardware"
|
||||
? theme.palette.info.dark
|
||||
: theme.palette.success.dark,
|
||||
padding: `${theme.spacing(0.5)} ${theme.spacing(1.5)}`,
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{t(`pages.statusPages.monitorsList.badge.${monitor?.type}`)}
|
||||
</Typography>
|
||||
</Stack>
|
||||
{showURL && monitor?.url && (
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
@@ -85,22 +113,49 @@ export const MonitorsList = ({ statusPage, monitors }: MonitorsListProps) => {
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
<StatusLabel status={monitor.status} />
|
||||
<StatusLabel status={monitor?.status} />
|
||||
</Stack>
|
||||
{statusPage.showCharts !== false && (
|
||||
<Box sx={{ overflow: "hidden", minWidth: 0, flex: 1 }}>
|
||||
{chartType === "histogram" ? (
|
||||
<HistogramResponseTime
|
||||
height={{ xs: 50, md: 100 }}
|
||||
gap={{ xs: theme.spacing(0.5), md: theme.spacing(5) }}
|
||||
checks={monitor?.checks?.slice().reverse() ?? []}
|
||||
/>
|
||||
) : (
|
||||
<HeatmapResponseTime
|
||||
checks={monitor?.checks?.slice().reverse() ?? []}
|
||||
/>
|
||||
|
||||
{!isInfrastructureMonitor && (
|
||||
<>
|
||||
{statusPage.showCharts !== false && (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
minWidth: 0,
|
||||
flex: 1,
|
||||
mb: theme.spacing(2),
|
||||
}}
|
||||
>
|
||||
{chartType === "histogram" ? (
|
||||
<HistogramResponseTime
|
||||
height={{ xs: 50, md: 100 }}
|
||||
gap={{ xs: theme.spacing(0.5), md: theme.spacing(5) }}
|
||||
checks={monitor?.checks?.slice().reverse() ?? []}
|
||||
/>
|
||||
) : (
|
||||
<HeatmapResponseTime
|
||||
checks={monitor?.checks?.slice().reverse() ?? []}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isInfrastructureMonitor && statusPage.showInfrastructure !== false && (
|
||||
<BaseBox
|
||||
key={monitor.id}
|
||||
padding={theme.spacing(4)}
|
||||
>
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
gap={theme.spacing(8)}
|
||||
></Stack>
|
||||
<InfrastructureMetrics monitor={monitor} />
|
||||
</BaseBox>
|
||||
)}
|
||||
</BaseBox>
|
||||
);
|
||||
|
||||
@@ -23,16 +23,17 @@ const StatusPageView = () => {
|
||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||
const isPublic = location.pathname.startsWith("/status/public");
|
||||
|
||||
const apiUrl = url ? `/status-page/${url}?type=uptime` : null;
|
||||
const apiUrl = url ? `/status-page/${url}?type=uptime&type=infrastructure` : null;
|
||||
|
||||
const { data, isLoading, error } = useGet<StatusPageResponse>(apiUrl);
|
||||
|
||||
const statusPage = data?.statusPage;
|
||||
const monitors = data?.monitors ?? [];
|
||||
const infrastructureMonitors = data?.infrastructureMonitors ?? [];
|
||||
|
||||
if (!statusPage) return null;
|
||||
|
||||
if (monitors?.length === 0) {
|
||||
if (monitors?.length === 0 && infrastructureMonitors?.length === 0) {
|
||||
return (
|
||||
<BasePage
|
||||
loading={isLoading}
|
||||
|
||||
Reference in new issue
Block a user