From 39779b9dd55ad02c5e570bb5dca373c054d3f0f7 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 14 Jul 2025 16:26:24 -0700 Subject: [PATCH 1/2] refacotr interval to be self documenting --- server/controllers/diagnosticController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/controllers/diagnosticController.js b/server/controllers/diagnosticController.js index 4410a28a5..e5368866a 100755 --- a/server/controllers/diagnosticController.js +++ b/server/controllers/diagnosticController.js @@ -56,12 +56,13 @@ class DiagnosticController { async getCPUUsage() { try { const startUsage = process.cpuUsage(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + const timingPeriod = 1000; // measured in ms + await new Promise((resolve) => setTimeout(resolve, timingPeriod)); const endUsage = process.cpuUsage(startUsage); const cpuUsage = { userUsageMs: endUsage.user / 1000, systemUsageMs: endUsage.system / 1000, - usagePercentage: ((endUsage.user + endUsage.system) / 1000 / 1000) * 100, + usagePercentage: ((endUsage.user + endUsage.system) / 1000 / timingPeriod) * 100, }; return cpuUsage; } catch (error) { From f62350fea093756450dce8cdee5de971e39dd41d Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 14 Jul 2025 16:26:34 -0700 Subject: [PATCH 2/2] add refresh button --- client/src/Hooks/logHooks.js | 28 ++++++++++++--------- client/src/Pages/Logs/Diagnostics/index.jsx | 14 +++++++++-- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/client/src/Hooks/logHooks.js b/client/src/Hooks/logHooks.js index 4b8657cbf..b954efb4b 100644 --- a/client/src/Hooks/logHooks.js +++ b/client/src/Hooks/logHooks.js @@ -89,22 +89,26 @@ const useFetchDiagnostics = () => { const [error, setError] = useState(undefined); const [diagnostics, setDiagnostics] = useState(undefined); + const fetchDiagnostics = async () => { + try { + setIsLoading(true); + const response = await networkService.getDiagnostics(); + setDiagnostics(response.data.data); + } catch (error) { + createToast({ + body: error.message, + }); + setError(error); + } finally { + setIsLoading(false); + } + }; + useEffect(() => { - const fetchDiagnostics = async () => { - try { - setIsLoading(true); - const response = await networkService.getDiagnostics(); - setDiagnostics(response.data.data); - } catch (error) { - setError(error); - } finally { - setIsLoading(false); - } - }; fetchDiagnostics(); }, []); - return [diagnostics, isLoading, error]; + return [diagnostics, fetchDiagnostics, isLoading, error]; }; export { useFetchLogs, useFetchQueueData, useFlushQueue, useFetchDiagnostics }; diff --git a/client/src/Pages/Logs/Diagnostics/index.jsx b/client/src/Pages/Logs/Diagnostics/index.jsx index e000c05bc..7c5d1f5a9 100644 --- a/client/src/Pages/Logs/Diagnostics/index.jsx +++ b/client/src/Pages/Logs/Diagnostics/index.jsx @@ -4,9 +4,9 @@ import Typography from "@mui/material/Typography"; import Gauges from "./components/gauges"; import Stats from "./components/stats"; import Divider from "@mui/material/Divider"; +import Button from "@mui/material/Button"; import { useTheme } from "@emotion/react"; -import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useFetchDiagnostics } from "../../../Hooks/logHooks"; @@ -16,7 +16,7 @@ const Diagnostics = () => { // Hooks const theme = useTheme(); const { t } = useTranslation(); - const [diagnostics, isLoading, error] = useFetchDiagnostics(); + const [diagnostics, fetchDiagnostics, isLoading, error] = useFetchDiagnostics(); // Setup return ( @@ -36,6 +36,16 @@ const Diagnostics = () => { diagnostics={diagnostics} isLoading={isLoading} /> + + + );