extended getDynamicData() (windows), updated docs
This commit is contained in:
parent
350506dd4d
commit
eb03599e18
@ -98,6 +98,7 @@ Other changes
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 3.26.0 | 2017-08-21 | extended `getDynamicData()` (windows), updated docs |
|
||||||
| 3.25.1 | 2017-08-07 | 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.25.0 | 2017-08-07 | improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` |
|
||||||
| 3.24.0 | 2017-08-05 | extended windows support `networkStats()`, `networkConnections()` |
|
| 3.24.0 | 2017-08-05 | extended windows support `networkStats()`, `networkConnections()` |
|
||||||
|
|||||||
45
README.md
45
README.md
@ -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:
|
All functions (except `version` and `time`) are implemented as asynchronous functions. Here a small example how to use them:
|
||||||
|
|
||||||
```
|
```js
|
||||||
const si = require('systeminformation');
|
const si = require('systeminformation');
|
||||||
|
|
||||||
// callback style
|
// callback style
|
||||||
@ -36,11 +36,21 @@ si.cpu()
|
|||||||
.then(data => console.log(data))
|
.then(data => console.log(data))
|
||||||
.catch(error => console.error(error));
|
.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
|
## News and Changes
|
||||||
|
|
||||||
### Latest Activity
|
### 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.25.0: improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()`
|
||||||
- Version 3.24.0: extended windows support `networkStats()`, `networkConnections()`
|
- Version 3.24.0: extended windows support `networkStats()`, `networkConnections()`
|
||||||
- Version 3.23.0: added `memLayout`, `diskLayout`, extended windows support (`inetChecksite`)
|
- 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**
|
**Callback Style**
|
||||||
|
|
||||||
```
|
```js
|
||||||
var si = require('systeminformation');
|
const si = require('systeminformation');
|
||||||
|
|
||||||
si.networkStats('eth1', function(data) {
|
si.networkStats('eth1', function(data) {
|
||||||
console.log('Network Interface Stats (eth1):');
|
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:
|
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')
|
si.networkStats('eth1')
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('Network Interface Stats (eth1):');
|
console.log('Network Interface Stats (eth1):');
|
||||||
@ -439,6 +451,31 @@ si.networkStats('eth1')
|
|||||||
.catch(error => console.error(error));
|
.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
|
## Known Issues
|
||||||
|
|
||||||
#### OSX - Temperature Sensor
|
#### OSX - Temperature Sensor
|
||||||
|
|||||||
56
lib/index.js
56
lib/index.js
@ -130,35 +130,29 @@ function getStaticData(callback) {
|
|||||||
|
|
||||||
data.version = version();
|
data.version = version();
|
||||||
|
|
||||||
system().then(res => {
|
Promise.all([
|
||||||
data.system = res;
|
system(),
|
||||||
osInfo.osInfo().then(res => {
|
osInfo.osInfo(),
|
||||||
data.os = res;
|
osInfo.versions(),
|
||||||
osInfo.versions().then(res => {
|
cpu.cpu(),
|
||||||
data.versions = res;
|
cpu.cpuFlags(),
|
||||||
cpu.cpu().then(res => {
|
graphics.graphics(),
|
||||||
data.cpu = res;
|
network.networkInterfaces(),
|
||||||
cpu.cpuFlags().then(res => {
|
mem.memLayout(),
|
||||||
data.cpu.flags = res;
|
filesystem.diskLayout()
|
||||||
graphics.graphics().then(res => {
|
]).then(res => {
|
||||||
data.graphics = res;
|
data.system = res[0];
|
||||||
network.networkInterfaces().then(res => {
|
data.os = res[1];
|
||||||
data.net = res;
|
data.versions = res[2];
|
||||||
mem.memLayout().then(res => {
|
data.cpu = res[3];
|
||||||
data.memLayout = res;
|
data.cpu.flags = res[4];
|
||||||
filesystem.diskLayout().then(res => {
|
data.graphics = res[5];
|
||||||
data.diskLayout = res;
|
data.net = res[6];
|
||||||
|
data.memLayout = res[7];
|
||||||
|
data.diskLayout = res[8];
|
||||||
if (callback) { callback(data) }
|
if (callback) { callback(data) }
|
||||||
resolve(data);
|
resolve(data);
|
||||||
})
|
});
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -190,7 +184,7 @@ function getDynamicData(srv, iface, callback) {
|
|||||||
|
|
||||||
// use closure to track ƒ completion
|
// use closure to track ƒ completion
|
||||||
let functionProcessed = (function () {
|
let functionProcessed = (function () {
|
||||||
let totalFunctions = (_windows ? 7 : 14);
|
let totalFunctions = (_windows ? 10 : 14);
|
||||||
|
|
||||||
return function () {
|
return function () {
|
||||||
if (--totalFunctions === 0) {
|
if (--totalFunctions === 0) {
|
||||||
@ -241,31 +235,25 @@ function getDynamicData(srv, iface, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_windows) {
|
|
||||||
cpu.currentLoad().then(res => {
|
cpu.currentLoad().then(res => {
|
||||||
data.currentLoad = res;
|
data.currentLoad = res;
|
||||||
functionProcessed();
|
functionProcessed();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
cpu.cpuTemperature().then(res => {
|
cpu.cpuTemperature().then(res => {
|
||||||
data.temp = res;
|
data.temp = res;
|
||||||
functionProcessed();
|
functionProcessed();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_windows) {
|
|
||||||
network.networkStats(iface).then(res => {
|
network.networkStats(iface).then(res => {
|
||||||
data.networkStats = res;
|
data.networkStats = res;
|
||||||
functionProcessed();
|
functionProcessed();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (!_windows) {
|
|
||||||
network.networkConnections().then(res => {
|
network.networkConnections().then(res => {
|
||||||
data.networkConnections = res;
|
data.networkConnections = res;
|
||||||
functionProcessed();
|
functionProcessed();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
mem.mem().then(res => {
|
mem.mem().then(res => {
|
||||||
data.mem = res;
|
data.mem = res;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user