2026-02-01 00:49:35 +00:00
|
|
|
import Grid from "@mui/material/Grid";
|
2026-04-28 23:57:14 -04:00
|
|
|
import Stack from "@mui/material/Stack";
|
|
|
|
|
import { NoticeBanner } from "@/Components/design-elements";
|
2026-02-20 18:13:39 +00:00
|
|
|
import { HistogramInfrastructure } from "@/Components/monitors";
|
2026-01-29 00:01:22 +00:00
|
|
|
|
|
|
|
|
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";
|
2026-04-28 23:57:14 -04:00
|
|
|
import { LAYOUT } from "@/Utils/Theme/constants";
|
2026-01-29 00:01:22 +00:00
|
|
|
|
2026-01-29 00:04:51 +00:00
|
|
|
const formatBytesToMB = (value: number) => `${(value / (1024 * 1024)).toFixed(2)} MB`;
|
2026-01-29 00:01:22 +00:00
|
|
|
|
|
|
|
|
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[] = [];
|
|
|
|
|
|
2026-01-29 17:43:33 +00:00
|
|
|
// Find the first check that has network data to get interface names
|
|
|
|
|
const checkWithNet = checks.find((c) => c.net && c.net.length > 0);
|
|
|
|
|
const netInterfaces = checkWithNet?.net || [];
|
2026-01-29 00:01:22 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2026-08-28 12:44:14 -04:00
|
|
|
// Loopback / bridge names Capture reports when it can only observe the
|
|
|
|
|
// container's own network namespace.
|
2026-07-10 03:16:42 +03:00
|
|
|
const CONTAINER_ONLY_IFACE_NAMES = new Set(["lo", "lo0", "docker0"]);
|
|
|
|
|
|
2026-08-28 12:44:14 -04:00
|
|
|
// Below this, an interface is carrying no traffic worth charting. Real host
|
|
|
|
|
// NICs sit orders of magnitude above it; a container's veth sits at or near
|
|
|
|
|
// zero.
|
|
|
|
|
const IDLE_INTERFACE_BYTES_PER_SECOND = 1024;
|
|
|
|
|
|
|
|
|
|
const interfaceIsIdle = (checks: HardwareCheckStats[], name: string): boolean =>
|
|
|
|
|
checks.every((check) => {
|
|
|
|
|
const iface = check.net?.find((candidate) => candidate.name === name);
|
|
|
|
|
if (!iface) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
(iface.bytesSentPerSecond || 0) < IDLE_INTERFACE_BYTES_PER_SECOND &&
|
|
|
|
|
(iface.deltaBytesRecv || 0) < IDLE_INTERFACE_BYTES_PER_SECOND
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Capture running inside a container sees only that container's network
|
|
|
|
|
// namespace. It reports the loopback and bridge names above, and usually also
|
|
|
|
|
// the container's own veth under a host-looking name (eth0, ens3, ...) - so
|
|
|
|
|
// requiring EVERY interface to be container-only missed the common case, and
|
|
|
|
|
// those users saw plausible-but-meaningless traffic with no explanation.
|
|
|
|
|
//
|
|
|
|
|
// Interface names alone cannot separate the two cases: a host-level agent on a
|
|
|
|
|
// machine running Docker legitimately reports docker0 too. What distinguishes
|
|
|
|
|
// them is that in the container case nothing carries real traffic. So the
|
|
|
|
|
// notice fires when a container-only interface is present AND every interface
|
|
|
|
|
// is idle, which leaves a genuine host reporting docker0 alongside a busy NIC
|
|
|
|
|
// untouched.
|
2026-07-10 03:16:42 +03:00
|
|
|
const onlyContainerVisibleInterfaces = (checks: HardwareCheckStats[]): boolean => {
|
|
|
|
|
const named = new Set<string>();
|
|
|
|
|
checks.forEach((c) => c.net?.forEach((iface) => named.add(iface.name)));
|
2026-08-28 12:44:14 -04:00
|
|
|
if (named.size === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const names = [...named];
|
|
|
|
|
if (!names.some((name) => CONTAINER_ONLY_IFACE_NAMES.has(name))) {
|
|
|
|
|
return false;
|
2026-07-10 03:16:42 +03:00
|
|
|
}
|
2026-08-28 12:44:14 -04:00
|
|
|
return names.every((name) => interfaceIsIdle(checks, name));
|
2026-07-10 03:16:42 +03:00
|
|
|
};
|
2026-04-28 23:57:14 -04:00
|
|
|
|
2026-01-29 00:01:22 +00:00
|
|
|
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]
|
|
|
|
|
);
|
2026-07-11 04:29:22 +03:00
|
|
|
const showLoopbackOnlyNotice =
|
2026-07-10 03:16:42 +03:00
|
|
|
chartConfigs.length > 0 && onlyContainerVisibleInterfaces(checks);
|
2026-01-29 00:01:22 +00:00
|
|
|
|
|
|
|
|
return (
|
2026-04-28 23:57:14 -04:00
|
|
|
<Stack gap={theme.spacing(LAYOUT.XS)}>
|
2026-07-11 04:29:22 +03:00
|
|
|
{showLoopbackOnlyNotice && (
|
2026-04-28 23:57:14 -04:00
|
|
|
<NoticeBanner severity="warning">
|
2026-07-11 04:29:22 +03:00
|
|
|
{t("pages.infrastructure.charts.labels.loopbackOnlyNotice")}
|
2026-04-28 23:57:14 -04:00
|
|
|
</NoticeBanner>
|
|
|
|
|
)}
|
|
|
|
|
<Grid
|
|
|
|
|
container
|
|
|
|
|
spacing={theme.spacing(LAYOUT.MD)}
|
|
|
|
|
>
|
|
|
|
|
{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>
|
|
|
|
|
</Stack>
|
2026-01-29 00:01:22 +00:00
|
|
|
);
|
|
|
|
|
};
|