node compatibility fixes
This commit is contained in:
parent
153e1e6f91
commit
915588fd9d
10
lib/cpu.js
10
lib/cpu.js
@ -1238,7 +1238,7 @@ function getCpuCurrentSpeedSync() {
|
||||
const cores = [];
|
||||
const speeds = [];
|
||||
|
||||
if (cpus?.length && Object.prototype.hasOwnProperty.call(cpus[0], 'speed')) {
|
||||
if (cpus && count.length && Object.prototype.hasOwnProperty.call(cpus[0], 'speed')) {
|
||||
for (let i in cpus) {
|
||||
speeds.push(cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10);
|
||||
}
|
||||
@ -1256,7 +1256,7 @@ function getCpuCurrentSpeedSync() {
|
||||
}
|
||||
}
|
||||
|
||||
if (speeds?.length) {
|
||||
if (speeds && speeds.length) {
|
||||
try {
|
||||
for (const i in speeds) {
|
||||
avgFreq = avgFreq + speeds[i];
|
||||
@ -1545,7 +1545,7 @@ function cpuTemperature(callback) {
|
||||
if (result.max) {
|
||||
result.max = Math.round(result.max * 100) / 100;
|
||||
}
|
||||
if (result?.cores.length) {
|
||||
if (result && result.cores && result.cores.length) {
|
||||
for (let i = 0; i < result.cores.length; i++) {
|
||||
result.cores[i] = Math.round(result.cores[i] * 100) / 100;
|
||||
}
|
||||
@ -1565,7 +1565,7 @@ function cpuTemperature(callback) {
|
||||
// round to 2 digits
|
||||
result.chipset = Math.round(res.soc * 100) / 100;
|
||||
}
|
||||
if (res?.cpuDieTemps.length) {
|
||||
if (res && res.cpuDieTemps.length) {
|
||||
for (const temp of res.cpuDieTemps) {
|
||||
result.cores.push(Math.round(temp * 100) / 100);
|
||||
}
|
||||
@ -2204,7 +2204,7 @@ function getFullLoad() {
|
||||
|
||||
let result = 0;
|
||||
|
||||
if (cpus?.length) {
|
||||
if (cpus && cpus.length) {
|
||||
for (let i = 0, len = cpus.length; i < len; i++) {
|
||||
const cpu = cpus[i].times;
|
||||
totalUser += cpu.user;
|
||||
|
||||
@ -75,7 +75,7 @@ function fsSize(drive, callback) {
|
||||
if (stdout.toString().toLowerCase().indexOf('filesystem')) {
|
||||
let removeLines = 0;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i]?.toLowerCase().startsWith('filesystem')) {
|
||||
if (lines[i] && lines[i].toLowerCase().startsWith('filesystem')) {
|
||||
removeLines = i;
|
||||
}
|
||||
}
|
||||
@ -491,7 +491,7 @@ function raidMatchLinux(data) {
|
||||
element.label = mdData.label; // <- assign label info
|
||||
element.uuid = mdData.uuid; // <- assign uuid info
|
||||
|
||||
if (mdData.members?.length && mdData.raid === element.type) {
|
||||
if (mdData && mdData.members && mdData.members.length && mdData.raid === element.type) {
|
||||
result = result.map((blockdevice) => {
|
||||
if (blockdevice.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) {
|
||||
blockdevice.group = element.name;
|
||||
@ -778,7 +778,7 @@ function calcFsSpeed(rx, wx) {
|
||||
ms: 0
|
||||
};
|
||||
|
||||
if (_fs_speed?.ms) {
|
||||
if (_fs_speed && _fs_speed.ms) {
|
||||
result.rx = rx;
|
||||
result.wx = wx;
|
||||
result.tx = result.rx + result.wx;
|
||||
@ -829,7 +829,7 @@ function fsStats(callback) {
|
||||
|
||||
let rx = 0;
|
||||
let wx = 0;
|
||||
if ((_fs_speed && !_fs_speed.ms) || (_fs_speed?.ms && Date.now() - _fs_speed.ms >= 500)) {
|
||||
if ((_fs_speed && !_fs_speed.ms) || (_fs_speed && _fs_speed.ms && Date.now() - _fs_speed.ms >= 500)) {
|
||||
if (_linux) {
|
||||
// exec("df -k | grep /dev/", function(error, stdout) {
|
||||
const procLsblk = exec('lsblk -r 2>/dev/null | grep /', { maxBuffer: 1024 * 1024 }, (error, stdout) => {
|
||||
@ -951,7 +951,7 @@ function calcDiskIO(rIO, wIO, rWaitTime, wWaitTime, tWaitTime) {
|
||||
tWaitPercent: null,
|
||||
ms: 0
|
||||
};
|
||||
if (_disk_io?.ms) {
|
||||
if (_disk_io && _disk_io.ms) {
|
||||
result.rIO = rIO;
|
||||
result.wIO = wIO;
|
||||
result.tIO = rIO + wIO;
|
||||
@ -1033,7 +1033,7 @@ function disksIO(callback) {
|
||||
let wWaitTime = 0;
|
||||
let tWaitTime = 0;
|
||||
|
||||
if ((_disk_io && !_disk_io.ms) || (_disk_io?.ms && Date.now() - _disk_io.ms >= 500)) {
|
||||
if ((_disk_io && !_disk_io.ms) || (_disk_io && _disk_io.ms && Date.now() - _disk_io.ms >= 500)) {
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
// prints Block layer statistics for all mounted volumes
|
||||
// var cmd = "for mount in `lsblk | grep / | sed -r 's/│ └─//' | cut -d ' ' -f 1`; do cat /sys/block/$mount/stat | sed -r 's/ +/;/g' | sed -r 's/^;//'; done";
|
||||
@ -1295,7 +1295,7 @@ function diskLayout(callback) {
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i].BSDName === diskBSDName) {
|
||||
result[i].smartStatus = disk.smart_status.passed ? 'Ok' : disk.smart_status.passed === false ? 'Predicted Failure' : 'unknown';
|
||||
if (disk.temperature?.current) {
|
||||
if (disk.temperature && disk.temperature.current) {
|
||||
result[i].temperature = disk.temperature.current;
|
||||
}
|
||||
result[i].smartData = disk;
|
||||
@ -1581,7 +1581,7 @@ function diskLayout(callback) {
|
||||
if (util.smartMonToolsInstalled()) {
|
||||
try {
|
||||
const smartDev = JSON.parse(execSync('smartctl --scan -j').toString());
|
||||
if (smartDev?.devices && smartDev.devices.length > 0) {
|
||||
if (smartDev && smartDev.devices && smartDev.devices.length > 0) {
|
||||
smartDev.devices.forEach((dev) => {
|
||||
workload.push(execPromiseSave(`smartctl -j -a ${dev.name}`, util.execOptsWin));
|
||||
});
|
||||
@ -1661,8 +1661,9 @@ function diskLayout(callback) {
|
||||
const serialNum = smartData.serial_number;
|
||||
const i = util.findObjectByKey(result, 'serialNum', serialNum);
|
||||
if (i !== -1) {
|
||||
result[i].smartStatus = smartData.smart_status?.passed ? 'Ok' : smartData.smart_status && smartData.smart_status.passed === false ? 'Predicted Failure' : 'unknown';
|
||||
if (smartData.temperature?.current) {
|
||||
result[i].smartStatus =
|
||||
smartData.smart_status && smartData.smart_status.passed ? 'Ok' : smartData.smart_status && smartData.smart_status.passed === false ? 'Predicted Failure' : 'unknown';
|
||||
if (smartData.temperature && smartData.temperature.current) {
|
||||
result[i].temperature = smartData.temperature.current;
|
||||
}
|
||||
result[i].smartData = smartData;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user