diff --git a/client/src/Pages/Infrastructure/Details/Components/StatusBoxes.tsx b/client/src/Pages/Infrastructure/Details/Components/StatusBoxes.tsx index ebfdad569..70f4325c6 100644 --- a/client/src/Pages/Infrastructure/Details/Components/StatusBoxes.tsx +++ b/client/src/Pages/Infrastructure/Details/Components/StatusBoxes.tsx @@ -11,7 +11,8 @@ export const StatusBoxes = ({ monitor }: { monitor: Monitor }) => { const { t } = useTranslation(); const theme = useTheme(); - const latestCheck = monitor?.recentChecks?.[0]; + const recentChecks = monitor?.recentChecks ?? []; + const latestCheck = recentChecks[recentChecks.length - 1]; // Get data from latest check const physicalCores = getCores(latestCheck?.cpu?.physical_core); const logicalCores = getCores(latestCheck?.cpu?.logical_core); @@ -21,13 +22,7 @@ export const StatusBoxes = ({ monitor }: { monitor: Monitor }) => { const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0; const diskTotalBytes = latestCheck?.disk?.reduce((acc, disk) => acc + (disk.total_bytes || 0), 0) || 0; - const os = getOsAndPlatform(latestCheck?.host); - - const platform = latestCheck?.host?.platform ?? undefined; - const osPlatform = - typeof os === "undefined" && typeof platform === "undefined" - ? undefined - : `${os} ${platform}`; + const osPlatform = getOsAndPlatform(latestCheck?.host); return ( - + { - const check = row.recentChecks?.[0]; + const recentChecks = row.recentChecks ?? []; + const check = recentChecks[recentChecks.length - 1]; const cpuUsage = (check?.cpu?.usage_percent || 0) * 100; return ; }, @@ -257,7 +258,8 @@ export const InfraMonitorsTable = ({ id: "memory", content: t("pages.infrastructure.table.headers.memory"), render: (row) => { - const check = row.recentChecks?.[0]; + const recentChecks = row.recentChecks ?? []; + const check = recentChecks[recentChecks.length - 1]; const memoryUsage = (check?.memory?.usage_percent || 0) * 100; return ; }, @@ -266,7 +268,8 @@ export const InfraMonitorsTable = ({ id: "disk", content: t("pages.infrastructure.table.headers.disk"), render: (row) => { - const check = row.recentChecks?.[0]; + const recentChecks = row.recentChecks ?? []; + const check = recentChecks[recentChecks.length - 1]; const totalDiskUsage = check?.disk?.reduce( (acc, disk) => acc + (disk?.usage_percent || 0), diff --git a/client/src/Pages/PageSpeed/Details/index.tsx b/client/src/Pages/PageSpeed/Details/index.tsx index 48a9ba99c..ea9da4a7f 100644 --- a/client/src/Pages/PageSpeed/Details/index.tsx +++ b/client/src/Pages/PageSpeed/Details/index.tsx @@ -45,6 +45,8 @@ const PageSpeedDetails = () => { const monitor = monitorData?.monitorData?.monitor; const groupedChecks = monitorData?.monitorData?.groupedChecks || []; const monitorStats = monitorData?.monitorStats || null; + const recentChecks = monitor?.recentChecks ?? []; + const latestCheck = recentChecks[recentChecks.length - 1]; return ( { direction={{ xs: "column", md: "row" }} gap={theme.spacing(10)} > - - + + ); diff --git a/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx b/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx index ab7d0dc35..3c92e6b0a 100644 --- a/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx +++ b/client/src/Pages/StatusPage/Status/themes/shared/ThemedInfrastructure.tsx @@ -36,7 +36,8 @@ const heatLevel = (value: number): GaugeFillLevel => export const ThemedInfrastructure = ({ monitor, sxApi }: Props) => { const { t } = useTranslation(); - const latest = monitor.recentChecks?.[0]; + const recentChecks = monitor.recentChecks ?? []; + const latest = recentChecks[recentChecks.length - 1]; const renderEmpty = () => ( {t("pages.statusPages.monitorsList.noData")} diff --git a/server/src/domain/checks/check.repository.mongo.ts b/server/src/domain/checks/check.repository.mongo.ts index 78f0b9344..cb1c5bfba 100644 --- a/server/src/domain/checks/check.repository.mongo.ts +++ b/server/src/domain/checks/check.repository.mongo.ts @@ -81,6 +81,7 @@ class MongoChecksRepository implements IChecksRepository { os: host?.os ?? "", platform: host?.platform ?? "", kernel_version: host?.kernel_version ?? "", + pretty_name: host?.pretty_name ?? "", }); const mapCapture = (capture?: CheckCaptureInfo): CheckCaptureInfo => ({ diff --git a/server/src/domain/monitors/monitor.service.ts b/server/src/domain/monitors/monitor.service.ts index 7a8478c5a..78a452044 100644 --- a/server/src/domain/monitors/monitor.service.ts +++ b/server/src/domain/monitors/monitor.service.ts @@ -363,7 +363,7 @@ export class MonitorService implements IMonitorService { const monitorsWithChecks = monitors.map((monitor: Monitor) => { const rawChecks = monitor.recentChecks ?? []; const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type); - const checks = isSnapshotType ? rawChecks.slice(0, 1) : rawChecks; + const checks = isSnapshotType ? rawChecks.slice(-1) : rawChecks; monitor.recentChecks = checks; return monitor; }); diff --git a/server/test/unit/services/monitorService.test.ts b/server/test/unit/services/monitorService.test.ts index 69edbba9c..0f56e5d2b 100644 --- a/server/test/unit/services/monitorService.test.ts +++ b/server/test/unit/services/monitorService.test.ts @@ -583,7 +583,7 @@ describe("MonitorService", () => { expect(result.monitors).toEqual([]); }); - it("uses snapshot (first check only) for hardware type monitors", async () => { + it("uses snapshot (latest check only) for hardware type monitors", async () => { const monitorsRepository = createMonitorsRepositoryMock(); (monitorsRepository.findMonitorsSummaryByTeamId as jest.Mock).mockResolvedValue({ totalMonitors: 1 }); (monitorsRepository.findMonitorCountByTeamIdAndType as jest.Mock).mockResolvedValue(1); @@ -602,6 +602,7 @@ describe("MonitorService", () => { const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: "hardware" }); expect(result.monitors[0].recentChecks).toHaveLength(1); + expect(result.monitors[0].recentChecks[0].responseTime).toBe(30); }); it("uses snapshot for hardware type when type is array with hardware", async () => { @@ -622,6 +623,7 @@ describe("MonitorService", () => { const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: ["hardware"] }); expect(result.monitors[0].recentChecks).toHaveLength(1); + expect(result.monitors[0].recentChecks[0].responseTime).toBe(20); }); it("normalizes checks for non-snapshot types when type is an array", async () => {