GroupedChecks

This commit is contained in:
Alex Holliday committed 2026-01-05 04:17:11 +00:00
1 parent cdc58e5905
commit 3182141d0a
14 files changed
+592 -62

No files matched your search

@@ -12,7 +12,6 @@ import { useTheme } from "@mui/material/styles";
import { useParams } from "react-router";
import type { ApiResponse } from "@/types/api";
import type { IMonitor, IMonitorWithMonitorStats } from "@/types/monitor";
import type { IInfraCheck } from "@/types/check";
import {
getFrequency,
getCores,
@@ -43,16 +42,16 @@ const InfraDetailsPage = () => {
const monitor = response?.data?.monitor;
const stats = response?.data?.stats;
const checks = (response?.data?.checks || []) as IInfraCheck[];
const palette = getStatusPalette(monitor?.status || "initializing");
const checks = Array.isArray(response?.data?.checks)
? response?.data?.checks
: [];
const palette = getStatusPalette(monitor?.status ?? "initializing");
const streakDuration = stats?.currentStreakStartedAt
? Date.now() - stats?.currentStreakStartedAt
: 0;
const streakStartedAt = stats?.currentStreakStartedAt ?? 0;
const streakDuration = streakStartedAt > 0 ? Date.now() - streakStartedAt : 0;
const lastChecked = stats?.lastCheckTimestamp
? Date.now() - stats?.lastCheckTimestamp
: -1;
const lastCheckTs = stats?.lastCheckTimestamp ?? -1;
const lastChecked = lastCheckTs >= 0 ? Date.now() - lastCheckTs : -1;
if (!monitor) {
return null;
@@ -88,36 +87,38 @@ const InfraDetailsPage = () => {
<StatBox
title={t("monitors.common.stats.lastResponseTime")}
subtitle={
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
typeof stats?.lastResponseTime === "number"
? `${stats.lastResponseTime} ms`
: "N/A"
}
/>
<StatBox
title={t("monitors.common.stats.cpuPhysical")}
subtitle={getCores(checks[0]?.cpu?.physical_core)}
subtitle={getCores(checks?.[0]?.cpu?.physical_core || 0)}
/>
<StatBox
title={t("monitors.common.stats.cpuLogical")}
subtitle={getCores(checks[0]?.cpu?.logical_core)}
subtitle={getCores(checks?.[0]?.cpu?.logical_core || 0)}
/>
<StatBox
title={t("monitors.common.stats.cpuFrequency")}
subtitle={getFrequency(checks[0]?.cpu?.current_frequency)}
subtitle={getFrequency(checks?.[0]?.cpu?.current_frequency || 0)}
/>
<StatBox
title={t("monitors.common.stats.cpuTemperature")}
subtitle={getAvgTemp(checks[0]?.cpu?.temperature)}
subtitle={getAvgTemp(checks?.[0]?.cpu?.temperature || [])}
/>
<StatBox
title={t("monitors.common.stats.memory")}
subtitle={getGbs(checks[0]?.memory?.total_bytes)}
subtitle={getGbs(checks?.[0]?.memory?.total_bytes || 0)}
/>
<StatBox
title={t("monitors.common.stats.disk")}
subtitle={getDiskTotalGbs(checks[0]?.disk)}
subtitle={getDiskTotalGbs(checks?.[0]?.disk)}
/>
<StatBox
title={t("monitors.common.stats.os")}
subtitle={getOsAndPlatform(checks[0]?.host)}
subtitle={getOsAndPlatform(checks?.[0]?.host || {})}
/>
</Stack>
@@ -5,9 +5,9 @@ import { Gauge } from "@/components/design-elements";
import { useTranslation } from "react-i18next";
import { getGbs, getFrequency } from "./InfraUtils";
import type { IInfraCheck } from "@/types/check";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
import type { GroupedCheck } from "@/types/check";
const InfraDetailGauge = ({
title,
@@ -42,7 +42,7 @@ const InfraDetailGauge = ({
);
};
export const InfraDetailsGauges = ({ checks }: { checks: IInfraCheck[] }) => {
export const InfraDetailsGauges = ({ checks }: { checks: GroupedCheck[] }) => {
const { t } = useTranslation();
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
@@ -54,31 +54,31 @@ export const InfraDetailsGauges = ({ checks }: { checks: IInfraCheck[] }) => {
>
<InfraDetailGauge
title={t("monitors.infrastructure.gauges.memory.title")}
progress={(checks[0]?.memory.usage_percent || 0) * 100}
progress={(checks[0]?.memory?.usage_percent || 0) * 100}
upperLabel={t("monitors.infrastructure.gauges.memory.upperLabel")}
upperValue={getGbs(checks[0]?.memory.used_bytes)}
upperValue={getGbs(checks[0]?.memory?.used_bytes || 0)}
lowerLabel={t("monitors.infrastructure.gauges.memory.lowerLabel")}
lowerValue={getGbs(checks[0]?.memory.total_bytes)}
lowerValue={getGbs(checks[0]?.memory?.total_bytes || 0)}
/>
<InfraDetailGauge
title={t("monitors.infrastructure.gauges.cpu.title")}
progress={(checks[0]?.cpu.usage_percent || 0) * 100}
progress={(checks[0]?.cpu?.usage_percent || 0) * 100}
upperLabel={t("monitors.infrastructure.gauges.cpu.upperLabel")}
upperValue={getFrequency(checks[0]?.cpu.current_frequency)}
upperValue={getFrequency(checks[0]?.cpu?.current_frequency || 0)}
lowerLabel={t("monitors.infrastructure.gauges.cpu.lowerLabel")}
lowerValue={getFrequency(checks[0]?.cpu.frequency)}
lowerValue={getFrequency(checks[0]?.cpu?.frequency || 0)}
/>
{checks[0]?.disk?.map((disk, idx) => {
return (
<InfraDetailGauge
key={disk.device + idx}
key={disk?.device || 0 + idx}
// title={`Disk ${idx} usage`}
title={t("monitors.infrastructure.gauges.disk.title", { idx })}
progress={(disk.usage_percent || 0) * 100}
upperLabel={t("monitors.infrastructure.gauges.disk.upperLabel")}
upperValue={getGbs(disk.used_bytes)}
upperValue={getGbs(disk?.used_bytes || 0)}
lowerLabel={t("monitors.infrastructure.gauges.disk.lowerLabel")}
lowerValue={getGbs(disk.total_bytes)}
lowerValue={getGbs(disk?.total_bytes || 0)}
/>
);
})}
@@ -2,12 +2,12 @@ import Grid from "@mui/material/Grid";
import { HistogramInfrastructure } from "@/components/monitors";
import { useTranslation } from "react-i18next";
import type { IInfraCheck } from "@/types/check";
import type { GroupedCheck } from "@/types/check";
import { useMemo } from "react";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
const getChartConfigs = (theme: any, checks: IInfraCheck[], t: any) => {
const getChartConfigs = (theme: any, checks: GroupedCheck[], t: any) => {
return [
{
title: t("common.charts.infrastructure.memory.title"),
@@ -52,7 +52,7 @@ export const InfraDetailsGraphs = ({
checks,
range,
}: {
checks: IInfraCheck[];
checks: GroupedCheck[];
range: string;
}) => {
const theme = useTheme();
@@ -36,7 +36,10 @@ export const getGbs = (bytes: number): string => {
}
};
export const getDiskTotalGbs = (disk: IDiskInfo[]): string => {
export const getDiskTotalGbs = (disk?: Partial<IDiskInfo>[]): string => {
if (!disk) {
return getGbs(0);
}
const totalBytes =
disk?.reduce((acc, disk) => acc + (disk.total_bytes || 0), 0) || 0;
return getGbs(totalBytes);