observe() added function to observe/watch system parameters
This commit is contained in:
parent
9d35f23922
commit
9f1b6ef43d
@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 4.27.0 | 2020-08-24 | `observe()` added function to observe/watch system parameters |
|
||||
| 4.26.12 | 2020-08-21 | `versions()` fixed issue windows |
|
||||
| 4.26.11 | 2020-08-20 | `cpuTemperature()` fixed issue windows |
|
||||
| 4.26.10 | 2020-07-16 | `networkStats()` fixed issue blocking windows |
|
||||
|
||||
@ -87,13 +87,13 @@ si.cpu()
|
||||
|
||||
(last 7 major and minor version releases)
|
||||
|
||||
- Version 4.27.0: `observe()` added observe / watch function
|
||||
- Version 4.26.0: `diskLayout()` added full S.M.A.R.T data (linux)
|
||||
- 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
|
||||
- ...
|
||||
|
||||
You can find all changes here: [detailed changelog][changelog-url]
|
||||
@ -633,7 +633,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
|
||||
| | [0].timeOffset | X | X | X | X | X | time Offset |
|
||||
| | [0].RTC | X | X | X | X | X | RTC |
|
||||
|
||||
#### 14. "Get All at once" - functions
|
||||
#### 14. "Get All / Observe" - functions
|
||||
|
||||
| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
|
||||
| --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- |
|
||||
@ -641,6 +641,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
|
||||
| si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once<br>Specify services and interfaces to monitor<br>Defaults to first external network interface<br>Pass "*" for ALL services (linux/win only)<br>Pass "*" for ALL network interfaces |
|
||||
| si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once<br>Specify services and interfaces to monitor<br>Defaults to first external network interface<br>Pass "*" for ALL services (linux/win only)<br>Pass "*" for ALL network interfaces |
|
||||
| si.get(valueObject,cb) | {...} | X | X | X | X | X | get partial system info data at once<br>In valueObject you can define<br>all values, you want to get back <br>(see documentation for details) |
|
||||
| si.observe(valueObject,interval,cb) | - | X | X | X | X | X | Observe a defined value object<br>call callback on changes<br>polling interval in milliseconds |
|
||||
|
||||
### cb: Asynchronous Function Calls (callback)
|
||||
|
||||
|
||||
@ -83,6 +83,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">4.27.0</th>
|
||||
<td>2020-08-24</td>
|
||||
<td><span class="code">observe()</span> added function to observe/watch system parameters</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">4.26.12</th>
|
||||
<td>2020-08-21</td>
|
||||
|
||||
@ -168,7 +168,7 @@
|
||||
<img class="logo" src="assets/logo.png">
|
||||
<div class="title">systeminformation</div>
|
||||
<div class="subtitle"><span id="typed"></span></div>
|
||||
<div class="version">Current Version: <span id="version">4.26.12</span></div>
|
||||
<div class="version">Current Version: <span id="version">4.27.0</span></div>
|
||||
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
|
||||
</div>
|
||||
<div class="down">
|
||||
@ -207,7 +207,7 @@
|
||||
<div class="title">Downloads last month</div>
|
||||
</div>
|
||||
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
||||
<div class="numbers">330</div>
|
||||
<div class="numbers">333</div>
|
||||
<div class="title">Dependends</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -15,10 +15,10 @@ function createMenu() {
|
||||
[1, 'wifi', 'Wifi'],
|
||||
[1, 'docker', 'Docker'],
|
||||
[1, 'vbox', 'Virtual Box'],
|
||||
[1, 'statsfunctions', 'Observers / Stats'],
|
||||
[0, '', 'More'],
|
||||
[1, 'history', 'Version history'],
|
||||
[1, 'issues', 'Known Issues'],
|
||||
[1, 'statsfunctions', 'Stats Functions'],
|
||||
[1, 'copyright', 'Copyright & License'],
|
||||
[1, 'contributors', 'Contributors'],
|
||||
[1, 'trademarks', 'Trademarks'],
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
<div class="col-12 sectionheader">
|
||||
<div class="title">Stats Functions</div>
|
||||
<div class="text">
|
||||
<h4>Getting correct stats values</h4>
|
||||
<h2>Getting correct stats values</h2>
|
||||
|
||||
<p>In <span class="code">fsStats()</span>, <span class="code">disksIO()</span>, <span class="code">currentLoad()</span> and <span class="code">networkStats()</span> the
|
||||
results / sec. values (rx_sec, IOPS, ...) are calculated correctly beginning with the <strong>second</strong> call of the function.
|
||||
@ -65,6 +65,58 @@ setInterval(function() {
|
||||
})
|
||||
}, 1000)</code></pre>
|
||||
<p>Beginning with the second call, you get network transfer values per second.</p>
|
||||
<h2>Observe System Parameters</h2>
|
||||
<p>systeminformation now allows you to easily observe system poarameters: First you define a result object of system parameters you want to abserve (see also secription of the <a href="general.html"><span class="code">si.get()</span> function here</a>):</p>
|
||||
<p>Then you just call an <span class="code">si.observe()</span> function with three parameters: your result object, the polling interval (in miliseconds) and a callback function. Systeminformation will now observe the result object. Every time the result changes, this callback function is called. Your callback function also gets the current value of all observed system parameters.</p>
|
||||
<table class="table table-sm table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Function</th>
|
||||
<th>Result object</th>
|
||||
<th>Linux</th>
|
||||
<th>BSD</th>
|
||||
<th>Mac</th>
|
||||
<th>Win</th>
|
||||
<th>Sun</th>
|
||||
<th>Comments</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr>
|
||||
<td>si.observe(valueObject,interval,cb)</td>
|
||||
<td>-</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td>Observe the defined value object<br>call callback on changes:</td>
|
||||
</tr>
|
||||
<tr class="example">
|
||||
<td></td>
|
||||
<td colspan="7">
|
||||
<h5>Example</h5>
|
||||
<pre><code class="js">const si = require('systeminformation');
|
||||
|
||||
// define all values, you want to get back
|
||||
valueObject = {
|
||||
battery: 'acconnected'
|
||||
}
|
||||
|
||||
function usersCallback(data) {
|
||||
console.log('Power usage now: ' + (data.battery.acconnected ? 'AC' : 'battery'));
|
||||
}
|
||||
|
||||
// now define the observer function
|
||||
let observer = si.observe(valueObject, 1000, usersCallback);
|
||||
|
||||
// In this example we stop our observer function after 30 seconds
|
||||
setTimeout(() => {
|
||||
clearInterval(observer)
|
||||
}, 30000);</code></pre class="example">
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>The key names of the <span class="code">valueObject</span> must be exactly the same as the representing function within systeminformation.</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
15
lib/index.js
15
lib/index.js
@ -349,6 +349,20 @@ function get(valueObject, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function observe(valueObject, interval, callback) {
|
||||
let _data = null;
|
||||
|
||||
const result = setInterval(() => {
|
||||
get(valueObject).then(data => {
|
||||
if (JSON.stringify(_data) !== JSON.stringify(data)) {
|
||||
_data = { ...data };
|
||||
callback(data);
|
||||
}
|
||||
})
|
||||
}, interval);
|
||||
return result;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// export all libs
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ -416,4 +430,5 @@ exports.getStaticData = getStaticData;
|
||||
exports.getDynamicData = getDynamicData;
|
||||
exports.getAllData = getAllData;
|
||||
exports.get = get;
|
||||
exports.observe = observe;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user