stat boxes
This commit is contained in:
1 parent
ec03addba6
commit
dcf5a77923
9 files changed
+240
-1
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { StatBox } from "@/Components/v2/design-elements";
|
||||
|
||||
import { useTheme } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
import {
|
||||
getAvgTemp,
|
||||
getCores,
|
||||
getFrequency,
|
||||
getGbs,
|
||||
getDiskTotalGbs,
|
||||
getOsAndPlatform,
|
||||
} from "@/Utils/InfraUtils";
|
||||
|
||||
export const StatusBoxes = ({ monitor }: { monitor: Monitor }) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
const latestCheck = monitor?.recentChecks?.[0];
|
||||
// Get data from latest check
|
||||
const physicalCores = getCores(latestCheck?.cpu?.physical_core);
|
||||
const logicalCores = getCores(latestCheck?.cpu?.logical_core);
|
||||
const cpuFrequency = getFrequency(latestCheck?.cpu?.frequency);
|
||||
const cpuTemps = latestCheck?.cpu?.temperature ?? [];
|
||||
const cpuTemperature = getAvgTemp(cpuTemps);
|
||||
const memoryTotalBytes = getGbs(latestCheck?.memory?.total_bytes);
|
||||
const diskTotalBytes = getDiskTotalGbs(latestCheck?.disk);
|
||||
const os = getOsAndPlatform(latestCheck?.host);
|
||||
|
||||
const platform = latestCheck?.host?.platform ?? undefined;
|
||||
const osPlatform =
|
||||
typeof os === "undefined" && typeof platform === "undefined"
|
||||
? undefined
|
||||
: `${os} ${platform}`;
|
||||
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={theme.spacing(8)}
|
||||
flexWrap={"wrap"}
|
||||
>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.cpuPhysical")}
|
||||
subtitle={physicalCores.toString()}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.cpuLogical")}
|
||||
subtitle={logicalCores.toString()}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.cpuFrequency")}
|
||||
subtitle={cpuFrequency}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.avgCpuTemperature")}
|
||||
subtitle={cpuTemperature}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.memory")}
|
||||
subtitle={memoryTotalBytes.toString()}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.disk")}
|
||||
subtitle={diskTotalBytes.toString()}
|
||||
/>
|
||||
<StatBox
|
||||
title={t("pages.infrastructure.statBoxes.os")}
|
||||
subtitle={osPlatform || "N/A"}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export const TabNetwork = () => {
|
||||
return <div>Network Content</div>;
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StatusBoxes } from "@/Pages/Infrastructure/Details/Components/StatusBoxes";
|
||||
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
|
||||
export const TabOverview = ({ monitor }: { monitor: Monitor | undefined }) => {
|
||||
if (!monitor) {
|
||||
return null;
|
||||
}
|
||||
return <StatusBoxes monitor={monitor} />;
|
||||
};
|
||||
@@ -1,7 +1,9 @@
|
||||
import { BasePage } from "@/Components/v2/design-elements";
|
||||
import { BasePage, Tab, Tabs } from "@/Components/v2/design-elements";
|
||||
import { HeaderMonitorControls, HeaderTimeRange } from "@/Components/v2/common";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { MonitorStatBoxes } from "@/Components/v2/monitors";
|
||||
import { TabNetwork } from "@/Pages/Infrastructure/Details/Components/TabNetwork";
|
||||
import { TabOverview } from "@/Pages/Infrastructure/Details/Components/TabOverview";
|
||||
|
||||
import { useTheme } from "@mui/material";
|
||||
import { useMemo, useState } from "react";
|
||||
@@ -9,14 +11,17 @@ import { useParams } from "react-router-dom";
|
||||
import { useGet } from "@/Hooks/UseApi";
|
||||
import type { HardwareDetailsResponse } from "@/Types/Monitor";
|
||||
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const InfrastructureDetails = () => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const isAdmin = useIsAdmin();
|
||||
|
||||
const { monitorId } = useParams<{ monitorId: string }>();
|
||||
|
||||
const [dateRange, setDateRange] = useState<string>("recent");
|
||||
const [selectedTab, setSelectedTab] = useState<number>(0);
|
||||
|
||||
const monitorDetailsUrl = useMemo(() => {
|
||||
if (!monitorId) {
|
||||
@@ -54,6 +59,17 @@ const InfrastructureDetails = () => {
|
||||
monitor={monitor}
|
||||
monitorStats={monitorStats}
|
||||
/>
|
||||
<Tabs
|
||||
value={selectedTab}
|
||||
onChange={(_e, value) => {
|
||||
setSelectedTab(value);
|
||||
}}
|
||||
>
|
||||
<Tab label={t("pages.infrastructure.tabs.labels.overview")} />
|
||||
<Tab label={t("pages.infrastructure.tabs.labels.network")} />
|
||||
</Tabs>
|
||||
{selectedTab === 0 && <TabOverview monitor={monitor} />}
|
||||
{selectedTab === 1 && <TabNetwork />}
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user