From 8e783f2cf8eec743d559632933c2dd5c682428d0 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 6 May 2020 12:16:47 +0200 Subject: [PATCH 1/7] 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": [] +} From ba3469db0c3567ba2c31f578d57d209b6ebc114f Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 6 May 2020 12:16:55 +0200 Subject: [PATCH 2/7] 4.24.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f038c41..05e20dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "systeminformation", - "version": "4.24.1", + "version": "4.24.2", "description": "Simple system and OS information library", "license": "MIT", "author": "Sebastian Hildebrandt (https://plus-innovations.com)", From 8fa0d3065a748c70b3cbd5d0ac9b1a4125f41eab Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 07:33:34 +0200 Subject: [PATCH 3/7] get() added function to get partial system info --- CHANGELOG.md | 1 + README.md | 3 ++- docs/general.html | 56 +++++++++++++++++++++++++++++++++++++++++++++++ docs/history.html | 5 +++++ docs/index.html | 2 +- lib/index.d.ts | 1 + lib/index.js | 36 ++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 582321e..d6cfb74 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.25.0 | 2020-05-07 | `get()` added function to get partial system info | | 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 | diff --git a/README.md b/README.md index ae3e3e5..96e8ed8 100644 --- a/README.md +++ b/README.md @@ -87,13 +87,13 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.25.0: `get()` added function to get partial system info - Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6 - Version 4.23.0: `versions()` added param to specify which program/lib versions to detect - Version 4.22.0: `services()` added pids (windows) - Version 4.21.0: added npx copmpatibility - Version 4.20.0: `battery()` added designcapacity, voltage, unit - Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup) -- Version 4.18.0: `networkInterfaces()` added dhcp for mac os, added dhcp linux fallback - ... You can find all changes here: [detailed changelog][changelog-url] @@ -639,6 +639,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | si.getStaticData(cb) | {...} | X | X | X | X | X | all static data at once | | si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | | si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | +| si.get(valueObject,cb) | {...} | X | X | X | X | X | get partial system info data at once
In valueObject you can define
all values, you want to get back
(see documentation for details) | ### cb: Asynchronous Function Calls (callback) diff --git a/docs/general.html b/docs/general.html index 765893f..2c741fe 100644 --- a/docs/general.html +++ b/docs/general.html @@ -174,6 +174,62 @@ X all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces + + si.get(valueObject,cb) + {...} + X + X + X + X + X + get partial data at once
Specify return object for all
values that should be returned.
See example: + + + + +
Example
+
const si = require('systeminformation');
+
+// define all values, you want to get back
+valueObject = {
+  cpu: '*',
+  osInfo: 'platform, release',
+  system: 'model, manufacturer'
+}
+
+si.get(valueObject).then(data => console.log(data));
+
+{
+  cpu: {
+    manufacturer: 'Intel®',
+    brand: 'Core™ i7-8569U',
+    vendor: 'GenuineIntel',
+    family: '6',
+    model: '142',
+    stepping: '10',
+    revision: '',
+    voltage: '',
+    speed: '2.80',
+    speedmin: '2.80',
+    speedmax: '2.80',
+    governor: '',
+    cores: 8,
+    physicalCores: 4,
+    processors: 1,
+    socket: '',
+    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 8388608 }
+  },
+  osInfo: {
+    platform: 'darwin',
+    release: '10.15.4'
+  },
+  system: {
+    model: 'MacBookPro15,2',
+    manufacturer: 'Apple Inc.'
+  }
+}
+
+

Static data is all hardware related (or more or less constant) data like system, baseboard, bios, OS, versions, cpu, network interfces, memory and disk layout

diff --git a/docs/history.html b/docs/history.html index 93bc0a8..53de7ba 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.25.0 + 2020-05-07 + get() added function to get partial system info /td> + 4.24.2 2020-05-06 diff --git a/docs/index.html b/docs/index.html index f1323ad..2e24136 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.24.2
+
Current Version: 4.25.0
diff --git a/lib/index.d.ts b/lib/index.d.ts index e0d0518..e0a9505 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -681,3 +681,4 @@ export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any): export function getStaticData(cb?: (data: Systeminformation.StaticData) => any): Promise; export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) => any): Promise; export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise; +export function get(valuesObject: any, cb?: (data: any) => any): Promise; diff --git a/lib/index.js b/lib/index.js index ac6ffff..f2dd0cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -308,6 +308,40 @@ function getAllData(srv, iface, callback) { }); } +function get(valueObject, callback) { + return new Promise((resolve) => { + process.nextTick(() => { + const allPromises = Object.keys(valueObject) + .filter(func => ({}.hasOwnProperty.call(exports, func))) + .map(func => exports[func]()); + + Promise.all(allPromises).then(data => { + const result = {}; + let i = 0; + for (let key in valueObject) { + if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length >= i) { + if (valueObject[key] === '*' || valueObject[key] === 'all') { + result[key] = data[i]; + } else { + const keys = valueObject[key].replace(/,/g, ' ').replace(/ +/g, ' ').split(' '); + const partialRes = {}; + keys.forEach(k => { + if ({}.hasOwnProperty.call(data[i], k)) { + partialRes[k] = data[i][k]; + } + }); + result[key] = partialRes; + } + i++; + } + } + if (callback) { callback(result); } + resolve(result); + }); + }); + }); +} + // ---------------------------------------------------------------------------------- // export all libs // ---------------------------------------------------------------------------------- @@ -374,3 +408,5 @@ exports.vboxInfo = vbox.vboxInfo; exports.getStaticData = getStaticData; exports.getDynamicData = getDynamicData; exports.getAllData = getAllData; +exports.get = get; + From e44e13e3c6bc303c66039ec851c97be92e3f782b Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 07:33:51 +0200 Subject: [PATCH 4/7] 4.25.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05e20dd..739f6bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "systeminformation", - "version": "4.24.2", + "version": "4.25.0", "description": "Simple system and OS information library", "license": "MIT", "author": "Sebastian Hildebrandt (https://plus-innovations.com)", From bcdbf99012f27a955e63784698b3751eeff5279a Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 10:49:39 +0200 Subject: [PATCH 5/7] updated docs --- docs/general.html | 133 ++++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 57 deletions(-) diff --git a/docs/general.html b/docs/general.html index 2c741fe..f414e74 100644 --- a/docs/general.html +++ b/docs/general.html @@ -46,7 +46,7 @@
General
-

In this section you will learn how to get general systeminformation data. We will also cover the "get-all" functions to get all data at once.

+

In this section you will learn how to get general systeminformation data. We will also cover the "get" and "get-all" functions to get partial or all data with one single call.

For function reference and examples we assume, that we imported systeminformation as follows:

const si = require('systeminformation');

Lib-Version and Time/Timezone

@@ -128,6 +128,81 @@

Keep in mind, that there is another function si.versions() that will return versions of other system libraries and software packages

+

Get Defined Result Object

+

Normally you would call each of the functions (where you want to have detailed system information) seperately. The docs pages contain a full reference (with examples) for each available function. But there is also another really handy way to get a self-defined information object in one single call:

+

The si.get() function is an alternative, where you can obtain several system information data in one call. You can define a json object which represents the data structure you are expecting and the si.get() call will then return all of the requested data in a single result object

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FunctionResult objectLinuxBSDMacWinSunComments
si.get(valueObject,cb){...}XXXXXget partial data at once
Specify return object for all
values that should be returned:
+
Example
+
const si = require('systeminformation');
+
+// define all values, you want to get back
+valueObject = {
+  cpu: '*',
+  osInfo: 'platform, release',
+  system: 'model, manufacturer'
+}
+
+si.get(valueObject).then(data => console.log(data));
+
+{
+  cpu: {
+    manufacturer: 'Intel®',
+    brand: 'Core™ i7-8569U',
+    vendor: 'GenuineIntel',
+    family: '6',
+    model: '142',
+    stepping: '10',
+    revision: '',
+    voltage: '',
+    speed: '2.80',
+    speedmin: '2.80',
+    speedmax: '2.80',
+    governor: '',
+    cores: 8,
+    physicalCores: 4,
+    processors: 1,
+    socket: '',
+    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 8388608 }
+  },
+  osInfo: {
+    platform: 'darwin',
+    release: '10.15.4'
+  },
+  system: {
+    model: 'MacBookPro15,2',
+    manufacturer: 'Apple Inc.'
+  }
+}
+
+
+

The key names of the valueObject must be exactly the same as the representing function within systeminformation.

Get All At Once

The following three functions si.getStaticData(), si.getDynamicData() and si.getAllData() will return most of the available data in a single result object:

@@ -174,62 +249,6 @@ - - - - - - - - - - - - -
X all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces
si.get(valueObject,cb){...}XXXXXget partial data at once
Specify return object for all
values that should be returned.
See example:
-
Example
-
const si = require('systeminformation');
-
-// define all values, you want to get back
-valueObject = {
-  cpu: '*',
-  osInfo: 'platform, release',
-  system: 'model, manufacturer'
-}
-
-si.get(valueObject).then(data => console.log(data));
-
-{
-  cpu: {
-    manufacturer: 'Intel®',
-    brand: 'Core™ i7-8569U',
-    vendor: 'GenuineIntel',
-    family: '6',
-    model: '142',
-    stepping: '10',
-    revision: '',
-    voltage: '',
-    speed: '2.80',
-    speedmin: '2.80',
-    speedmax: '2.80',
-    governor: '',
-    cores: 8,
-    physicalCores: 4,
-    processors: 1,
-    socket: '',
-    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 8388608 }
-  },
-  osInfo: {
-    platform: 'darwin',
-    release: '10.15.4'
-  },
-  system: {
-    model: 'MacBookPro15,2',
-    manufacturer: 'Apple Inc.'
-  }
-}
-
-

Static data is all hardware related (or more or less constant) data like system, baseboard, bios, OS, versions, cpu, network interfces, memory and disk layout

From d1e2146732114c7b6ac2d5e71ef3df6b6aba3892 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 10:56:49 +0200 Subject: [PATCH 6/7] get() minor bounds test fix, updated docs --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/index.js | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6cfb74..fd017df 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.25.1 | 2020-05-07 | `get()` minor bounds test fix, updated docs | | 4.25.0 | 2020-05-07 | `get()` added function to get partial system info | | 4.24.2 | 2020-05-06 | `cpu()` fix (BSD), `networkStats()` fix BSD | | 4.24.1 | 2020-05-03 | `processes()` fix parsing command and params | diff --git a/docs/history.html b/docs/history.html index 53de7ba..10ba2f8 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.25.1 + 2020-05-07 + get() minor bounds test fix, updated docs /td> + 4.25.0 2020-05-07 diff --git a/docs/index.html b/docs/index.html index 2e24136..c6ce963 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.25.0
+
Current Version: 4.25.1
diff --git a/lib/index.js b/lib/index.js index f2dd0cf..7542b92 100644 --- a/lib/index.js +++ b/lib/index.js @@ -319,7 +319,7 @@ function get(valueObject, callback) { const result = {}; let i = 0; for (let key in valueObject) { - if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length >= i) { + if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length > i) { if (valueObject[key] === '*' || valueObject[key] === 'all') { result[key] = data[i]; } else { From b1795606aea4009ac43b792b9357d3a0f8048766 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 10:56:58 +0200 Subject: [PATCH 7/7] 4.25.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 739f6bd..241b62e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "systeminformation", - "version": "4.25.0", + "version": "4.25.1", "description": "Simple system and OS information library", "license": "MIT", "author": "Sebastian Hildebrandt (https://plus-innovations.com)",