added MAC address to networkInterfaces, fixed currentLoad
This commit is contained in:
parent
3aadf17c83
commit
972d28cfb6
@ -88,6 +88,7 @@ Other changes
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 3.9.0 | 2016-11-11 | added MAC address to networkInterfaces, fixed currentLoad |
|
||||
| 3.8.1 | 2016-11-04 | updated docs |
|
||||
| 3.8.0 | 2016-11-04 | added dockerContainerProcesses |
|
||||
| 3.7.1 | 2016-11-03 | code refactoring |
|
||||
|
||||
20
LICENSE
20
LICENSE
@ -1,20 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2016 Sebastian Hildebrandt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@ -42,6 +42,7 @@ si.cpu()
|
||||
|
||||
### Latest Activity
|
||||
|
||||
- Version 3.9.0: extended networkInterfaces (added MAC address).
|
||||
- Version 3.8.0: added dockerContainerProcesses (array of processes inside a docker container).
|
||||
- Version 3.7.0: extended docker stats.
|
||||
- Version 3.6.0: added versions (kernel, ssl, node, npm, pm2, ...).
|
||||
@ -183,6 +184,7 @@ This library is splitted in several sections:
|
||||
| - [0].iface | X | X | interface name |
|
||||
| - [0].ip4 | X | X | ip4 address |
|
||||
| - [0].ip6 | X | X | ip6 address |
|
||||
| - [0].mac | X | X | MAC address |
|
||||
| - [0].internal | X | X | true if internal interface |
|
||||
| si.networkInterfaceDefault(cb) | X | X | get name of default network interface |
|
||||
| si.networkStats(iface,cb) | X | X | current network stats of given interface<br>iface parameter is optional<br>defaults to first external network interface|
|
||||
|
||||
@ -81,6 +81,7 @@
|
||||
// --------------------------------
|
||||
//
|
||||
// version date comment
|
||||
// 3.9.0 2016-11-11 added MAC address to networkInterfaces, fixed currentLoad
|
||||
// 3.8.1 2016-11-04 updated docs
|
||||
// 3.8.0 2016-11-04 added dockerContainerProcesses
|
||||
// 3.7.1 2016-11-03 code refactoring
|
||||
|
||||
@ -96,6 +96,7 @@ function networkInterfaces(callback) {
|
||||
for (let dev in ifaces) {
|
||||
let ip4 = '';
|
||||
let ip6 = '';
|
||||
let mac = '';
|
||||
if (ifaces.hasOwnProperty(dev)) {
|
||||
ifaces[dev].forEach(function (details) {
|
||||
if (details.family == 'IPv4') {
|
||||
@ -104,9 +105,10 @@ function networkInterfaces(callback) {
|
||||
if (details.family == 'IPv6') {
|
||||
ip6 = details.address
|
||||
}
|
||||
mac = details.mac
|
||||
});
|
||||
let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : null;
|
||||
result.push({ iface: dev, ip4: ip4, ip6: ip6, internal: internal })
|
||||
result.push({ iface: dev, ip4: ip4, ip6: ip6, mac : mac, internal: internal })
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result) }
|
||||
|
||||
@ -40,7 +40,12 @@ let _current_cpu = {
|
||||
steal: 0,
|
||||
guest: 0,
|
||||
guest_nice: 0,
|
||||
all: 0
|
||||
all: 0,
|
||||
ms: 0,
|
||||
currentload: 0,
|
||||
currentload_user: 0,
|
||||
currentload_nice: 0,
|
||||
currentload_system: 0
|
||||
};
|
||||
|
||||
// --------------------------
|
||||
@ -50,15 +55,21 @@ function getLoad() {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = {};
|
||||
let loads = os.loadavg().map(function (x) { return x / util.cores() });
|
||||
result.avgload = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
|
||||
let avgload = parseFloat((Math.max.apply(Math, loads)).toFixed(2));
|
||||
let result = {
|
||||
avgload: avgload,
|
||||
currentload: _current_cpu.currentload,
|
||||
currentload_user: _current_cpu.currentload_user,
|
||||
currentload_nice: _current_cpu.currentload_nice,
|
||||
currentload_system: _current_cpu.currentload_system
|
||||
};
|
||||
|
||||
if (_darwin) {
|
||||
result.currentload = -1;
|
||||
result.currentload_user = -1;
|
||||
result.currentload_nice = -1;
|
||||
result.currentload_system = -1;
|
||||
|
||||
if (_darwin) {
|
||||
exec("ps -cax -o pcpu", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().replace(/,+/g, ".").split('\n');
|
||||
@ -72,6 +83,9 @@ function getLoad() {
|
||||
});
|
||||
}
|
||||
if (_linux) {
|
||||
let now = Date.now() - _current_cpu.ms;
|
||||
if (now >= 1000) {
|
||||
_current_cpu.ms = Date.now();
|
||||
exec("cat /proc/stat | grep 'cpu '", function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
@ -103,11 +117,19 @@ function getLoad() {
|
||||
steal: steal,
|
||||
guest: guest,
|
||||
guest_nice: guest_nice,
|
||||
all: all
|
||||
all: all,
|
||||
ms: _current_cpu.ms,
|
||||
currentload: result.currentload,
|
||||
currentload_user: result.currentload_user,
|
||||
currentload_nice: result.currentload_nice,
|
||||
currentload_system: result.currentload_system
|
||||
}
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user