extended getDynamicData() (windows), updated docs

This commit is contained in:
Sebastian Hildebrandt 2017-08-21 13:37:51 +02:00
parent 350506dd4d
commit eb03599e18
3 changed files with 78 additions and 52 deletions

View File

@ -98,6 +98,7 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.26.0 | 2017-08-21 | extended `getDynamicData()` (windows), updated docs |
| 3.25.1 | 2017-08-07 | updated docs |
| 3.25.0 | 2017-08-07 | improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` |
| 3.24.0 | 2017-08-05 | extended windows support `networkStats()`, `networkConnections()` |

View File

@ -22,7 +22,7 @@ $ npm install systeminformation --save
All functions (except `version` and `time`) are implemented as asynchronous functions. Here a small example how to use them:
```
```js
const si = require('systeminformation');
// callback style
@ -36,11 +36,21 @@ si.cpu()
.then(data => console.log(data))
.catch(error => console.error(error));
// full async / await example (node >= 7.6)
async function cpu() {
try {
const data = await si.cpu();
console.log(data)
} catch {
console.log(e)
}
}
```
## News and Changes
### Latest Activity
- Version 3.26.0: extended `getDynamicData()` (windows), updated docs
- Version 3.25.0: improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()`
- Version 3.24.0: extended windows support `networkStats()`, `networkConnections()`
- Version 3.23.0: added `memLayout`, `diskLayout`, extended windows support (`inetChecksite`)
@ -407,8 +417,8 @@ Remember: all functions (except `version` and `time`) are implemented as asynchr
**Callback Style**
```
var si = require('systeminformation');
```js
const si = require('systeminformation');
si.networkStats('eth1', function(data) {
console.log('Network Interface Stats (eth1):');
@ -426,7 +436,9 @@ si.networkStats('eth1', function(data) {
When omitting callback parameter (cb), then you can use all function in a promise oriented way. All functions (exept of `version` and `time`) are returning a promis, that you can consume:
```
```js
const si = require('systeminformation');
si.networkStats('eth1')
.then(data => {
console.log('Network Interface Stats (eth1):');
@ -439,6 +451,31 @@ si.networkStats('eth1')
.catch(error => console.error(error));
```
### Async / Await
**Using async / await** (available since node v7.6)
Since node 7.6 you can ylso use the `async` / `await pattern. The example would then loog like this:
```js
const si = require('systeminformation');
async function network() {
try {
const data = await si.networkStats('eth1')
console.log(`Network Interface Stats (eth1):
- is up: ${data.operstate}
- RX bytes overall: ${data.rx}
- TX bytes overall: ${data.tx}
- RX bytes/sec: ${data.rx_sec}
- TX bytes/sec: ${data.tx_sec}`)
} catch (e) {
console.log(e)
}
}
```
## Known Issues
#### OSX - Temperature Sensor

View File

@ -130,35 +130,29 @@ function getStaticData(callback) {
data.version = version();
system().then(res => {
data.system = res;
osInfo.osInfo().then(res => {
data.os = res;
osInfo.versions().then(res => {
data.versions = res;
cpu.cpu().then(res => {
data.cpu = res;
cpu.cpuFlags().then(res => {
data.cpu.flags = res;
graphics.graphics().then(res => {
data.graphics = res;
network.networkInterfaces().then(res => {
data.net = res;
mem.memLayout().then(res => {
data.memLayout = res;
filesystem.diskLayout().then(res => {
data.diskLayout = res;
if (callback) { callback(data) }
resolve(data);
})
})
})
})
})
})
})
})
})
Promise.all([
system(),
osInfo.osInfo(),
osInfo.versions(),
cpu.cpu(),
cpu.cpuFlags(),
graphics.graphics(),
network.networkInterfaces(),
mem.memLayout(),
filesystem.diskLayout()
]).then(res => {
data.system = res[0];
data.os = res[1];
data.versions = res[2];
data.cpu = res[3];
data.cpu.flags = res[4];
data.graphics = res[5];
data.net = res[6];
data.memLayout = res[7];
data.diskLayout = res[8];
if (callback) { callback(data) }
resolve(data);
});
});
});
}
@ -190,7 +184,7 @@ function getDynamicData(srv, iface, callback) {
// use closure to track ƒ completion
let functionProcessed = (function () {
let totalFunctions = (_windows ? 7 : 14);
let totalFunctions = (_windows ? 10 : 14);
return function () {
if (--totalFunctions === 0) {
@ -241,31 +235,25 @@ function getDynamicData(srv, iface, callback) {
});
}
if (!_windows) {
cpu.currentLoad().then(res => {
data.currentLoad = res;
functionProcessed();
});
}
cpu.currentLoad().then(res => {
data.currentLoad = res;
functionProcessed();
});
cpu.cpuTemperature().then(res => {
data.temp = res;
functionProcessed();
});
if (!_windows) {
network.networkStats(iface).then(res => {
data.networkStats = res;
functionProcessed();
});
}
network.networkStats(iface).then(res => {
data.networkStats = res;
functionProcessed();
});
if (!_windows) {
network.networkConnections().then(res => {
data.networkConnections = res;
functionProcessed();
});
}
network.networkConnections().then(res => {
data.networkConnections = res;
functionProcessed();
});
mem.mem().then(res => {
data.mem = res;