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 NetworkCharts from "./NetworkCharts";
|
||||||
import MonitorTimeFrameHeader from "../../../../../Components/MonitorTimeFrameHeader";
|
import MonitorTimeFrameHeader from "../../../../../Components/MonitorTimeFrameHeader";
|
||||||
|
|
||||||
const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
|
const getNetworkInterfaceData = (checks) => {
|
||||||
const eth0Data = (checks || [])
|
const interfaceNames = ["eth0", "Ethernet", "en0"];
|
||||||
|
|
||||||
|
return (checks || [])
|
||||||
.map((check) => {
|
.map((check) => {
|
||||||
const en0 = (check.net || []).find((iface) => iface.name === "en0");
|
const networkInterface = (check.net || []).find((iface) =>
|
||||||
if (!en0) return null;
|
interfaceNames.includes(iface.name)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!networkInterface) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_id: check._id,
|
_id: check._id,
|
||||||
bytesPerSec: en0.avgBytesRecv,
|
bytesPerSec: networkInterface.avgBytesRecv,
|
||||||
packetsPerSec: en0.avgPacketsRecv,
|
packetsPerSec: networkInterface.avgPacketsRecv,
|
||||||
errors: en0.avgErrOut ?? 0,
|
errors: networkInterface.avgErrOut ?? 0,
|
||||||
drops: en0.avgDropOut ?? 0,
|
drops: networkInterface.avgDropOut ?? 0,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
console.log(eth0Data);
|
const Network = ({ net, checks, isLoading, dateRange, setDateRange }) => {
|
||||||
|
const eth0Data = getNetworkInterfaceData(checks);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NetworkStatBoxes
|
<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 }) => {
|
getHardwareDetailsById = async ({ monitorId, dateRange }) => {
|
||||||
try {
|
try {
|
||||||
const monitor = await this.Monitor.findById(monitorId);
|
const monitor = await this.Monitor.findById(monitorId);
|
||||||
@@ -384,10 +342,6 @@ class MonitorModule {
|
|||||||
const hardwareStats = await this.HardwareCheck.aggregate(buildHardwareDetailsPipeline(monitor, dates, dateString));
|
const hardwareStats = await this.HardwareCheck.aggregate(buildHardwareDetailsPipeline(monitor, dates, dateString));
|
||||||
|
|
||||||
const stats = hardwareStats[0];
|
const stats = hardwareStats[0];
|
||||||
if (stats && stats.checks) {
|
|
||||||
// Replace net with per-second rates
|
|
||||||
stats.checks = this.processNetworkRates(stats.checks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...monitor.toObject(),
|
...monitor.toObject(),
|
||||||
|
|||||||
@@ -378,108 +378,110 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
|
|||||||
},
|
},
|
||||||
net: {
|
net: {
|
||||||
$map: {
|
$map: {
|
||||||
input: { $range: [0, "$$netCount"] },
|
input: {
|
||||||
|
$range: [0, { $size: { $arrayElemAt: ["$net", 0] } }],
|
||||||
|
},
|
||||||
as: "netIndex",
|
as: "netIndex",
|
||||||
in: {
|
in: {
|
||||||
name: {
|
name: {
|
||||||
$arrayElemAt: [
|
$arrayElemAt: [
|
||||||
{
|
{
|
||||||
$map: {
|
$map: {
|
||||||
input: "$net",
|
input: { $arrayElemAt: ["$net", 0] },
|
||||||
as: "netArray",
|
as: "iface",
|
||||||
in: { $arrayElemAt: ["$$netArray.name", "$$netIndex"] },
|
in: "$$iface.name",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
0,
|
"$$netIndex",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
avgBytesSent: {
|
avgBytesSent: {
|
||||||
$avg: {
|
$subtract: [
|
||||||
$map: {
|
{
|
||||||
input: "$net",
|
$arrayElemAt: [
|
||||||
as: "netArray",
|
{
|
||||||
in: {
|
$map: {
|
||||||
$arrayElemAt: ["$$netArray.bytes_sent", "$$netIndex"],
|
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: {
|
avgBytesRecv: {
|
||||||
$avg: {
|
$subtract: [
|
||||||
$map: {
|
{
|
||||||
input: "$net",
|
$arrayElemAt: [
|
||||||
as: "netArray",
|
{
|
||||||
in: {
|
$map: {
|
||||||
$arrayElemAt: ["$$netArray.bytes_recv", "$$netIndex"],
|
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: {
|
avgPacketsSent: {
|
||||||
$avg: {
|
$subtract: [
|
||||||
$map: {
|
{
|
||||||
input: "$net",
|
$arrayElemAt: [
|
||||||
as: "netArray",
|
{
|
||||||
in: {
|
$map: {
|
||||||
$arrayElemAt: ["$$netArray.packets_sent", "$$netIndex"],
|
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: {
|
avgPacketsRecv: {
|
||||||
$avg: {
|
$subtract: [
|
||||||
$map: {
|
{
|
||||||
input: "$net",
|
$arrayElemAt: [
|
||||||
as: "netArray",
|
{
|
||||||
in: {
|
$map: {
|
||||||
$arrayElemAt: ["$$netArray.packets_recv", "$$netIndex"],
|
input: { $arrayElemAt: ["$net", { $subtract: [{ $size: "$net" }, 1] }] },
|
||||||
},
|
as: "iface",
|
||||||
|
in: "$$iface.packets_recv",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"$$netIndex",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
},
|
$arrayElemAt: [
|
||||||
avgErrIn: {
|
{ $map: { input: { $arrayElemAt: ["$net", 0] }, as: "iface", in: "$$iface.packets_recv" } },
|
||||||
$avg: {
|
"$$netIndex",
|
||||||
$map: {
|
],
|
||||||
input: "$net",
|
|
||||||
as: "netArray",
|
|
||||||
in: {
|
|
||||||
$arrayElemAt: ["$$netArray.err_in", "$$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