Skip to content

Commit 43ac5b5

Browse files
committed
time formatting
1 parent 1558b27 commit 43ac5b5

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

client/src/Components/v2/monitors/MonitorStatBoxes.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Stack from "@mui/material/Stack";
22
import { StatBox } from "@/Components/v2/design-elements";
33

4+
import prettyMilliseconds from "pretty-ms";
45
import { useTheme } from "@mui/material/styles";
56
import type { MonitorStats, Monitor } from "@/Types/Monitor";
6-
import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js";
77
import { getStatusPalette } from "@/Utils/MonitorUtils";
88
import { useTranslation } from "react-i18next";
99

@@ -32,11 +32,16 @@ export const MonitorStatBoxes = ({
3232

3333
// Determine time since last check
3434
const timeOfLastCheck = monitorStats?.lastCheckTimestamp || 0;
35-
const timeSinceLastCheck = Date.now() - timeOfLastCheck;
35+
const timeSinceLastCheck = Date.now() - timeOfLastCheck || 0;
3636

37-
const streakTime = getHumanReadableDuration(timeSinceLastFailure);
37+
const options = {
38+
secondsDecimalDigits: 0,
39+
millisecondsDecimalDigits: 0,
40+
};
3841

39-
const lastCheckTime = getHumanReadableDuration(timeSinceLastCheck);
42+
const streakTime = prettyMilliseconds(timeSinceLastFailure, options);
43+
44+
const lastCheckTime = prettyMilliseconds(timeSinceLastCheck, options);
4045
const palette = getStatusPalette(monitor?.status);
4146

4247
return (
@@ -55,7 +60,7 @@ export const MonitorStatBoxes = ({
5560
/>
5661
<StatBox
5762
title={t("pages.common.monitors.statBoxes.lastResponseTime")}
58-
subtitle={monitorStats?.lastResponseTime + " ms"}
63+
subtitle={prettyMilliseconds(monitorStats?.lastResponseTime ?? 0)}
5964
/>
6065

6166
{monitor?.type === "http" && (

client/src/Pages/Incidents/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Incident, IncidentSummaryItem } from "@/Types/Incident";
2-
import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js";
2+
import prettyMilliseconds from "pretty-ms";
33

44
type IncidentLike = Pick<Incident, "startTime" | "endTime" | "status">;
55

@@ -24,5 +24,8 @@ export const getIncidentsDuration = (incident: IncidentLike | IncidentSummaryIte
2424
return "-";
2525
}
2626

27-
return getHumanReadableDuration(durationMs);
27+
return prettyMilliseconds(durationMs, {
28+
secondsDecimalDigits: 0,
29+
millisecondsDecimalDigits: 0,
30+
});
2831
};

client/src/Pages/Maintenance/MaintenanceWindowTable.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Typography from "@mui/material/Typography";
2-
import prettyMilliseconds from "pretty-ms";
32
import { Table, ValueLabel } from "@/Components/v2/design-elements";
43
import { Pagination } from "@/Components/v2/design-elements/Table";
54
import { ActionsMenu } from "@/Components/v2/actions-menu";
65
import { DialogInput } from "@/Components/v2/inputs/Dialog";
76

7+
import prettyMilliseconds from "pretty-ms";
88
import { useTheme } from "@mui/material";
99
import type { Header } from "@/Components/v2/design-elements/Table";
1010
import type { ActionMenuItem } from "@/Components/v2/actions-menu";
@@ -15,7 +15,6 @@ import { useSelector, useDispatch } from "react-redux";
1515
import type { RootState } from "@/Types/state";
1616
import Box from "@mui/material/Box";
1717
import { setRowsPerPage } from "@/Features/UI/uiSlice";
18-
import { formatDurationRounded } from "@/Utils/timeUtilsLegacy";
1918
import dayjs from "dayjs";
2019
import { useState } from "react";
2120
import { useDelete, usePatch } from "@/Hooks/UseApi";
@@ -153,7 +152,9 @@ export const MaintenanceWindowTable = ({
153152
id: "repeat",
154153
content: t("pages.maintenanceWindow.table.headers.repeat"),
155154
render: (row) =>
156-
row.repeat === 0 ? t("common.labels.na") : formatDurationRounded(row.repeat),
155+
row.repeat === 0
156+
? t("common.labels.na")
157+
: prettyMilliseconds(row.repeat, { verbose: true }),
157158
},
158159
{
159160
id: "actions",

client/src/Pages/Uptime/Details/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useGet } from "@/Hooks/UseApi";
2020
import type { MonitorDetailsResponse } from "@/Types/Monitor";
2121
import type { ChecksResponse } from "@/Types/Check";
2222
import type { RootState } from "@/Types/state";
23-
import { formatDateWithTz } from "@/Utils/timeUtilsLegacy";
23+
import { formatDateWithTz } from "@/Utils/TimeUtils";
2424
import { t } from "i18next";
2525

2626
const certificateDateFormat = "MMM D, YYYY h A";

server/src/service/business/diagnosticService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ class DiagnosticService {
5555
};
5656

5757
const used = process.memoryUsage();
58-
const memoryUsage: Record<string, number> = {};
59-
for (const key of Object.keys(used) as Array<keyof NodeJS.MemoryUsage>) {
60-
memoryUsage[`${key}Mb`] = Math.round((used[key] / 1024 / 1024) * 100) / 100; // MB
61-
}
58+
59+
// In MB
60+
const memoryUsage: Record<keyof NodeJS.MemoryUsage, number> = {
61+
rss: Math.round((used.rss / 1024 / 1024) * 100) / 100,
62+
heapTotal: Math.round((used.heapTotal / 1024 / 1024) * 100) / 100,
63+
heapUsed: Math.round((used.heapUsed / 1024 / 1024) * 100) / 100,
64+
external: Math.round((used.external / 1024 / 1024) * 100) / 100,
65+
arrayBuffers: Math.round((used.arrayBuffers / 1024 / 1024) * 100) / 100,
66+
};
6267

6368
// CPU Usage
6469
const cpuMetrics = await this.getCPUUsage();

0 commit comments

Comments
 (0)