Metrics validated.

This commit is contained in:
Owaise committed 2025-08-14 00:04:53 +05:30
1 parent f5aefb1f0b
commit 2141c3eacd
2 files changed
+236 -89

No files matched your search

@@ -343,17 +343,6 @@ class MonitorModule {
const stats = hardwareStats[0]; const stats = hardwareStats[0];
if (stats?.net?.length) {
const elapsedSeconds = (new Date(dates.end).getTime() - new Date(dates.start).getTime()) / 1000;
stats.net = stats.net.map((iface) => ({
...iface,
bytesSentPerSec: iface.deltaBytesSent / elapsedSeconds,
bytesRecvPerSec: iface.deltaBytesRecv / elapsedSeconds,
packetsSentPerSec: iface.deltaPacketsSent / elapsedSeconds,
packetsRecvPerSec: iface.deltaPacketsRecv / elapsedSeconds,
}));
}
return { return {
...monitor.toObject(), ...monitor.toObject(),
stats, stats,
@@ -263,6 +263,9 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
net: { net: {
$push: "$net", $push: "$net",
}, },
updatedAts: {
$push: "$updatedAt",
},
}, },
}, },
{ {
@@ -378,9 +381,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
}, },
net: { net: {
$map: { $map: {
input: { input: { $range: [0, { $size: { $arrayElemAt: ["$net", 0] } }] },
$range: [0, { $size: { $arrayElemAt: ["$net", 0] } }],
},
as: "netIndex", as: "netIndex",
in: { in: {
name: { name: {
@@ -395,9 +396,16 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
deltaBytesSent: { bytesSentPerSecond: {
$subtract: [ $let: {
{ vars: {
first: {
$arrayElemAt: [
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_sent" } },
"$$netIndex",
],
},
last: {
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
@@ -409,17 +417,30 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
},
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{ {
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
],
},
},
},
deltaBytesRecv: {
$let: {
vars: {
first: {
$arrayElemAt: [ $arrayElemAt: [
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_sent" } }, { $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_recv" } },
"$$netIndex", "$$netIndex",
], ],
}, },
], last: {
},
deltaBytesRecv: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
@@ -431,17 +452,30 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
},
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{ {
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
],
},
},
},
deltaPacketsSent: {
$let: {
vars: {
first: {
$arrayElemAt: [ $arrayElemAt: [
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_recv" } }, { $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_sent" } },
"$$netIndex", "$$netIndex",
], ],
}, },
], last: {
},
deltaPacketsSent: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
@@ -453,21 +487,28 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
},
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{ {
$arrayElemAt: [ $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_sent" } }, },
"$$netIndex", 0,
], ],
}, },
], },
}, },
deltaPacketsRecv: { deltaPacketsRecv: {
$subtract: [ $let: {
{ vars: {
first: {
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] }, input: { $arrayElemAt: ["$net", 0] },
as: "iface", as: "iface",
in: "$$iface.packets_recv", in: "$$iface.packets_recv",
}, },
@@ -475,17 +516,53 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
{ last: {
$arrayElemAt: [ $arrayElemAt: [
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_recv" } }, {
$map: {
input: {
$arrayElemAt: [
"$net",
{
$subtract: [{ $size: "$net" }, 1],
},
],
},
as: "iface",
in: "$$iface.packets_recv",
},
},
"$$netIndex", "$$netIndex",
], ],
}, },
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{
$subtract: [{ $size: "$updatedAts" }, 1],
},
], ],
}, },
deltaErrIn: { },
$subtract: [ in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{ {
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
],
},
},
},
deltaErrIn: {
$let: {
vars: {
first: {
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.err_in" } }, "$$netIndex"],
},
last: {
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
@@ -497,18 +574,28 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
{ tFirst: { $arrayElemAt: ["$updatedAts", 0] },
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.err_in" } }, "$$netIndex"], tLast: { $arrayElemAt: ["$updatedAts", { $subtract: [{ $size: "$updatedAts" }, 1] }] },
}, },
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
], ],
}, },
},
},
deltaErrOut: { deltaErrOut: {
$subtract: [ $let: {
{ vars: {
first: {
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] }, input: { $arrayElemAt: ["$net", 0] },
as: "iface", as: "iface",
in: "$$iface.err_out", in: "$$iface.err_out",
}, },
@@ -516,18 +603,54 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
{ last: {
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.err_out" } }, "$$netIndex"],
},
],
},
deltaDropIn: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] }, input: {
$arrayElemAt: [
"$net",
{
$subtract: [{ $size: "$net" }, 1],
},
],
},
as: "iface",
in: "$$iface.err_out",
},
},
"$$netIndex",
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{
$subtract: [{ $size: "$updatedAts" }, 1],
},
],
},
},
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
],
},
},
},
deltaDropIn: {
$let: {
vars: {
first: {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", 0] },
as: "iface", as: "iface",
in: "$$iface.drop_in", in: "$$iface.drop_in",
}, },
@@ -535,18 +658,54 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
{ last: {
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.drop_in" } }, "$$netIndex"],
},
],
},
deltaDropOut: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] }, input: {
$arrayElemAt: [
"$net",
{
$subtract: [{ $size: "$net" }, 1],
},
],
},
as: "iface",
in: "$$iface.drop_in",
},
},
"$$netIndex",
],
},
tFirst: { $arrayElemAt: ["$updatedAts", 0] },
tLast: {
$arrayElemAt: [
"$updatedAts",
{
$subtract: [{ $size: "$updatedAts" }, 1],
},
],
},
},
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
],
},
},
},
deltaDropOut: {
$let: {
vars: {
first: {
$arrayElemAt: [
{
$map: {
input: { $arrayElemAt: ["$net", 0] },
as: "iface", as: "iface",
in: "$$iface.drop_out", in: "$$iface.drop_out",
}, },
@@ -554,47 +713,42 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
"$$netIndex", "$$netIndex",
], ],
}, },
{ last: {
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.drop_out" } }, "$$netIndex"],
},
],
},
deltaFifoIn: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
{ {
$map: { $map: {
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] }, input: {
$arrayElemAt: [
"$net",
{
$subtract: [{ $size: "$net" }, 1],
},
],
},
as: "iface", as: "iface",
in: "$$iface.fifo_in", in: "$$iface.drop_out",
}, },
}, },
"$$netIndex", "$$netIndex",
], ],
}, },
{ tFirst: { $arrayElemAt: ["$updatedAts", 0] },
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.fifo_in" } }, "$$netIndex"], tLast: {
},
],
},
deltaFifoOut: {
$subtract: [
{
$arrayElemAt: [ $arrayElemAt: [
"$updatedAts",
{ {
$map: { $subtract: [{ $size: "$updatedAts" }, 1],
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
as: "iface",
in: "$$iface.fifo_out",
}, },
},
"$$netIndex",
], ],
}, },
{
$arrayElemAt: [{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.fifo_out" } }, "$$netIndex"],
}, },
in: {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
},
0,
], ],
}, },
}, },
@@ -602,6 +756,10 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
}, },
}, },
}, },
firstUpdatedAt: 1,
lastUpdatedAt: 1,
},
},
], ],
as: "hourlyStats", as: "hourlyStats",
}, },