@trap_stevo/osx
Version:
OSX, the pinnacle of real-time system resource tracking, seamlessly monitors and transmits vital system metrics, transforming complex data into clear, actionable insights. Experience the future of system monitoring with your ultimate ally for comprehensiv
918 lines (917 loc) • 46.8 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
var os = require('os');
var _require = require('child_process'),
exec = _require.exec;
var util = require('util');
var execAsync = util.promisify(exec);
var getCPUOverallUtilizationWindows = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var _yield$execAsync, cpuUsageOutput, lines, coreUsages, totalUsage, averageUsage;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return execAsync('wmic cpu get loadpercentage');
case 3:
_yield$execAsync = _context.sent;
cpuUsageOutput = _yield$execAsync.stdout;
lines = cpuUsageOutput.trim().split('\n').filter(function (line) {
return line.trim() !== '' && !isNaN(line.trim());
});
coreUsages = lines.map(function (line) {
return parseFloat(line.trim());
}).filter(function (value) {
return !isNaN(value);
});
if (!(coreUsages.length === 0)) {
_context.next = 10;
break;
}
console.error("No valid CPU usage data found.");
return _context.abrupt("return", null);
case 10:
totalUsage = coreUsages.reduce(function (acc, usage) {
return acc + usage;
}, 0);
averageUsage = totalUsage / coreUsages.length;
console.log("Overall CPU Usage: ".concat(averageUsage.toFixed(2), "%"));
console.log("Total Usage: ".concat(totalUsage, ", Number of Cores: ").concat(coreUsages.length));
return _context.abrupt("return", averageUsage.toFixed(2));
case 17:
_context.prev = 17;
_context.t0 = _context["catch"](0);
console.error("Error retrieving CPU usage: ".concat(_context.t0));
return _context.abrupt("return", null);
case 21:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 17]]);
}));
return function getCPUOverallUtilizationWindows() {
return _ref.apply(this, arguments);
};
}();
var getCpuCores = function getCpuCores() {
var cpuInfo = os.cpus();
return cpuInfo.map(function (cpu, index) {
return {
core: index,
speed: cpu.speed,
load: {
user: cpu.times.user,
nice: cpu.times.nice,
sys: cpu.times.sys,
idle: cpu.times.idle,
irq: cpu.times.irq
}
};
});
};
var getCpuUsage = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(platform) {
var cpuInfo, cpuUsage, cpuTemp, _yield$execAsync2, cpuUsageOutput, _yield$execAsync3, _cpuUsageOutput, _yield$execAsync4, _cpuUsageOutput2;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
cpuInfo = os.cpus();
cpuUsage = 'N/A';
cpuTemp = 'N/A';
_context2.prev = 3;
if (!(platform === 'win32' || platform === 'windows')) {
_context2.next = 14;
break;
}
_context2.next = 7;
return execAsync('powershell -Command "(Get-Counter \\"\\Processor(_Total)\\% Processor Time\\").CounterSamples.CookedValue"');
case 7:
_yield$execAsync2 = _context2.sent;
cpuUsageOutput = _yield$execAsync2.stdout;
_context2.next = 11;
return getCPUOverallUtilizationWindows();
case 11:
cpuUsage = _context2.sent;
_context2.next = 28;
break;
case 14:
if (!(platform === 'linux')) {
_context2.next = 22;
break;
}
_context2.next = 17;
return execAsync('top -bn1 | grep "Cpu(s)" | sed "s/.*, *\\([0-9.]*\\)%* id.*/\\1/" | awk \'{print 100 - $1}\'');
case 17:
_yield$execAsync3 = _context2.sent;
_cpuUsageOutput = _yield$execAsync3.stdout;
cpuUsage = parseFloat(_cpuUsageOutput.trim()) || 'N/A';
_context2.next = 28;
break;
case 22:
if (!(platform === 'darwin' || platform === 'mac')) {
_context2.next = 28;
break;
}
_context2.next = 25;
return execAsync('ps -A -o %cpu | awk \'{s+=$1} END {print s}\'');
case 25:
_yield$execAsync4 = _context2.sent;
_cpuUsageOutput2 = _yield$execAsync4.stdout;
cpuUsage = parseFloat(_cpuUsageOutput2.trim()) || 'N/A';
case 28:
_context2.next = 33;
break;
case 30:
_context2.prev = 30;
_context2.t0 = _context2["catch"](3);
console.error('Error retrieving CPU data:', _context2.t0);
case 33:
return _context2.abrupt("return", {
model: cpuInfo[0].model,
usage: cpuUsage !== null ? cpuUsage : "N/A",
speed: cpuInfo.map(function (cpu) {
return cpu.speed;
}),
cores: getCpuCores(),
temp: cpuTemp
});
case 34:
case "end":
return _context2.stop();
}
}, _callee2, null, [[3, 30]]);
}));
return function getCpuUsage(_x) {
return _ref2.apply(this, arguments);
};
}();
var getMemoryUsage = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(platform) {
var totalMemory, freeMemory, usedMemory, buffers, cached, slab, _yield$execAsync5, memoryInfo, memInfoLines, _yield$execAsync6, _memoryInfo, _memInfoLines, _yield$execAsync7, _memoryInfo2, _memInfoLines2;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
totalMemory = os.totalmem();
freeMemory = os.freemem();
usedMemory = totalMemory - freeMemory;
buffers = 'N/A';
cached = 'N/A';
slab = 'N/A';
_context3.prev = 6;
if (!(platform === 'linux')) {
_context3.next = 16;
break;
}
_context3.next = 10;
return execAsync('cat /proc/meminfo');
case 10:
_yield$execAsync5 = _context3.sent;
memoryInfo = _yield$execAsync5.stdout;
memInfoLines = memoryInfo.split('\n');
memInfoLines.forEach(function (line) {
if (line.startsWith('Buffers:')) {
buffers = parseInt(line.split(':')[1].trim()) * 1024;
}
if (line.startsWith('Cached:')) {
cached = parseInt(line.split(':')[1].trim()) * 1024;
}
if (line.startsWith('Slab:')) {
slab = parseInt(line.split(':')[1].trim()) * 1024;
}
});
_context3.next = 33;
break;
case 16:
if (!(platform === 'darwin' || platform === 'mac')) {
_context3.next = 25;
break;
}
_context3.next = 19;
return execAsync('vm_stat');
case 19:
_yield$execAsync6 = _context3.sent;
_memoryInfo = _yield$execAsync6.stdout;
_memInfoLines = _memoryInfo.split('\n');
_memInfoLines.forEach(function (line) {
if (line.startsWith('Pages active:')) {
buffers = parseInt(line.split(':')[1].trim()) * 4096;
}
if (line.startsWith('Pages inactive:')) {
cached = parseInt(line.split(':')[1].trim()) * 4096;
}
if (line.startsWith('Pages wired down:')) {
slab = parseInt(line.split(':')[1].trim()) * 4096;
}
});
_context3.next = 33;
break;
case 25:
if (!(platform === 'win32' || platform === 'windows')) {
_context3.next = 33;
break;
}
_context3.next = 28;
return execAsync('wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Value');
case 28:
_yield$execAsync7 = _context3.sent;
_memoryInfo2 = _yield$execAsync7.stdout;
_memInfoLines2 = _memoryInfo2.split('\n');
_memInfoLines2.forEach(function (line) {
if (line.startsWith('FreePhysicalMemory=')) {
freeMemory = parseInt(line.split('=')[1].trim()) * 1024;
}
if (line.startsWith('TotalVisibleMemorySize=')) {
totalMemory = parseInt(line.split('=')[1].trim()) * 1024;
}
});
usedMemory = totalMemory - freeMemory;
case 33:
_context3.next = 38;
break;
case 35:
_context3.prev = 35;
_context3.t0 = _context3["catch"](6);
console.error('Error retrieving memory data:', _context3.t0);
case 38:
return _context3.abrupt("return", {
total: totalMemory,
free: freeMemory,
used: usedMemory,
active: usedMemory,
available: freeMemory,
buffers: buffers,
cached: cached,
slab: slab
});
case 39:
case "end":
return _context3.stop();
}
}, _callee3, null, [[6, 35]]);
}));
return function getMemoryUsage(_x2) {
return _ref3.apply(this, arguments);
};
}();
var getDiskUsage = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(platform) {
var disks, _yield$execAsync8, diskOutput, _yield$execAsync9, _diskOutput;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
disks = [];
_context4.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context4.next = 10;
break;
}
_context4.next = 5;
return execAsync('wmic logicaldisk get size,freespace,caption');
case 5:
_yield$execAsync8 = _context4.sent;
diskOutput = _yield$execAsync8.stdout;
disks = diskOutput.trim().split('\n').slice(1).map(function (line) {
var _line$trim$split = line.trim().split(/\s+/),
_line$trim$split2 = _slicedToArray(_line$trim$split, 3),
fs = _line$trim$split2[0],
freespace = _line$trim$split2[1],
size = _line$trim$split2[2];
return {
fs: fs,
size: parseInt(size, 10),
used: parseInt(size, 10) - parseInt(freespace, 10),
available: parseInt(freespace, 10),
use: (parseInt(size, 10) - parseInt(freespace, 10)) / parseInt(size, 10) * 100
};
});
_context4.next = 16;
break;
case 10:
if (!(platform === 'linux' || platform === 'darwin' || platform === 'mac')) {
_context4.next = 16;
break;
}
_context4.next = 13;
return execAsync('df -h --output=source,size,used,avail,pcent,target');
case 13:
_yield$execAsync9 = _context4.sent;
_diskOutput = _yield$execAsync9.stdout;
disks = _diskOutput.trim().split('\n').slice(1).map(function (line) {
var _line$trim$split3 = line.trim().split(/\s+/),
_line$trim$split4 = _slicedToArray(_line$trim$split3, 6),
fs = _line$trim$split4[0],
size = _line$trim$split4[1],
used = _line$trim$split4[2],
available = _line$trim$split4[3],
use = _line$trim$split4[4],
mount = _line$trim$split4[5];
return {
fs: fs,
size: size,
used: used,
available: available,
use: use,
mount: mount
};
});
case 16:
_context4.next = 21;
break;
case 18:
_context4.prev = 18;
_context4.t0 = _context4["catch"](1);
console.error('Error retrieving disk usage:', _context4.t0);
case 21:
return _context4.abrupt("return", disks);
case 22:
case "end":
return _context4.stop();
}
}, _callee4, null, [[1, 18]]);
}));
return function getDiskUsage(_x3) {
return _ref4.apply(this, arguments);
};
}();
var getWifiNetworks = /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(platform) {
var wifiNetworks, _yield$execAsync10, wifiOutput, wifiLines, currentNetwork, _yield$execAsync11, _wifiOutput, _wifiLines, _yield$execAsync12, _wifiOutput2, _wifiLines2, _currentNetwork;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
wifiNetworks = [];
_context5.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context5.next = 12;
break;
}
_context5.next = 5;
return execAsync('netsh wlan show interfaces');
case 5:
_yield$execAsync10 = _context5.sent;
wifiOutput = _yield$execAsync10.stdout;
wifiLines = wifiOutput.trim().split('\n');
currentNetwork = {};
wifiLines.forEach(function (line) {
if (line.includes('SSID') && !line.includes('BSSID')) {
currentNetwork.ssid = line.split(':').slice(1).join(':').trim();
} else if (line.includes('BSSID')) {
currentNetwork.bssid = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Signal')) {
currentNetwork.signalLevel = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Channel')) {
currentNetwork.channel = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Radio type')) {
currentNetwork.radioType = line.split(':').slice(1).join(':').trim();
} else if (line.includes('State')) {
currentNetwork.state = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Authentication')) {
currentNetwork.authentication = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Cipher')) {
currentNetwork.cipher = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Receive rate (Mbps)')) {
currentNetwork.receiveRate = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Transmit rate (Mbps)')) {
currentNetwork.transmitRate = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Physical address')) {
currentNetwork.physicalAddress = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Interface type')) {
currentNetwork.interfaceType = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Network type')) {
currentNetwork.networkType = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Band')) {
currentNetwork.band = line.split(':').slice(1).join(':').trim();
} else if (line.includes('Profile')) {
currentNetwork.profile = line.split(':').slice(1).join(':').trim();
}
if (line.trim() === '' && currentNetwork.ssid) {
wifiNetworks.push(currentNetwork);
currentNetwork = {};
}
});
_context5.next = 30;
break;
case 12:
if (!(platform === 'linux')) {
_context5.next = 21;
break;
}
_context5.next = 15;
return execAsync('nmcli -t -f active,ssid,signal dev wifi');
case 15:
_yield$execAsync11 = _context5.sent;
_wifiOutput = _yield$execAsync11.stdout;
_wifiLines = _wifiOutput.trim().split('\n');
_wifiLines.forEach(function (line) {
var _line$split = line.split(':'),
_line$split2 = _slicedToArray(_line$split, 3),
active = _line$split2[0],
ssid = _line$split2[1],
signal = _line$split2[2];
if (active === 'yes') {
wifiNetworks.push({
ssid: ssid.trim(),
signalLevel: signal.trim()
});
}
});
_context5.next = 30;
break;
case 21:
if (!(platform === 'darwin' || platform === 'mac')) {
_context5.next = 30;
break;
}
_context5.next = 24;
return execAsync('/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I');
case 24:
_yield$execAsync12 = _context5.sent;
_wifiOutput2 = _yield$execAsync12.stdout;
_wifiLines2 = _wifiOutput2.trim().split('\n');
_currentNetwork = {};
_wifiLines2.forEach(function (line) {
if (line.includes('SSID:')) {
_currentNetwork.ssid = line.split(':').slice(1).join(':').trim();
}
if (line.includes('BSSID:')) {
_currentNetwork.bssid = line.split(':').slice(1).join(':').trim();
}
if (line.includes('agrCtlRSSI:')) {
_currentNetwork.signalLevel = line.split(':').slice(1).join(':').trim();
}
if (line.includes('channel:')) {
_currentNetwork.channel = line.split(':').slice(1).join(':').trim();
}
if (line.includes('state:')) {
_currentNetwork.state = line.split(':').slice(1).join(':').trim();
}
});
if (_currentNetwork.ssid) {
wifiNetworks.push(_currentNetwork);
}
case 30:
_context5.next = 35;
break;
case 32:
_context5.prev = 32;
_context5.t0 = _context5["catch"](1);
console.error('Error retrieving Wi-Fi data:', _context5.t0);
case 35:
return _context5.abrupt("return", wifiNetworks);
case 36:
case "end":
return _context5.stop();
}
}, _callee5, null, [[1, 32]]);
}));
return function getWifiNetworks(_x4) {
return _ref5.apply(this, arguments);
};
}();
var getNetworkStats = /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(platform) {
var network, _yield$execAsync13, networkOutput, lines, stats, _yield$execAsync14, _networkOutput, _lines, _yield$execAsync15, _networkOutput2, _lines2;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
network = [];
_context6.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context6.next = 12;
break;
}
_context6.next = 5;
return execAsync('netstat -e');
case 5:
_yield$execAsync13 = _context6.sent;
networkOutput = _yield$execAsync13.stdout;
lines = networkOutput.trim().split('\n');
stats = lines.slice(4).map(function (line) {
return line.trim().split(/\s+/);
});
network = [{
iface: "Bytes",
rx_bytes: stats[0][1] ? parseInt(stats[0][1], 10) : 'N/A',
tx_bytes: stats[0][2] ? parseInt(stats[0][2], 10) : 'N/A'
}, {
iface: "Unicast",
rx_bytes: stats[1][2] ? parseInt(stats[1][2], 10) : 'N/A',
tx_bytes: stats[1][3] ? parseInt(stats[1][3], 10) : 'N/A'
}, {
iface: "Non-unicast",
rx_bytes: stats[2][2] ? parseInt(stats[2][2], 10) : 'N/A',
tx_bytes: stats[2][3] ? parseInt(stats[2][3], 10) : 'N/A'
}, {
iface: "Discards",
rx_bytes: stats[3][1] ? parseInt(stats[3][1], 10) : 'N/A',
tx_bytes: stats[3][2] ? parseInt(stats[3][2], 10) : 'N/A'
}, {
iface: "Errors",
rx_bytes: stats[4][1] ? parseInt(stats[4][1], 10) : 'N/A',
tx_bytes: stats[4][2] ? parseInt(stats[4][2], 10) : 'N/A'
}, {
iface: "Unknown",
rx_bytes: stats[5][2] ? parseInt(stats[5][2], 10) : 'N/A',
tx_bytes: 'N/A'
}];
_context6.next = 28;
break;
case 12:
if (!(platform === 'linux')) {
_context6.next = 21;
break;
}
_context6.next = 15;
return execAsync('cat /proc/net/dev');
case 15:
_yield$execAsync14 = _context6.sent;
_networkOutput = _yield$execAsync14.stdout;
_lines = _networkOutput.trim().split('\n').slice(2);
network = _lines.map(function (line) {
var _line$trim$split5 = line.trim().split(/\s+/),
_line$trim$split6 = _slicedToArray(_line$trim$split5, 10),
iface = _line$trim$split6[0],
rx_bytes = _line$trim$split6[1],
tx_bytes = _line$trim$split6[9];
return {
iface: iface,
rx_bytes: parseInt(rx_bytes, 10),
tx_bytes: parseInt(tx_bytes, 10)
};
});
_context6.next = 28;
break;
case 21:
if (!(platform === 'darwin' || platform === 'mac')) {
_context6.next = 28;
break;
}
_context6.next = 24;
return execAsync('netstat -ib');
case 24:
_yield$execAsync15 = _context6.sent;
_networkOutput2 = _yield$execAsync15.stdout;
_lines2 = _networkOutput2.trim().split('\n').slice(1);
network = _lines2.map(function (line) {
var cols = line.trim().split(/\s+/);
return {
iface: cols[0],
rx_bytes: parseInt(cols[6], 10),
tx_bytes: parseInt(cols[9], 10)
};
});
case 28:
_context6.next = 33;
break;
case 30:
_context6.prev = 30;
_context6.t0 = _context6["catch"](1);
console.error('Error retrieving network stats:', _context6.t0);
case 33:
return _context6.abrupt("return", network.map(function (stat) {
return {
iface: stat.iface,
rx_bytes: stat.rx_bytes !== 0 ? stat.rx_bytes : 'N/A',
tx_bytes: stat.tx_bytes !== 0 ? stat.tx_bytes : 'N/A'
};
}));
case 34:
case "end":
return _context6.stop();
}
}, _callee6, null, [[1, 30]]);
}));
return function getNetworkStats(_x5) {
return _ref6.apply(this, arguments);
};
}();
var getGpuUsage = /*#__PURE__*/function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(platform) {
var gpus, _yield$execAsync16, gpuModelOutput, gpuModels, i, model, _yield$execAsync17, gpuDetailsOutput, details, utilizationGpu, utilizationMemory, powerDraw, temperatureGpu, memoryUsed, memoryFree, _yield$execAsync18, _gpuModelOutput, _gpuModels, _i, _model, _yield$execAsync19, _gpuDetailsOutput, _details, _utilizationGpu, _utilizationMemory, _powerDraw, _temperatureGpu, _memoryUsed, _memoryFree;
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
gpus = [];
_context7.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context7.next = 34;
break;
}
_context7.next = 5;
return execAsync('wmic path win32_videocontroller get name');
case 5:
_yield$execAsync16 = _context7.sent;
gpuModelOutput = _yield$execAsync16.stdout;
gpuModels = gpuModelOutput.trim().split('\n').slice(1).map(function (model) {
return model.trim();
});
i = 0;
case 9:
if (!(i < gpuModels.length)) {
_context7.next = 32;
break;
}
_context7.prev = 10;
model = gpuModels[i];
_context7.next = 14;
return execAsync("nvidia-smi -i ".concat(i, " --query-gpu=utilization.gpu,utilization.memory,power.draw,temperature.gpu,memory.used,memory.free --format=csv,noheader,nounits"));
case 14:
_yield$execAsync17 = _context7.sent;
gpuDetailsOutput = _yield$execAsync17.stdout;
details = gpuDetailsOutput.trim().split(',').map(function (value) {
return value.trim();
});
utilizationGpu = details[0] ? parseFloat(details[0]) : 'N/A';
utilizationMemory = details[1] ? parseFloat(details[1]) : 'N/A';
powerDraw = details[2] ? parseFloat(details[2]) : 'N/A';
temperatureGpu = details[3] ? parseFloat(details[3]) : 'N/A';
memoryUsed = details[4] ? parseFloat(details[4]) : 'N/A';
memoryFree = details[5] ? parseFloat(details[5]) : 'N/A';
gpus.push({
model: model,
utilizationGpu: utilizationGpu,
utilizationMemory: utilizationMemory,
powerDraw: powerDraw,
temperatureGpu: temperatureGpu,
memoryUsed: memoryUsed,
memoryFree: memoryFree
});
_context7.next = 29;
break;
case 26:
_context7.prev = 26;
_context7.t0 = _context7["catch"](10);
console.error("Error retrieving GPU data for index ".concat(i, ":"), _context7.t0);
case 29:
i++;
_context7.next = 9;
break;
case 32:
_context7.next = 64;
break;
case 34:
if (!(platform === 'linux' || platform === 'darwin' || platform === 'mac')) {
_context7.next = 64;
break;
}
_context7.next = 37;
return execAsync('lspci | grep VGA');
case 37:
_yield$execAsync18 = _context7.sent;
_gpuModelOutput = _yield$execAsync18.stdout;
_gpuModels = _gpuModelOutput.trim().split('\n').map(function (line) {
return line.split('VGA compatible controller: ')[1];
});
_i = 0;
case 41:
if (!(_i < _gpuModels.length)) {
_context7.next = 64;
break;
}
_context7.prev = 42;
_model = _gpuModels[_i].trim();
_context7.next = 46;
return execAsync("nvidia-smi -i ".concat(_i, " --query-gpu=utilization.gpu,utilization.memory,power.draw,temperature.gpu,memory.used,memory.free --format=csv,noheader,nounits"));
case 46:
_yield$execAsync19 = _context7.sent;
_gpuDetailsOutput = _yield$execAsync19.stdout;
_details = _gpuDetailsOutput.trim().split(',').map(function (value) {
return value.trim();
});
_utilizationGpu = _details[0] ? parseFloat(_details[0]) : 'N/A';
_utilizationMemory = _details[1] ? parseFloat(_details[1]) : 'N/A';
_powerDraw = _details[2] ? parseFloat(_details[2]) : 'N/A';
_temperatureGpu = _details[3] ? parseFloat(_details[3]) : 'N/A';
_memoryUsed = _details[4] ? parseFloat(_details[4]) : 'N/A';
_memoryFree = _details[5] ? parseFloat(_details[5]) : 'N/A';
gpus.push({
model: _model,
utilizationGpu: _utilizationGpu,
utilizationMemory: _utilizationMemory,
powerDraw: _powerDraw,
temperatureGpu: _temperatureGpu,
memoryUsed: _memoryUsed,
memoryFree: _memoryFree
});
_context7.next = 61;
break;
case 58:
_context7.prev = 58;
_context7.t1 = _context7["catch"](42);
console.error("Error retrieving GPU data for index ".concat(_i, ":"), _context7.t1);
case 61:
_i++;
_context7.next = 41;
break;
case 64:
_context7.next = 69;
break;
case 66:
_context7.prev = 66;
_context7.t2 = _context7["catch"](1);
console.error('Error retrieving GPU data:', _context7.t2);
case 69:
return _context7.abrupt("return", gpus);
case 70:
case "end":
return _context7.stop();
}
}, _callee7, null, [[1, 66], [10, 26], [42, 58]]);
}));
return function getGpuUsage(_x6) {
return _ref7.apply(this, arguments);
};
}();
var getOsInfo = /*#__PURE__*/function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
return _context8.abrupt("return", {
platform: os.platform(),
distro: os.release(),
release: os.version(),
codename: '',
kernel: os.release(),
arch: os.arch(),
hostname: os.hostname(),
fqdn: os.hostname(),
codepage: '437',
logofile: 'windows',
serial: 'N/A',
build: os.version(),
servicepack: '0.0',
uefi: true,
hypervisor: true,
remoteSession: false
});
case 1:
case "end":
return _context8.stop();
}
}, _callee8);
}));
return function getOsInfo() {
return _ref8.apply(this, arguments);
};
}();
var getProcessInfo = /*#__PURE__*/function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(platform) {
var processes, _yield$execAsync20, processOutput, _yield$execAsync21, _processOutput;
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
processes = [];
_context9.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context9.next = 10;
break;
}
_context9.next = 5;
return execAsync('tasklist /fo csv');
case 5:
_yield$execAsync20 = _context9.sent;
processOutput = _yield$execAsync20.stdout;
processes = processOutput.trim().split('\n').slice(1).map(function (line) {
var _line$split$map = line.split('","').map(function (str) {
return str.replace(/"/g, '');
}),
_line$split$map2 = _slicedToArray(_line$split$map, 5),
imageName = _line$split$map2[0],
pid = _line$split$map2[1],
sessionName = _line$split$map2[2],
sessionNum = _line$split$map2[3],
memUsage = _line$split$map2[4];
return {
name: imageName,
pid: parseInt(pid, 10),
memory: memUsage.replace(/,/g, '').replace(' K', '').replace('\r', '') + ' K'
};
});
_context9.next = 16;
break;
case 10:
if (!(platform === 'linux' || platform === 'darwin' || platform === 'mac')) {
_context9.next = 16;
break;
}
_context9.next = 13;
return execAsync('ps aux --sort=-%mem');
case 13:
_yield$execAsync21 = _context9.sent;
_processOutput = _yield$execAsync21.stdout;
processes = _processOutput.trim().split('\n').slice(1).map(function (line) {
var cols = line.trim().split(/\s+/);
return {
name: cols[10],
pid: parseInt(cols[1], 10),
memory: cols[5] + ' KB'
};
});
case 16:
_context9.next = 21;
break;
case 18:
_context9.prev = 18;
_context9.t0 = _context9["catch"](1);
console.error('Error retrieving process info:', _context9.t0);
case 21:
_context9.t1 = processes.length;
_context9.next = 24;
return getRunningProcesses(platform);
case 24:
_context9.t2 = _context9.sent;
_context9.t3 = processes;
return _context9.abrupt("return", {
all: _context9.t1,
running: _context9.t2,
processes: _context9.t3
});
case 27:
case "end":
return _context9.stop();
}
}, _callee9, null, [[1, 18]]);
}));
return function getProcessInfo(_x7) {
return _ref9.apply(this, arguments);
};
}();
var getRunningProcesses = /*#__PURE__*/function () {
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(platform) {
var running, _yield$execAsync22, processOutput, lines, _yield$execAsync23, runningOutput;
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
running = 'N/A';
_context10.prev = 1;
if (!(platform === 'win32' || platform === 'windows')) {
_context10.next = 11;
break;
}
_context10.next = 5;
return execAsync('tasklist /fo csv');
case 5:
_yield$execAsync22 = _context10.sent;
processOutput = _yield$execAsync22.stdout;
lines = processOutput.trim().split('\n').slice(1);
running = lines.filter(function (line) {
return line.includes('Running');
}).length;
_context10.next = 17;
break;
case 11:
if (!(platform === 'linux' || platform === 'darwin' || platform === 'mac')) {
_context10.next = 17;
break;
}
_context10.next = 14;
return execAsync('ps aux | grep " R" | wc -l');
case 14:
_yield$execAsync23 = _context10.sent;
runningOutput = _yield$execAsync23.stdout;
running = parseInt(runningOutput.trim(), 10);
case 17:
_context10.next = 22;
break;
case 19:
_context10.prev = 19;
_context10.t0 = _context10["catch"](1);
console.error('Error retrieving running processes:', _context10.t0);
case 22:
return _context10.abrupt("return", running);
case 23:
case "end":
return _context10.stop();
}
}, _callee10, null, [[1, 19]]);
}));
return function getRunningProcesses(_x8) {
return _ref10.apply(this, arguments);
};
}();
var getUptime = function getUptime() {
return os.uptime();
};
module.exports = {
getCoreLoad: getCpuCores,
getCpuUsage: getCpuUsage,
getMemoryUsage: getMemoryUsage,
getDiskUsage: getDiskUsage,
getWifiNetworks: getWifiNetworks,
getNetworkStats: getNetworkStats,
getGpuUsage: getGpuUsage,
getOsInfo: getOsInfo,
getProcessInfo: getProcessInfo,
getUptime: getUptime
};
;