mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-24 19:01:01 -06:00
Added net to be returned from api in backend for infra.
This commit is contained in:
@@ -40,6 +40,20 @@ const captureSchema = mongoose.Schema({
|
||||
mode: { type: String, default: "" },
|
||||
});
|
||||
|
||||
const networkInterfaceSchema = mongoose.Schema({
|
||||
name: { type: String, required: true },
|
||||
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(
|
||||
{
|
||||
...BaseCheckSchema.obj,
|
||||
@@ -69,6 +83,11 @@ const HardwareCheckSchema = mongoose.Schema(
|
||||
type: captureSchema,
|
||||
default: () => ({}),
|
||||
},
|
||||
|
||||
net: {
|
||||
type: [networkInterfaceSchema],
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
@@ -220,6 +220,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
||||
diskCount: {
|
||||
$size: "$disk",
|
||||
},
|
||||
netCount: { $size: "$net" },
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -227,6 +228,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
||||
from: "hardwarechecks",
|
||||
let: {
|
||||
diskCount: "$diskCount",
|
||||
netCount: "$netCount",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
@@ -258,6 +260,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
||||
disks: {
|
||||
$push: "$disk",
|
||||
},
|
||||
net: {
|
||||
$push: "$net",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -371,6 +376,83 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
net: {
|
||||
$map: {
|
||||
input: { $range: [0, "$$netCount"] },
|
||||
as: "netIndex",
|
||||
in: {
|
||||
name: {
|
||||
$concat: ["net", { $toString: "$$netIndex" }],
|
||||
},
|
||||
bytesSent: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.bytes_sent", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
bytesRecv: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.bytes_recv", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
packetsSent: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.packets_sent", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
packetsRecv: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.packets_recv", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
errIn: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.errin", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
errOut: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.errout", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -232,7 +232,7 @@ class StatusService {
|
||||
}
|
||||
|
||||
if (type === "hardware") {
|
||||
const { cpu, memory, disk, host } = payload?.data ?? {};
|
||||
const { cpu, memory, disk, host, net } = payload?.data ?? {};
|
||||
const { errors } = payload?.errors ?? [];
|
||||
check.cpu = cpu ?? {};
|
||||
check.memory = memory ?? {};
|
||||
@@ -240,6 +240,7 @@ class StatusService {
|
||||
check.host = host ?? {};
|
||||
check.errors = errors ?? [];
|
||||
check.capture = payload?.capture ?? {};
|
||||
check.net = net ?? {};
|
||||
}
|
||||
return check;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user