diff --git a/CHANGELOG.md b/CHANGELOG.md index 64eab88..5ae9784 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.23.7 | 2020-04-26 | `getCpuCurrentSpeedSync()` workarround fix | | 4.23.6 | 2020-04-25 | `networkGatewayDefault()` bug fix no interfaces | | 4.23.5 | 2020-04-20 | updated docs | | 4.23.4 | 2020-04-20 | `users()` optimized parseDateTime function | diff --git a/docs/history.html b/docs/history.html index e6899a3..9ce68b4 100644 --- a/docs/history.html +++ b/docs/history.html @@ -84,8 +84,13 @@ - 4.23.4 - 2020-04-20 + 4.23.7 + 2020-04-2& + getCpuCurrentSpeedSync() workarround fix + + + 4.23.6 + 2020-04-25 networkGatewayDefault() bugfix no interfaces diff --git a/docs/index.html b/docs/index.html index 22b77d5..4a94af0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.23.6
+
Current Version: 4.23.7
diff --git a/lib/cpu.js b/lib/cpu.js index ed8901d..8e0dc8d 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -695,7 +695,7 @@ function getCpuCurrentSpeedSync() { let avgFreq = 0; let cores = []; - if (cpus.length) { + if (cpus && cpus.length) { for (let i in cpus) { if ({}.hasOwnProperty.call(cpus, i)) { avgFreq = avgFreq + cpus[i].speed; @@ -1142,7 +1142,7 @@ function getLoad() { let totalIrq = 0; let totalIdle = 0; let cores = []; - _corecount = cpus.length; + _corecount = (cpus && cpus.length) ? cpus.length : 1; for (let i = 0; i < _corecount; i++) { const cpu = cpus[i].times; @@ -1292,17 +1292,23 @@ function getFullLoad() { let totalIrq = 0; let totalIdle = 0; - for (let i = 0, len = cpus.length; i < len; i++) { - const cpu = cpus[i].times; - totalUser += cpu.user; - totalSystem += cpu.sys; - totalNice += cpu.nice; - totalIrq += cpu.irq; - totalIdle += cpu.idle; - } - let totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser; - let result = (totalTicks - totalIdle) / totalTicks * 100.0; + let result = 0; + if (cpus && cpus.length) { + for (let i = 0, len = cpus.length; i < len; i++) { + const cpu = cpus[i].times; + totalUser += cpu.user; + totalSystem += cpu.sys; + totalNice += cpu.nice; + totalIrq += cpu.irq; + totalIdle += cpu.idle; + } + let totalTicks = totalIdle + totalIrq + totalNice + totalSystem + totalUser; + result = (totalTicks - totalIdle) / totalTicks * 100.0; + + } else { + result = 0; + } resolve(result); }); });