Merge pull request #2693 from Owaiseimdad/Network-tab-implementation-infra

Network tab implementation infra, in api at backend
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-08-05 09:54:17 -07:00
commit e19de23770
3 files changed
+113 -1

No files matched your search

+20
View File
@@ -40,6 +40,20 @@ const captureSchema = mongoose.Schema({
mode: { type: String, default: "" }, mode: { type: String, default: "" },
}); });
const networkInterfaceSchema = mongoose.Schema({
name: { type: String },
bytes_sent: { type: Number, default: 0 },
bytes_recv: { type: Number, default: 0 },
packets_sent: { type: Number, default: 0 },
packets_recv: { type: Number, default: 0 },
err_in: { type: Number, default: 0 },
err_out: { type: Number, default: 0 },
drop_in: { type: Number, default: 0 },
drop_out: { type: Number, default: 0 },
fifo_in: { type: Number, default: 0 },
fifo_out: { type: Number, default: 0 },
});
const HardwareCheckSchema = mongoose.Schema( const HardwareCheckSchema = mongoose.Schema(
{ {
...BaseCheckSchema.obj, ...BaseCheckSchema.obj,
@@ -69,6 +83,12 @@ const HardwareCheckSchema = mongoose.Schema(
type: captureSchema, type: captureSchema,
default: () => ({}), default: () => ({}),
}, },
net: {
type: [networkInterfaceSchema],
default: () => [],
required: false,
},
}, },
{ timestamps: true } { timestamps: true }
); );
@@ -220,6 +220,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
diskCount: { diskCount: {
$size: "$disk", $size: "$disk",
}, },
netCount: { $size: "$net" },
}, },
}, },
{ {
@@ -227,6 +228,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
from: "hardwarechecks", from: "hardwarechecks",
let: { let: {
diskCount: "$diskCount", diskCount: "$diskCount",
netCount: "$netCount",
}, },
pipeline: [ pipeline: [
{ {
@@ -258,6 +260,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
disks: { disks: {
$push: "$disk", $push: "$disk",
}, },
net: {
$push: "$net",
},
}, },
}, },
{ {
@@ -371,6 +376,92 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
}, },
}, },
}, },
net: {
$map: {
input: { $range: [0, "$$netCount"] },
as: "netIndex",
in: {
name: {
$arrayElemAt: [
{
$map: {
input: "$net",
as: "netArray",
in: { $arrayElemAt: ["$$netArray.name", "$$netIndex"] },
},
},
0,
],
},
avgBytesSent: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.bytes_sent", "$$netIndex"],
},
},
},
},
avgBytesRecv: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.bytes_recv", "$$netIndex"],
},
},
},
},
avgPacketsSent: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.packets_sent", "$$netIndex"],
},
},
},
},
avgPacketsRecv: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.packets_recv", "$$netIndex"],
},
},
},
},
avgErrIn: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.err_in", "$$netIndex"],
},
},
},
},
avgErrOut: {
$avg: {
$map: {
input: "$net",
as: "netArray",
in: {
$arrayElemAt: ["$$netArray.err_out", "$$netIndex"],
},
},
},
},
},
},
},
}, },
}, },
], ],
@@ -236,7 +236,7 @@ class StatusService {
} }
if (type === "hardware") { if (type === "hardware") {
const { cpu, memory, disk, host } = payload?.data ?? {}; const { cpu, memory, disk, host, net } = payload?.data ?? {};
const { errors } = payload?.errors ?? []; const { errors } = payload?.errors ?? [];
check.cpu = cpu ?? {}; check.cpu = cpu ?? {};
check.memory = memory ?? {}; check.memory = memory ?? {};
@@ -244,6 +244,7 @@ class StatusService {
check.host = host ?? {}; check.host = host ?? {};
check.errors = errors ?? []; check.errors = errors ?? [];
check.capture = payload?.capture ?? {}; check.capture = payload?.capture ?? {};
check.net = net ?? {};
} }
return check; return check;
}; };