Merge pull request #2620 from bluewave-labs/feat/diagnostics
Feat/diagnostics
This commit is contained in:
3 files changed
+31
-16
No files matched your search
@@ -89,22 +89,26 @@ const useFetchDiagnostics = () => {
|
|||||||
const [error, setError] = useState(undefined);
|
const [error, setError] = useState(undefined);
|
||||||
const [diagnostics, setDiagnostics] = 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(() => {
|
useEffect(() => {
|
||||||
const fetchDiagnostics = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getDiagnostics();
|
|
||||||
setDiagnostics(response.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchDiagnostics();
|
fetchDiagnostics();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return [diagnostics, isLoading, error];
|
return [diagnostics, fetchDiagnostics, isLoading, error];
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useFetchLogs, useFetchQueueData, useFlushQueue, useFetchDiagnostics };
|
export { useFetchLogs, useFetchQueueData, useFlushQueue, useFetchDiagnostics };
|
||||||
@@ -4,9 +4,9 @@ import Typography from "@mui/material/Typography";
|
|||||||
import Gauges from "./components/gauges";
|
import Gauges from "./components/gauges";
|
||||||
import Stats from "./components/stats";
|
import Stats from "./components/stats";
|
||||||
import Divider from "@mui/material/Divider";
|
import Divider from "@mui/material/Divider";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useState } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useFetchDiagnostics } from "../../../Hooks/logHooks";
|
import { useFetchDiagnostics } from "../../../Hooks/logHooks";
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ const Diagnostics = () => {
|
|||||||
// Hooks
|
// Hooks
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [diagnostics, isLoading, error] = useFetchDiagnostics();
|
const [diagnostics, fetchDiagnostics, isLoading, error] = useFetchDiagnostics();
|
||||||
// Setup
|
// Setup
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(4)}>
|
<Stack gap={theme.spacing(4)}>
|
||||||
@@ -36,6 +36,16 @@ const Diagnostics = () => {
|
|||||||
diagnostics={diagnostics}
|
diagnostics={diagnostics}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
/>
|
/>
|
||||||
|
<Box>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
onClick={fetchDiagnostics}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
Fetch Diagnostics
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,12 +56,13 @@ class DiagnosticController {
|
|||||||
async getCPUUsage() {
|
async getCPUUsage() {
|
||||||
try {
|
try {
|
||||||
const startUsage = process.cpuUsage();
|
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 endUsage = process.cpuUsage(startUsage);
|
||||||
const cpuUsage = {
|
const cpuUsage = {
|
||||||
userUsageMs: endUsage.user / 1000,
|
userUsageMs: endUsage.user / 1000,
|
||||||
systemUsageMs: endUsage.system / 1000,
|
systemUsageMs: endUsage.system / 1000,
|
||||||
usagePercentage: ((endUsage.user + endUsage.system) / 1000 / 1000) * 100,
|
usagePercentage: ((endUsage.user + endUsage.system) / 1000 / timingPeriod) * 100,
|
||||||
};
|
};
|
||||||
return cpuUsage;
|
return cpuUsage;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user