Version 4.0 anoucements

This commit is contained in:
Sebastian Hildebrandt 2019-01-05 17:45:27 +01:00
parent c1d05921f2
commit 88d99c9777
4 changed files with 65 additions and 43 deletions

View File

@ -100,7 +100,6 @@ Other changes
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 3.55.0 | 2019-01-04 | `networkInterfaces()` extended, `networkStats()` extended, bugfix windows |
| 3.54.0 | 2018-12-30 | added TypeScript type definitions |
| 3.53.1 | 2018-12-29 | `versions()` bug fix nginx version |
| 3.53.0 | 2018-12-29 | `versions()` added perl, python, gcc |

View File

@ -14,6 +14,19 @@ Simple system and OS information library for [node.js][nodejs-url]
[![Caretaker][caretaker-image]][caretaker-url]
[![MIT license][license-img]][license-url]
## Version 4.0 - just arround the corner
I am currently working on the next major release, version 4.0. What you will see is
- new systeminformation website with better documentation and examples
- added typescript information
- automated tests - travis-ci integration
- reworked network section: this will now return more information and allows to get networkStats for more than one interface at once.
- better Raspberry detection
- lot of minor improvements
But be aware: you will see some minor breaking changes. I expect to finalize the new version by end of January 2019.
## Quick Start
Lightweight collection of 35+ functions to retrieve detailed hardware, system and OS information.

10
lib/index.d.ts vendored
View File

@ -251,9 +251,9 @@ export namespace Systeminformation {
}
interface FsStatsData {
rx: number;
wx: number;
tx: number;
rx_bytes: number;
wx_bytes: number;
tx_bytes: number;
rx_sec: number;
wx_sec: number;
tx_sec: number;
@ -290,10 +290,10 @@ export namespace Systeminformation {
interface NetworkStatsData {
iface: string;
operstate: string;
rx: number;
rx_bytes: number;
rx_dropped: number;
rx_errors: number;
tx: number;
tx_bytes: number;
tx_dropped: number;
tx_errors: number;
rx_sec: number;

View File

@ -285,9 +285,16 @@ function networkInterfaces(callback) {
}
});
}
// if (_darwin) {
//
// }
if (_darwin || _freebsd || _openbsd) {
const cmd = 'netstat -i';
let lines = execSync(cmd).toString().split('\n');
lines.forEach(line => {
const parts = line.replace(/ +/g, ' ').split(' ');
if (parts.length > 2 && parts[0] === dev) {
mtu = parts[1];
}
});
}
let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : null;
result.push({
iface: dev,
@ -305,6 +312,7 @@ function networkInterfaces(callback) {
});
}
}
_networkInterfaces = result;
if (callback) { callback(result); }
resolve(result);
}
@ -317,14 +325,14 @@ exports.networkInterfaces = networkInterfaces;
// --------------------------
// NET - Speed
function calcNetworkSpeed(iface, rx, tx, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors) {
function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors) {
let result = {
iface,
operstate,
rx,
rx_bytes,
rx_dropped,
rx_errors,
tx,
tx_bytes,
tx_dropped,
tx_errors,
rx_sec: -1,
@ -334,10 +342,10 @@ function calcNetworkSpeed(iface, rx, tx, operstate, rx_dropped, rx_errors, tx_dr
if (_network[iface] && _network[iface].ms) {
result.ms = Date.now() - _network[iface].ms;
result.rx_sec = (rx - _network[iface].rx) >= 0 ? (rx - _network[iface].rx) / (result.ms / 1000) : 0;
result.tx_sec = (tx - _network[iface].tx) >= 0 ? (tx - _network[iface].tx) / (result.ms / 1000) : 0;
_network[iface].rx = rx;
_network[iface].tx = tx;
result.rx_sec = (rx_bytes - _network[iface].rx_bytes) >= 0 ? (rx_bytes - _network[iface].rx_bytes) / (result.ms / 1000) : 0;
result.tx_sec = (tx_bytes - _network[iface].tx_bytes) >= 0 ? (tx_bytes - _network[iface].tx_bytes) / (result.ms / 1000) : 0;
_network[iface].rx_bytes = rx_bytes;
_network[iface].tx_bytes = tx_bytes;
_network[iface].rx_sec = result.rx_sec;
_network[iface].tx_sec = result.tx_sec;
_network[iface].ms = Date.now();
@ -345,8 +353,8 @@ function calcNetworkSpeed(iface, rx, tx, operstate, rx_dropped, rx_errors, tx_dr
_network[iface].operstate = operstate;
} else {
if (!_network[iface]) _network[iface] = {};
_network[iface].rx = rx;
_network[iface].tx = tx;
_network[iface].rx_bytes = rx_bytes;
_network[iface].tx_bytes = tx_bytes;
_network[iface].rx_sec = -1;
_network[iface].tx_sec = -1;
_network[iface].ms = Date.now();
@ -367,10 +375,10 @@ function networkStats(iface, callback) {
let lines = sections[i].trim().split('\r\n');
perfData.push({
name: util.getValue(lines, 'Name', '=').replace(/[()\[\] ]+/g, '').toLowerCase(),
rx: parseInt(util.getValue(lines, 'BytesReceivedPersec', '='), 10),
rx_bytes: parseInt(util.getValue(lines, 'BytesReceivedPersec', '='), 10),
rx_errors: parseInt(util.getValue(lines, 'PacketsReceivedErrors', '='), 10),
rx_dropped: parseInt(util.getValue(lines, 'PacketsReceivedDiscarded', '='), 10),
tx: parseInt(util.getValue(lines, 'BytesSentPersec', '='), 10),
tx_bytes: parseInt(util.getValue(lines, 'BytesSentPersec', '='), 10),
tx_errors: parseInt(util.getValue(lines, 'PacketsOutboundErrors', '='), 10),
tx_dropped: parseInt(util.getValue(lines, 'PacketsOutboundDiscarded', '='), 10)
});
@ -394,10 +402,10 @@ function networkStats(iface, callback) {
let result = {
iface: iface,
operstate: 'unknown',
rx: 0,
rx_bytes: 0,
rx_dropped: 0,
rx_errors: 0,
tx: 0,
tx_bytes: 0,
tx_dropped: 0,
tx_errors: 0,
rx_sec: -1,
@ -406,8 +414,8 @@ function networkStats(iface, callback) {
};
let operstate = 'unknown';
let rx = 0;
let tx = 0;
let rx_bytes = 0;
let tx_bytes = 0;
let rx_dropped = 0;
let rx_errors = 0;
let tx_dropped = 0;
@ -429,14 +437,14 @@ function networkStats(iface, callback) {
if (!error) {
lines = stdout.toString().split('\n');
operstate = lines[0].trim();
rx = parseInt(lines[1], 10);
tx = parseInt(lines[2], 10);
rx_bytes = parseInt(lines[1], 10);
tx_bytes = parseInt(lines[2], 10);
rx_dropped = parseInt(lines[3], 10);
rx_errors = parseInt(lines[4], 10);
tx_dropped = parseInt(lines[5], 10);
tx_errors = parseInt(lines[6], 10);
result = calcNetworkSpeed(iface, rx, tx, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
}
if (callback) { callback(result); }
@ -455,16 +463,16 @@ function networkStats(iface, callback) {
for (let i = 1; i < lines.length; i++) {
const line = lines[i].replace(/ +/g, ' ').split(' ');
if (line && line[0] && line[7] && line[10]) {
rx = rx + parseInt(line[7]);
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]); }
tx = tx + parseInt(line[10]);
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]); }
operstate = 'up';
}
}
result = calcNetworkSpeed(iface, rx, tx, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
}
if (callback) { callback(result); }
resolve(result);
@ -485,14 +493,14 @@ function networkStats(iface, callback) {
// skip header line
// use the second line because it is tied to the NIC instead of the ipv4 or ipv6 address
stats = lines[1].replace(/ +/g, ' ').split(' ');
rx = parseInt(stats[6]);
rx_bytes = parseInt(stats[6]);
rx_dropped = parseInt(stats[11]);
rx_errors = parseInt(stats[5]);
tx = parseInt(stats[9]);
tx_bytes = parseInt(stats[9]);
tx_dropped = parseInt(stats[11]);
tx_errors = parseInt(stats[8]);
result = calcNetworkSpeed(iface, rx, tx, result.operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
result = calcNetworkSpeed(iface, rx_bytes, tx_bytes, result.operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
}
}
if (callback) { callback(result); }
@ -502,27 +510,29 @@ function networkStats(iface, callback) {
}
if (_windows) {
let perfData = [];
let ifaceName = iface;
// Performance Data
cmd = util.getWmic() + ' path Win32_PerfRawData_Tcpip_NetworkInterface Get name,BytesReceivedPersec,BytesSentPersec,BytesTotalPersec,PacketsOutboundDiscarded,PacketsOutboundErrors,PacketsReceivedDiscarded,PacketsReceivedErrors /value';
exec(cmd, util.execOptsWin, function (error, stdout) {
if (!error) {
const psections = stdout.split(/\n\s*\n/);
const psections = stdout.toString().split(/\n\s*\n/);
perfData = parseLinesWindowsPerfData(psections);
}
// Network Interfaces
networkInterfaces().then(interfaces => {
// get bytes sent, received from perfData by name
rx = 0;
tx = 0;
rx_bytes = 0;
tx_bytes = 0;
perfData.forEach(detail => {
interfaces.forEach(det => {
if (det.iface === iface && det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === detail.name) {
rx = detail.rx;
if ((det.iface.toLowerCase() === iface.toLowerCase() || det.mac.toLowerCase() === iface.toLowerCase() || det.ip4.toLowerCase() === iface.toLowerCase() || det.ip6.toLowerCase() === iface.toLowerCase() || det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === iface.replace(/[()\[\] ]+/g, '').toLowerCase()) && det.ifaceName.replace(/[()\[\] ]+/g, '').toLowerCase() === detail.name) {
ifaceName = det.iface;
rx_bytes = detail.rx_bytes;
rx_dropped = detail.rx_dropped;
rx_errors = detail.rx_errors;
tx = detail.tx;
tx_bytes = detail.tx_bytes;
tx_dropped = detail.tx_dropped;
tx_errors = detail.tx_errors;
operstate = det.operstate;
@ -530,8 +540,8 @@ function networkStats(iface, callback) {
});
});
if (rx && tx) {
result = calcNetworkSpeed(iface, parseInt(rx), parseInt(tx), operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
if (rx_bytes && tx_bytes) {
result = calcNetworkSpeed(ifaceName, parseInt(rx_bytes), parseInt(tx_bytes), operstate, rx_dropped, rx_errors, tx_dropped, tx_errors);
}
if (callback) { callback(result); }
resolve(result);
@ -539,8 +549,8 @@ function networkStats(iface, callback) {
});
}
} else {
result.rx = _network[iface].rx;
result.tx = _network[iface].tx;
result.rx_bytes = _network[iface].rx_bytes;
result.tx_bytes = _network[iface].tx_bytes;
result.rx_sec = _network[iface].rx_sec;
result.tx_sec = _network[iface].tx_sec;
result.ms = _network[iface].last_ms;