From 1ecec115e4ed02b93e487df6da2c737b702d4f20 Mon Sep 17 00:00:00 2001 From: Owaise Date: Fri, 15 Aug 2025 11:28:22 +0530 Subject: [PATCH 1/2] Fixed the selector and also null points for networks. --- .../Details/Components/NetworkStats/index.jsx | 33 +++++------- .../db/mongo/modules/monitorModuleQueries.js | 54 +++++++++---------- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx b/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx index 227523439..cf1ae436c 100644 --- a/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx +++ b/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx @@ -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 && ( - setSelectedInterface(e.target.value)} + items={availableInterfaces.map((interfaceName) => ({ + _id: interfaceName, + name: interfaceName + }))} sx={{ minWidth: 200 }} - > - {t("networkInterface")} - - + /> )} { { $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,7 @@ 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 +418,7 @@ 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 +444,7 @@ 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 +453,7 @@ 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 +479,7 @@ 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 +488,7 @@ 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 +522,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $map: { input: { $arrayElemAt: [ - "$net", + { $ifNull: ["$net", []] }, { - $subtract: [{ $size: "$net" }, 1], + $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1], }, ], }, @@ -538,9 +538,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 +566,7 @@ 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 +575,7 @@ 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 +609,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $map: { input: { $arrayElemAt: [ - "$net", + { $ifNull: ["$net", []] }, { - $subtract: [{ $size: "$net" }, 1], + $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1], }, ], }, @@ -625,9 +625,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 +664,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $map: { input: { $arrayElemAt: [ - "$net", + { $ifNull: ["$net", []] }, { - $subtract: [{ $size: "$net" }, 1], + $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1], }, ], }, @@ -680,9 +680,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 +719,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $map: { input: { $arrayElemAt: [ - "$net", + { $ifNull: ["$net", []] }, { - $subtract: [{ $size: "$net" }, 1], + $subtract: [{ $size: { $ifNull: ["$net", []] } }, 1], }, ], }, @@ -735,9 +735,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { tFirst: { $arrayElemAt: ["$updatedAts", 0] }, tLast: { $arrayElemAt: [ - "$updatedAts", + { $ifNull: ["$updatedAts", []] }, { - $subtract: [{ $size: "$updatedAts" }, 1], + $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1], }, ], }, From 88c478c5339a035fcead1e6f75ba320119f3f695 Mon Sep 17 00:00:00 2001 From: Owaise Date: Fri, 15 Aug 2025 11:37:38 +0530 Subject: [PATCH 2/2] Formatting is done. --- .../Details/Components/NetworkStats/index.jsx | 2 +- .../db/mongo/modules/monitorModuleQueries.js | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx b/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx index cf1ae436c..41d2b0a87 100644 --- a/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx +++ b/client/src/Pages/Infrastructure/Details/Components/NetworkStats/index.jsx @@ -71,7 +71,7 @@ const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => { onChange={(e) => setSelectedInterface(e.target.value)} items={availableInterfaces.map((interfaceName) => ({ _id: interfaceName, - name: interfaceName + name: interfaceName, }))} sx={{ minWidth: 200 }} /> diff --git a/server/src/db/mongo/modules/monitorModuleQueries.js b/server/src/db/mongo/modules/monitorModuleQueries.js index 13352dcd4..f6d20d855 100755 --- a/server/src/db/mongo/modules/monitorModuleQueries.js +++ b/server/src/db/mongo/modules/monitorModuleQueries.js @@ -409,7 +409,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $arrayElemAt: [ { $map: { - input: { $arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }] }, + tLast: { + $arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }], + }, }, in: { $cond: [ @@ -566,7 +578,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { $arrayElemAt: [ { $map: { - input: { $arrayElemAt: [{ $ifNull: ["$net", []] }, { $subtract: [{ $size: { $ifNull: ["$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: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }] }, + tLast: { + $arrayElemAt: [{ $ifNull: ["$updatedAts", []] }, { $subtract: [{ $size: { $ifNull: ["$updatedAts", []] } }, 1] }], + }, }, in: { $cond: [