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..fd017df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ 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 | | 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/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..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:

diff --git a/docs/history.html b/docs/history.html index a1d7205..10ba2f8 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,21 @@ + + + + + + + + + + + + + diff --git a/docs/index.html b/docs/index.html index b904529..c6ce963 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.24.1
+
Current Version: 4.25.1
diff --git a/lib/cpu.js b/lib/cpu.js index f002a1f..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'); } 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 3cb9205..9db5ec1 100755 --- a/lib/index.js +++ b/lib/index.js @@ -315,6 +315,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 // ---------------------------------------------------------------------------------- @@ -381,3 +415,5 @@ exports.vboxInfo = vbox.vboxInfo; exports.getStaticData = getStaticData; exports.getDynamicData = getDynamicData; exports.getAllData = getAllData; +exports.get = get; + 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/package.json b/package.json index f038c41..241b62e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "systeminformation", - "version": "4.24.1", + "version": "4.25.1", "description": "Simple system and OS information library", "license": "MIT", "author": "Sebastian Hildebrandt (https://plus-innovations.com)", 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": [] +}
4.25.12020-05-07get() minor bounds test fix, updated docs /td> +
4.25.02020-05-07get() added function to get partial system info /td> +
4.24.22020-05-06cpu() fix BSD, networkStats() fix BSD
4.24.1 2020-05-03