network charts
This commit is contained in:
1 parent
353b97e7d3
commit
38ef9ccad3
7 files changed
+166
-13
No files matched your search
@@ -93,7 +93,7 @@ const createGradient = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const HistogramInfrastructure = ({
|
export const HistogramInfrastructure = ({
|
||||||
range,
|
dateRange,
|
||||||
title,
|
title,
|
||||||
type,
|
type,
|
||||||
idx: _idx,
|
idx: _idx,
|
||||||
@@ -107,8 +107,9 @@ export const HistogramInfrastructure = ({
|
|||||||
gradientEndColor,
|
gradientEndColor,
|
||||||
strokeColor,
|
strokeColor,
|
||||||
fillColor,
|
fillColor,
|
||||||
|
yAxisFormatter,
|
||||||
}: {
|
}: {
|
||||||
range: string;
|
dateRange: string;
|
||||||
title: string;
|
title: string;
|
||||||
type: string;
|
type: string;
|
||||||
idx: number | null;
|
idx: number | null;
|
||||||
@@ -122,6 +123,7 @@ export const HistogramInfrastructure = ({
|
|||||||
gradientEndColor?: string;
|
gradientEndColor?: string;
|
||||||
strokeColor: string;
|
strokeColor: string;
|
||||||
fillColor?: string;
|
fillColor?: string;
|
||||||
|
yAxisFormatter?: (value: number) => string;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const uniqueId = useId();
|
const uniqueId = useId();
|
||||||
@@ -160,11 +162,14 @@ export const HistogramInfrastructure = ({
|
|||||||
tick={(props) => (
|
tick={(props) => (
|
||||||
<XTick
|
<XTick
|
||||||
{...props}
|
{...props}
|
||||||
range={range}
|
range={dateRange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<YAxis domain={type === "temp" ? tempYDomain : yDomain} />
|
<YAxis
|
||||||
|
domain={type === "temp" ? tempYDomain : yDomain}
|
||||||
|
tickFormatter={yAxisFormatter}
|
||||||
|
/>
|
||||||
|
|
||||||
<CartesianGrid
|
<CartesianGrid
|
||||||
stroke={theme.palette.divider}
|
stroke={theme.palette.divider}
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ const getChartConfigs = (theme: any, checks: HardwareCheckStats[], t: any) => {
|
|||||||
|
|
||||||
export const InfraDetailsCharts = ({
|
export const InfraDetailsCharts = ({
|
||||||
checks,
|
checks,
|
||||||
range,
|
dateRange,
|
||||||
}: {
|
}: {
|
||||||
checks: HardwareCheckStats[];
|
checks: HardwareCheckStats[];
|
||||||
range: string;
|
dateRange: string;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
@@ -63,7 +63,6 @@ export const InfraDetailsCharts = ({
|
|||||||
[theme, checks, t]
|
[theme, checks, t]
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(checks);
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
@@ -76,7 +75,7 @@ export const InfraDetailsCharts = ({
|
|||||||
key={`${config.type}-${config.idx ?? ""}`}
|
key={`${config.type}-${config.idx ?? ""}`}
|
||||||
>
|
>
|
||||||
<HistogramInfrastructure
|
<HistogramInfrastructure
|
||||||
range={range}
|
dateRange={dateRange}
|
||||||
title={config.title}
|
title={config.title}
|
||||||
type={config.type}
|
type={config.type}
|
||||||
idx={config.idx}
|
idx={config.idx}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
import Grid from "@mui/material/Grid2";
|
||||||
|
import { HistogramInfrastructure } from "@/Components/v2/monitors";
|
||||||
|
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import type { HardwareCheckStats } from "@/Types/Monitor";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
|
const formatBytesToMB = (value: number) =>
|
||||||
|
`${(value / (1024 * 1024)).toFixed(2)} MB`;
|
||||||
|
|
||||||
|
interface ChartConfig {
|
||||||
|
title: string;
|
||||||
|
type: string;
|
||||||
|
dataKeys: string[];
|
||||||
|
strokeColor: string;
|
||||||
|
gradientStartColor: string;
|
||||||
|
idx: number | null;
|
||||||
|
interfaceName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getChartConfigs = (
|
||||||
|
theme: any,
|
||||||
|
checks: HardwareCheckStats[],
|
||||||
|
t: any
|
||||||
|
): ChartConfig[] => {
|
||||||
|
const configs: ChartConfig[] = [];
|
||||||
|
|
||||||
|
const netInterfaces = checks[0]?.net || [];
|
||||||
|
|
||||||
|
netInterfaces.forEach((iface, idx) => {
|
||||||
|
configs.push(
|
||||||
|
{
|
||||||
|
title: t("pages.infrastructure.charts.labels.netBytesSent", {
|
||||||
|
name: iface.name,
|
||||||
|
}),
|
||||||
|
type: "netBytesSent",
|
||||||
|
dataKeys: [`net[${idx}].bytesSentPerSecond`],
|
||||||
|
strokeColor: theme.palette.primary.main,
|
||||||
|
gradientStartColor: theme.palette.primary.main,
|
||||||
|
idx,
|
||||||
|
interfaceName: iface.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("pages.infrastructure.charts.labels.netBytesRecv", {
|
||||||
|
name: iface.name,
|
||||||
|
}),
|
||||||
|
type: "netBytesRecv",
|
||||||
|
dataKeys: [`net[${idx}].deltaBytesRecv`],
|
||||||
|
strokeColor: theme.palette.success.main,
|
||||||
|
gradientStartColor: theme.palette.success.main,
|
||||||
|
idx,
|
||||||
|
interfaceName: iface.name,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return configs;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InfraNetworkCharts = ({
|
||||||
|
checks,
|
||||||
|
dateRange,
|
||||||
|
}: {
|
||||||
|
checks: HardwareCheckStats[];
|
||||||
|
dateRange: string;
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const chartConfigs = useMemo(
|
||||||
|
() => getChartConfigs(theme, checks, t),
|
||||||
|
[theme, checks, t]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
{chartConfigs.map((config) => {
|
||||||
|
return (
|
||||||
|
<Grid
|
||||||
|
size={isSmall ? 12 : 6}
|
||||||
|
key={`${config.type}-${config.interfaceName ?? config.idx ?? ""}`}
|
||||||
|
>
|
||||||
|
<HistogramInfrastructure
|
||||||
|
dateRange={dateRange}
|
||||||
|
title={config.title}
|
||||||
|
type={config.type}
|
||||||
|
idx={config.idx}
|
||||||
|
checks={checks}
|
||||||
|
xKey="bucketDate"
|
||||||
|
dataKeys={config.dataKeys}
|
||||||
|
gradient={true}
|
||||||
|
gradientStartColor={config.gradientStartColor}
|
||||||
|
gradientEndColor="#ffffff"
|
||||||
|
strokeColor={config.strokeColor}
|
||||||
|
yAxisFormatter={formatBytesToMB}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,3 +1,29 @@
|
|||||||
export const TabNetwork = () => {
|
import Stack from "@mui/material/Stack";
|
||||||
return <div>Network Content</div>;
|
import { InfraNetworkCharts } from "./ChartsNetwork";
|
||||||
|
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
import type { HardwareStats } from "@/Types/Monitor";
|
||||||
|
|
||||||
|
export const TabNetwork = ({
|
||||||
|
stats,
|
||||||
|
dateRange,
|
||||||
|
}: {
|
||||||
|
stats: HardwareStats | undefined;
|
||||||
|
dateRange: string;
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
if (!stats) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const checks = stats?.checks || [];
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(8)}>
|
||||||
|
<InfraNetworkCharts
|
||||||
|
checks={checks}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
@@ -9,9 +9,11 @@ import type { HardwareStats, Monitor } from "@/Types/Monitor";
|
|||||||
export const TabOverview = ({
|
export const TabOverview = ({
|
||||||
monitor,
|
monitor,
|
||||||
stats,
|
stats,
|
||||||
|
dateRange,
|
||||||
}: {
|
}: {
|
||||||
monitor: Monitor | undefined;
|
monitor: Monitor | undefined;
|
||||||
stats: HardwareStats | undefined;
|
stats: HardwareStats | undefined;
|
||||||
|
dateRange: string;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
@@ -25,7 +27,7 @@ export const TabOverview = ({
|
|||||||
<InfraDetailsGauges snapshot={monitor.recentChecks?.[0]} />
|
<InfraDetailsGauges snapshot={monitor.recentChecks?.[0]} />
|
||||||
<InfraDetailsCharts
|
<InfraDetailsCharts
|
||||||
checks={checks}
|
checks={checks}
|
||||||
range={"recent"}
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ const InfrastructureDetails = () => {
|
|||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
monitorStats={monitorStats}
|
monitorStats={monitorStats}
|
||||||
/>
|
/>
|
||||||
|
<HeaderTimeRange
|
||||||
|
isLoading={monitorIsLoading}
|
||||||
|
hasDateRange={true}
|
||||||
|
dateRange={dateRange}
|
||||||
|
setDateRange={setDateRange}
|
||||||
|
/>
|
||||||
<Tabs
|
<Tabs
|
||||||
value={selectedTab}
|
value={selectedTab}
|
||||||
onChange={(_e, value) => {
|
onChange={(_e, value) => {
|
||||||
@@ -72,9 +78,15 @@ const InfrastructureDetails = () => {
|
|||||||
<TabOverview
|
<TabOverview
|
||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
stats={stats}
|
stats={stats}
|
||||||
|
dateRange={dateRange}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{selectedTab === 1 && (
|
||||||
|
<TabNetwork
|
||||||
|
stats={stats}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{selectedTab === 1 && <TabNetwork />}
|
|
||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -322,7 +322,9 @@
|
|||||||
"memory": "Memory usage",
|
"memory": "Memory usage",
|
||||||
"cpu": "CPU usage",
|
"cpu": "CPU usage",
|
||||||
"temp": "Temp",
|
"temp": "Temp",
|
||||||
"disk": "Disk usage"
|
"disk": "Disk usage",
|
||||||
|
"netBytesSent": "{{name}} - Bytes Sent",
|
||||||
|
"netBytesRecv": "{{name}} - Bytes Received"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user