diff --git a/CHANGELOG.md b/CHANGELOG.md
index 323cb77..6075744 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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 |
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index f9dc944..0000000
--- a/LICENSE
+++ /dev/null
@@ -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.
diff --git a/README.md b/README.md
index 488860f..011c59e 100644
--- a/README.md
+++ b/README.md
@@ -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
iface parameter is optional
defaults to first external network interface|
diff --git a/lib/index.js b/lib/index.js
index 30723c6..97ec828 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -81,24 +81,25 @@
// --------------------------------
//
// version date comment
-// 3.8.1 2016-11-04 updated docs
-// 3.8.0 2016-11-04 added dockerContainerProcesses
-// 3.7.1 2016-11-03 code refactoring
-// 3.7.0 2016-11-02 extended docker stats, and no longer relying on curl (version conflicts)
-// 3.6.0 2016-09-16 added versions (kernel, ssl, node, npm, pm2, ...)
-// 3.5.1 2016-09-14 bugfix graphics info
-// 3.5.0 2016-09-14 added graphics info (controller, display)
-// 3.4.4 2016-09-02 tiny fixes system.model, getDefaultNetworkInterface
-// 3.4.3 2016-09-02 tiny bug fix fsStats, disksIO OSX
-// 3.4.2 2016-09-01 improved default network interface
-// 3.4.1 2016-08-30 updated docs
-// 3.4.0 2016-08-30 rewritten current process cpu usage (linux)
-// 3.3.0 2016-08-24 added process list
-// 3.2.1 2016-08-20 updated docs, improvement system
-// 3.2.0 2016-08-19 added battery info
-// 3.1.1 2016-08-18 improved system and os detection (vm, ...), bug fix disksIO
-// 3.1.0 2016-08-18 added docker stats
-// 3.0.1 2016-08-17 Bug-Fix disksIO, users, updated docs
+// 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
+// 3.7.0 2016-11-02 extended docker stats, and no longer relying on curl (version conflicts)
+// 3.6.0 2016-09-16 added versions (kernel, ssl, node, npm, pm2, ...)
+// 3.5.1 2016-09-14 bugfix graphics info
+// 3.5.0 2016-09-14 added graphics info (controller, display)
+// 3.4.4 2016-09-02 tiny fixes system.model, getDefaultNetworkInterface
+// 3.4.3 2016-09-02 tiny bug fix fsStats, disksIO OSX
+// 3.4.2 2016-09-01 improved default network interface
+// 3.4.1 2016-08-30 updated docs
+// 3.4.0 2016-08-30 rewritten current process cpu usage (linux)
+// 3.3.0 2016-08-24 added process list
+// 3.2.1 2016-08-20 updated docs, improvement system
+// 3.2.0 2016-08-19 added battery info
+// 3.1.1 2016-08-18 improved system and os detection (vm, ...), bug fix disksIO
+// 3.1.0 2016-08-18 added docker stats
+// 3.0.1 2016-08-17 Bug-Fix disksIO, users, updated docs
// 3.0.0 2016-08-03 new major version 3.0
// 2.0.5 2016-02-22 some more tiny correction ...
// 2.0.4 2016-02-22 tiny correction - removed double quotes CPU brand, ...
diff --git a/lib/network.js b/lib/network.js
index 7a88d33..29e4e0c 100644
--- a/lib/network.js
+++ b/lib/network.js
@@ -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) }
diff --git a/lib/processes.js b/lib/processes.js
index 8dc941e..761bbe2 100644
--- a/lib/processes.js
+++ b/lib/processes.js
@@ -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));
- result.currentload = -1;
- result.currentload_user = -1;
- result.currentload_nice = -1;
- result.currentload_system = -1;
+ 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;
exec("ps -cax -o pcpu", function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/,+/g, ".").split('\n');
@@ -72,42 +83,53 @@ function getLoad() {
});
}
if (_linux) {
- exec("cat /proc/stat | grep 'cpu '", function (error, stdout) {
- if (!error) {
- let lines = stdout.toString().split('\n');
- let parts = lines[0].replace(/ +/g, " ").split(' ');
- let user = (parts.length >= 2 ? parseInt(parts[1]) : 0);
- let nice = (parts.length >= 3 ? parseInt(parts[2]) : 0);
- let system = (parts.length >= 4 ? parseInt(parts[3]) : 0);
- let idle = (parts.length >= 5 ? parseInt(parts[4]) : 0);
- let iowait = (parts.length >= 6 ? parseInt(parts[5]) : 0);
- let irq = (parts.length >= 7 ? parseInt(parts[6]) : 0);
- let softirq = (parts.length >= 8 ? parseInt(parts[7]) : 0);
- let steal = (parts.length >= 9 ? parseInt(parts[8]) : 0);
- let guest = (parts.length >= 10 ? parseInt(parts[9]) : 0);
- let guest_nice = (parts.length >= 11 ? parseInt(parts[10]) : 0);
- let all = user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
- result.currentload = (user + nice + system - _current_cpu.user - _current_cpu.nice - _current_cpu.system) / (all - _current_cpu.all) * 100;
+ 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');
+ let parts = lines[0].replace(/ +/g, " ").split(' ');
+ let user = (parts.length >= 2 ? parseInt(parts[1]) : 0);
+ let nice = (parts.length >= 3 ? parseInt(parts[2]) : 0);
+ let system = (parts.length >= 4 ? parseInt(parts[3]) : 0);
+ let idle = (parts.length >= 5 ? parseInt(parts[4]) : 0);
+ let iowait = (parts.length >= 6 ? parseInt(parts[5]) : 0);
+ let irq = (parts.length >= 7 ? parseInt(parts[6]) : 0);
+ let softirq = (parts.length >= 8 ? parseInt(parts[7]) : 0);
+ let steal = (parts.length >= 9 ? parseInt(parts[8]) : 0);
+ let guest = (parts.length >= 10 ? parseInt(parts[9]) : 0);
+ let guest_nice = (parts.length >= 11 ? parseInt(parts[10]) : 0);
+ let all = user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
+ result.currentload = (user + nice + system - _current_cpu.user - _current_cpu.nice - _current_cpu.system) / (all - _current_cpu.all) * 100;
- result.currentload_user = (user - _current_cpu.user) / (all - _current_cpu.all) * 100;
- result.currentload_nice = (nice - _current_cpu.nice) / (all - _current_cpu.all) * 100;
- result.currentload_system = (system - _current_cpu.system) / (all - _current_cpu.all) * 100;
- _current_cpu = {
- user: user,
- nice: nice,
- system: system,
- idle: idle,
- iowait: iowait,
- irq: irq,
- softirq: softirq,
- steal: steal,
- guest: guest,
- guest_nice: guest_nice,
- all: all
+ result.currentload_user = (user - _current_cpu.user) / (all - _current_cpu.all) * 100;
+ result.currentload_nice = (nice - _current_cpu.nice) / (all - _current_cpu.all) * 100;
+ result.currentload_system = (system - _current_cpu.system) / (all - _current_cpu.all) * 100;
+ _current_cpu = {
+ user: user,
+ nice: nice,
+ system: system,
+ idle: idle,
+ iowait: iowait,
+ irq: irq,
+ softirq: softirq,
+ steal: steal,
+ guest: guest,
+ guest_nice: guest_nice,
+ 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);
- });
+ }
}
});
});