From 8e783f2cf8eec743d559632933c2dd5c682428d0 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 6 May 2020 12:16:47 +0200 Subject: [PATCH] cpu() fix BSD, networkStats() fix BSD --- .gitignore | 1 - CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/cpu.js | 8 ++++---- lib/network.js | 8 ++++---- tslint.json | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 tslint.json diff --git a/.gitignore b/.gitignore index bdb756c..b66f952 100644 --- a/.gitignore +++ b/.gitignore @@ -65,5 +65,4 @@ yarn.lock test/ dist/ tsconfig.json -tslint.json typings.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 10d5ece..582321e 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.24.2 | 2020-05-06 | `cpu()` fix (BSD), `networkStats()` fix BSD | | 4.24.1 | 2020-05-03 | `processes()` fix parsing command and params | | 4.24.0 | 2020-05-01 | `networkInterfaces()` added subnet mask ip4 and ip6 | | 4.23.10 | 2020-05-01 | `cpuTemperature()` optimized parsing linux | diff --git a/docs/history.html b/docs/history.html index a1d7205..93bc0a8 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.24.2 + 2020-05-06 + cpu() fix BSD, networkStats() fix BSD + 4.24.1 2020-05-03 diff --git a/docs/index.html b/docs/index.html index b904529..f1323ad 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.24.1
+
Current Version: 4.24.2
diff --git a/lib/cpu.js b/lib/cpu.js index c532c57..4507a4a 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -506,12 +506,12 @@ function getCpu() { let modelline = ''; let lines = []; if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model; - exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; dmidecode -t 7 2>/dev/null; unset LC_ALL', function (error, stdout) { + exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) { let cache = []; if (!error) { const data = stdout.toString().split('# dmidecode'); - const processor = data.length > 0 ? data[1] : ''; - cache = data.length > 1 ? data[2].split('Cache Information') : []; + const processor = data.length > 1 ? data[1] : ''; + cache = data.length > 2 ? data[2].split('Cache Information') : []; lines = processor.split('\n'); } @@ -767,7 +767,7 @@ function cpuTemperature(callback) { for (let i = 0; i < temps.length; i++) { if (temps[i] && (labels[i] === undefined || (labels[i] && labels[i].toLowerCase().startsWith('core')))) { result.cores.push(Math.round(parseInt(temps[i], 10) / 100) / 10); - } else if (temps[i] && labels[i] && result.main === -1) { + } else if (temps[i] && labels[i] && result.main === -1) { result.main = Math.round(parseInt(temps[i], 10) / 100) / 10; } } diff --git a/lib/network.js b/lib/network.js index 342639b..d379d41 100644 --- a/lib/network.js +++ b/lib/network.js @@ -1081,11 +1081,11 @@ function networkStatsSingle(iface) { const line = lines[i].replace(/ +/g, ' ').split(' '); if (line && line[0] && line[7] && line[10]) { rx_bytes = rx_bytes + parseInt(line[7]); - if (stats[6].trim() !== '-') { rx_dropped = rx_dropped + parseInt(stats[6]); } - if (stats[5].trim() !== '-') { rx_errors = rx_errors + parseInt(stats[5]); } + if (line[6].trim() !== '-') { rx_dropped = rx_dropped + parseInt(line[6]); } + if (line[5].trim() !== '-') { rx_errors = rx_errors + parseInt(line[5]); } tx_bytes = tx_bytes + parseInt(line[10]); - if (stats[12].trim() !== '-') { tx_dropped = tx_dropped + parseInt(stats[12]); } - if (stats[9].trim() !== '-') { tx_errors = tx_errors + parseInt(stats[9]); } + if (line[12].trim() !== '-') { tx_dropped = tx_dropped + parseInt(line[12]); } + if (line[9].trim() !== '-') { tx_errors = tx_errors + parseInt(line[9]); } operstate = 'up'; } } diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..6783f80 --- /dev/null +++ b/tslint.json @@ -0,0 +1,51 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "no-trailing-whitespace": false, + "quotemark": [ + false + ], + "comment-format": [ + false + ], + "member-access": false, + "whitespace": [ + true + ], + "object-literal-shorthand": false, + "ordered-imports": [ + false + ], + "one-line": [ + false + ], + "max-line-length": [ + true, + 140 + ], + "only-arrow-functions": [ + false + ], + "object-literal-sort-keys": [ + false + ], + "array-type": [ + false + ], + "variable-name": [ + false + ], + "interface-name": [ + false + ], + "one-variable-per-declaration": [ + false + ], + "no-console": false + }, + "rulesDirectory": [] +}