Merge pull request #2794 from Owaiseimdad/Network-patch-fixes-part-1

Fixed the selector and also null points for networks
This commit is contained in:
Alexander Holliday
2025-08-15 13:12:04 -07:00
committed by GitHub
2 changed files with 55 additions and 48 deletions

View File

@@ -1,8 +1,9 @@
import PropTypes from "prop-types";
import { useState, useEffect } from "react";
import { FormControl, InputLabel, Select, MenuItem, Box } from "@mui/material";
import { Box } from "@mui/material";
import { useTranslation } from "react-i18next";
import { useTheme } from "@emotion/react";
import Select from "../../../../../Components/Inputs/Select";
import NetworkStatBoxes from "./NetworkStatBoxes";
import NetworkCharts from "./NetworkCharts";
import MonitorTimeFrameHeader from "../../../../../Components/MonitorTimeFrameHeader";
@@ -63,27 +64,17 @@ const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
gap={theme.spacing(4)}
>
{availableInterfaces.length > 0 && (
<FormControl
variant="outlined"
size="small"
<Select
name="networkInterface"
label={t("networkInterface")}
value={selectedInterface}
onChange={(e) => setSelectedInterface(e.target.value)}
items={availableInterfaces.map((interfaceName) => ({
_id: interfaceName,
name: interfaceName,
}))}
sx={{ minWidth: 200 }}
>
<InputLabel>{t("networkInterface")}</InputLabel>
<Select
value={selectedInterface}
onChange={(e) => setSelectedInterface(e.target.value)}
label={t("networkInterface")}
>
{availableInterfaces.map((interfaceName) => (
<MenuItem
key={interfaceName}
value={interfaceName}
>
{interfaceName}
</MenuItem>
))}
</Select>
</FormControl>
/>
)}
<MonitorTimeFrameHeader
isLoading={isLoading}

View File

@@ -218,9 +218,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
{
$project: {
diskCount: {
$size: "$disk",
$size: { $ifNull: ["$disk", []] },
},
netCount: { $size: "$net" },
netCount: { $size: { $ifNull: ["$net", []] } },
},
},
{
@@ -381,7 +381,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
},
net: {
$map: {
input: { $range: [0, { $size: { $arrayElemAt: ["$net", 0] } }] },
input: { $range: [0, { $size: { $ifNull: [{ $arrayElemAt: ["$net", 0] }, []] } }] },
as: "netIndex",
in: {
name: {
@@ -409,7 +409,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
input: {
$arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1] }],
},
as: "iface",
in: "$$iface.bytes_sent",
},
@@ -418,7 +420,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
tLast: {
$arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }],
},
},
in: {
$cond: [
@@ -444,7 +448,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
input: {
$arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1] }],
},
as: "iface",
in: "$$iface.bytes_recv",
},
@@ -453,7 +459,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
tLast: {
$arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }],
},
},
in: {
$cond: [
@@ -479,7 +487,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
input: {
$arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1] }],
},
as: "iface",
in: "$$iface.packets_sent",
},
@@ -488,7 +498,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
tLast: {
$arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }],
},
},
in: {
$cond: [
@@ -522,9 +534,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$map: {
input: {
$arrayElemAt: [
"$net",
{ $ifNull: ["$net", []] },
{
$subtract: [{ $size: "$net" }, 1],
$subtract: [{ $size: { $ifNull: ["$net", []] } }, 1],
},
],
},
@@ -538,9 +550,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{ $ifNull: ["$updatedAts", []] },
{
$subtract: [{ $size: "$updatedAts" }, 1],
$subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1],
},
],
},
@@ -566,7 +578,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
input: {
$arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1] }],
},
as: "iface",
in: "$$iface.err_in",
},
@@ -575,7 +589,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
tLast: {
$arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }],
},
},
in: {
$cond: [
@@ -609,9 +625,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$map: {
input: {
$arrayElemAt: [
"$net",
{ $ifNull: ["$net", []] },
{
$subtract: [{ $size: "$net" }, 1],
$subtract: [{ $size: { $ifNull: ["$net", []] } }, 1],
},
],
},
@@ -625,9 +641,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{ $ifNull: ["$updatedAts", []] },
{
$subtract: [{ $size: "$updatedAts" }, 1],
$subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1],
},
],
},
@@ -664,9 +680,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$map: {
input: {
$arrayElemAt: [
"$net",
{ $ifNull: ["$net", []] },
{
$subtract: [{ $size: "$net" }, 1],
$subtract: [{ $size: { $ifNull: ["$net", []] } }, 1],
},
],
},
@@ -680,9 +696,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{ $ifNull: ["$updatedAts", []] },
{
$subtract: [{ $size: "$updatedAts" }, 1],
$subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1],
},
],
},
@@ -719,9 +735,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$map: {
input: {
$arrayElemAt: [
"$net",
{ $ifNull: ["$net", []] },
{
$subtract: [{ $size: "$net" }, 1],
$subtract: [{ $size: { $ifNull: ["$net", []] } }, 1],
},
],
},
@@ -735,9 +751,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{ $ifNull: ["$updatedAts", []] },
{
$subtract: [{ $size: "$updatedAts" }, 1],
$subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1],
},
],
},