Fixed the code for linus, windows and mac based. Also made changes to pipeline.
This commit is contained in:
1 parent
65f437f08e
commit
355a445ead
3 files changed
+100
-136
No files matched your search
@@ -3,24 +3,32 @@ import NetworkStatBoxes from "./NetworkStatBoxes";
|
||||
import NetworkCharts from "./NetworkCharts";
|
||||
import MonitorTimeFrameHeader from "../../../../../Components/MonitorTimeFrameHeader";
|
||||
|
||||
const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
|
||||
const eth0Data = (checks || [])
|
||||
const getNetworkInterfaceData = (checks) => {
|
||||
const interfaceNames = ["eth0", "Ethernet", "en0"];
|
||||
|
||||
return (checks || [])
|
||||
.map((check) => {
|
||||
const en0 = (check.net || []).find((iface) => iface.name === "en0");
|
||||
if (!en0) return null;
|
||||
const networkInterface = (check.net || []).find((iface) =>
|
||||
interfaceNames.includes(iface.name)
|
||||
);
|
||||
|
||||
if (!networkInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
_id: check._id,
|
||||
bytesPerSec: en0.avgBytesRecv,
|
||||
packetsPerSec: en0.avgPacketsRecv,
|
||||
errors: en0.avgErrOut ?? 0,
|
||||
drops: en0.avgDropOut ?? 0,
|
||||
bytesPerSec: networkInterface.avgBytesRecv,
|
||||
packetsPerSec: networkInterface.avgPacketsRecv,
|
||||
errors: networkInterface.avgErrOut ?? 0,
|
||||
drops: networkInterface.avgDropOut ?? 0,
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
console.log(eth0Data);
|
||||
|
||||
const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
|
||||
const eth0Data = getNetworkInterfaceData(checks);
|
||||
return (
|
||||
<>
|
||||
<NetworkStatBoxes
|
||||
|
||||
@@ -326,48 +326,6 @@ class MonitorModule {
|
||||
}
|
||||
};
|
||||
|
||||
processNetworkRates = (checks) => {
|
||||
if (!Array.isArray(checks) || checks.length === 0) return [];
|
||||
|
||||
const sorted = [...checks].sort((a, b) => new Date(a._id) - new Date(b._id));
|
||||
const lastSeen = {};
|
||||
|
||||
for (const check of sorted) {
|
||||
if (!Array.isArray(check.net)) {
|
||||
check.net = [];
|
||||
continue;
|
||||
}
|
||||
|
||||
const newNet = [];
|
||||
|
||||
for (const iface of check.net) {
|
||||
const prev = lastSeen[iface.name];
|
||||
const t1 = new Date(check._id);
|
||||
|
||||
if (prev) {
|
||||
const t0 = new Date(prev._id);
|
||||
const dt = (t1 - t0) / 1000;
|
||||
|
||||
if (dt > 0) {
|
||||
newNet.push({
|
||||
name: iface.name,
|
||||
avgBytesRecv: iface.avgBytesRecv - prev.avgBytesRecv,
|
||||
avgPacketsRecv: iface.avgPacketsRecv - prev.avgPacketsRecv,
|
||||
avgErrOut: iface.avgErrOut - prev.avgErrOut,
|
||||
avgDropOut: iface.avgDropOut,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lastSeen[iface.name] = { ...iface, _id: check._id };
|
||||
}
|
||||
|
||||
check.net = newNet;
|
||||
}
|
||||
|
||||
return sorted;
|
||||
};
|
||||
|
||||
getHardwareDetailsById = async ({ monitorId, dateRange }) => {
|
||||
try {
|
||||
const monitor = await this.Monitor.findById(monitorId);
|
||||
@@ -384,10 +342,6 @@ class MonitorModule {
|
||||
const hardwareStats = await this.HardwareCheck.aggregate(buildHardwareDetailsPipeline(monitor, dates, dateString));
|
||||
|
||||
const stats = hardwareStats[0];
|
||||
if (stats && stats.checks) {
|
||||
// Replace net with per-second rates
|
||||
stats.checks = this.processNetworkRates(stats.checks);
|
||||
}
|
||||
|
||||
return {
|
||||
...monitor.toObject(),
|
||||
|
||||
@@ -378,108 +378,110 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
||||
},
|
||||
net: {
|
||||
$map: {
|
||||
input: { $range: [0, "$$netCount"] },
|
||||
input: {
|
||||
$range: [0, { $size: { $arrayElemAt: ["$net", 0] } }],
|
||||
},
|
||||
as: "netIndex",
|
||||
in: {
|
||||
name: {
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: { $arrayElemAt: ["$$netArray.name", "$$netIndex"] },
|
||||
input: { $arrayElemAt: ["$net", 0] },
|
||||
as: "iface",
|
||||
in: "$$iface.name",
|
||||
},
|
||||
},
|
||||
0,
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
avgBytesSent: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.bytes_sent", "$$netIndex"],
|
||||
},
|
||||
$subtract: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$map: {
|
||||
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
|
||||
as: "iface",
|
||||
in: "$$iface.bytes_sent",
|
||||
},
|
||||
},
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_sent" } },
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
avgBytesRecv: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.bytes_recv", "$$netIndex"],
|
||||
},
|
||||
$subtract: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$map: {
|
||||
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
|
||||
as: "iface",
|
||||
in: "$$iface.bytes_recv",
|
||||
},
|
||||
},
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.bytes_recv" } },
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
avgPacketsSent: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.packets_sent", "$$netIndex"],
|
||||
},
|
||||
$subtract: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$map: {
|
||||
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
|
||||
as: "iface",
|
||||
in: "$$iface.packets_sent",
|
||||
},
|
||||
},
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_sent" } },
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
avgPacketsRecv: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.packets_recv", "$$netIndex"],
|
||||
},
|
||||
$subtract: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{
|
||||
$map: {
|
||||
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
|
||||
as: "iface",
|
||||
in: "$$iface.packets_recv",
|
||||
},
|
||||
},
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
avgErrIn: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.err_in", "$$netIndex"],
|
||||
},
|
||||
{
|
||||
$arrayElemAt: [
|
||||
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_recv" } },
|
||||
"$$netIndex",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
avgErrOut: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.err_out", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
avgDropIn: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.drop_in", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
avgDropOut: {
|
||||
$avg: {
|
||||
$map: {
|
||||
input: "$net",
|
||||
as: "netArray",
|
||||
in: {
|
||||
$arrayElemAt: ["$$netArray.drop_out", "$$netIndex"],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user