diff --git a/CHANGELOG.md b/CHANGELOG.md index 6670403..dcbd90c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.27.0 | 2017-09-11 | added raw data to `currentLoad()`, fixed `networkInterfaces()` MAC problem node 8.x | | 3.26.2 | 2017-09-01 | removed redundant code | | 3.26.1 | 2017-08-23 | fixed `cpu().speed` windows / AMD, updated docs | | 3.26.0 | 2017-08-21 | extended `getDynamicData()` (windows), updated docs | diff --git a/README.md b/README.md index e9a0334..e403df8 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ const si = require('systeminformation'); si.cpu(function(data) { console.log('CPU-Information:'); console.log(data); -}) +}); // promises style - new in version 3 si.cpu() @@ -41,7 +41,7 @@ async function cpu() { try { const data = await si.cpu(); console.log(data) - } catch { + } catch (e) { console.log(e) } } @@ -50,6 +50,7 @@ async function cpu() { ## News and Changes ### Latest Activity +- Version 3.27.0: added raw data to `currentLoad()`, fixed `networkInterfaces()` MAC problem node 8.x - Version 3.26.0: improved windows support `getDynamicData()`, updated docs - Version 3.25.0: improved windows support `networkStats()`, `cpuCache()`, bug fix `getStaticData()` - Version 3.24.0: extended windows support `networkStats()`, `networkConnections()` @@ -317,15 +318,17 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | Function | Result object | Linux | OSX | Win | Comments | | --------------- | ----- | ----- | ---- | ------- | -------- | -| si.currentLoad(cb) | {...} | X | X | | CPU-Load | -| | avgload | X | X | | average load | -| | currentload | X | X | | CPU-Load in % | -| | currentload_user | X | X | | CPU-Load User in % | -| | currentload_nice | X | X | | CPU-Load Nice in % | -| | currentload_system | X | X | | CPU-Load System in % | -| | currentload_irq | X | X | | CPU-Load System in % | -| | cpus[] | X | X | | current loads per CPU in % | -| si.fullLoad(cb) | : integer | X | X | | CPU-full load since bootup in % | +| si.currentLoad(cb) | {...} | X | X | X | CPU-Load | +| | avgload | X | X | X | average load | +| | currentload | X | X | X | CPU-Load in % | +| | currentload_user | X | X | X | CPU-Load User in % | +| | currentload_system | X | X | X | CPU-Load System in % | +| | currentload_nice | X | X | X | CPU-Load Nice in % | +| | currentload_idle | X | X | X | CPU-Load Idle in % | +| | currentload_irq | X | X | X | CPU-Load System in % | +| | raw_currentload... | X | X | X | CPU-Load raw values (ticks) | +| | cpus[] | X | X | X | current loads per CPU in % + raw ticks | +| si.fullLoad(cb) | : integer | X | X | X | CPU-full load since bootup in % | | si.processes(cb) | {...} | X | X | | # running processes | | | all | X | X | | # of all processes | | | running | X | X | | # of all processes running | @@ -463,7 +466,7 @@ const si = require('systeminformation'); async function network() { try { - const data = await si.networkStats('eth1') + const data = await si.networkStats('eth1'); console.log(`Network Interface Stats (eth1): - is up: ${data.operstate} - RX bytes overall: ${data.rx} diff --git a/lib/cpu.js b/lib/cpu.js index 0e68a94..a6c5ef3 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -36,9 +36,16 @@ let _current_cpu = { ms: 0, currentload: 0, currentload_user: 0, - currentload_nice: 0, currentload_system: 0, - currentload_irq: 0 + currentload_nice: 0, + currentload_idle: 0, + currentload_irq: 0, + raw_currentload: 0, + raw_currentload_user: 0, + raw_currentload_system: 0, + raw_currentload_nice: 0, + raw_currentload_idle: 0, + raw_currentload_irq: 0 }; let _cpus = []; let _corecount = 0; @@ -564,29 +571,38 @@ function getLoad() { totalUser += cpu.user; totalSystem += cpu.sys; totalNice += cpu.nice; - totalIrq += cpu.irq; totalIdle += cpu.idle; + totalIrq += cpu.irq; let tmp_tick = (_cpus && _cpus[i] && _cpus[i].totalTick ? _cpus[i].totalTick : 0); let tmp_load = (_cpus && _cpus[i] && _cpus[i].totalLoad ? _cpus[i].totalLoad : 0); let tmp_user = (_cpus && _cpus[i] && _cpus[i].user ? _cpus[i].user : 0); let tmp_system = (_cpus && _cpus[i] && _cpus[i].sys ? _cpus[i].sys : 0); let tmp_nice = (_cpus && _cpus[i] && _cpus[i].nice ? _cpus[i].nice : 0); + let tmp_idle = (_cpus && _cpus[i] && _cpus[i].idle ? _cpus[i].idle : 0); let tmp_irq = (_cpus && _cpus[i] && _cpus[i].irq ? _cpus[i].irq : 0); _cpus[i] = cpu; _cpus[i].totalTick = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq + _cpus[i].idle; _cpus[i].totalLoad = _cpus[i].user + _cpus[i].sys + _cpus[i].nice + _cpus[i].irq; _cpus[i].currentTick = _cpus[i].totalTick - tmp_tick; - _cpus[i].load = (_cpus[i].totalLoad - tmp_load) / _cpus[i].currentTick * 100; - _cpus[i].load_user = (_cpus[i].user - tmp_user) / _cpus[i].currentTick * 100; - _cpus[i].load_system = (_cpus[i].sys - tmp_system) / _cpus[i].currentTick * 100; - _cpus[i].load_nice = (_cpus[i].nice - tmp_nice) / _cpus[i].currentTick * 100; - _cpus[i].load_irq = (_cpus[i].irq - tmp_irq) / _cpus[i].currentTick * 100; + _cpus[i].load = (_cpus[i].totalLoad - tmp_load); + _cpus[i].load_user = (_cpus[i].user - tmp_user); + _cpus[i].load_system = (_cpus[i].sys - tmp_system); + _cpus[i].load_nice = (_cpus[i].nice - tmp_nice); + _cpus[i].load_idle = (_cpus[i].idle - tmp_idle); + _cpus[i].load_irq = (_cpus[i].irq - tmp_irq); cores[i] = {}; - cores[i].load = _cpus[i].load; - cores[i].load_user = _cpus[i].load_user; - cores[i].load_system = _cpus[i].load_system; - cores[i].load_nice = _cpus[i].load_nice; - cores[i].load_irq = _cpus[i].load_irq; + cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100; + cores[i].load_user = _cpus[i].load_user / _cpus[i].currentTick * 100; + cores[i].load_system = _cpus[i].load_system / _cpus[i].currentTick * 100; + cores[i].load_nice = _cpus[i].load_nice / _cpus[i].currentTick * 100; + cores[i].load_idle = _cpus[i].load_idle / _cpus[i].currentTick * 100; + cores[i].load_irq = _cpus[i].load_irq / _cpus[i].currentTick * 100; + cores[i].raw_load = _cpus[i].load; + cores[i].raw_load_user = _cpus[i].load_user; + cores[i].raw_load_system = _cpus[i].load_system; + cores[i].raw_load_nice = _cpus[i].load_nice; + cores[i].raw_load_idle = _cpus[i].load_idle; + cores[i].raw_load_irq = _cpus[i].load_irq; } let totalTick = totalUser + totalSystem + totalNice + totalIrq + totalIdle; let totalLoad = totalUser + totalSystem + totalNice + totalIrq; @@ -597,7 +613,14 @@ function getLoad() { currentload_user: (totalUser - _current_cpu.user) / currentTick * 100, currentload_system: (totalSystem - _current_cpu.system) / currentTick * 100, currentload_nice: (totalNice - _current_cpu.nice) / currentTick * 100, + currentload_idle: (totalIdle - _current_cpu.idle) / currentTick * 100, currentload_irq: (totalIrq - _current_cpu.irq) / currentTick * 100, + raw_currentload: (totalLoad - _current_cpu.load), + raw_currentload_user: (totalUser - _current_cpu.user), + raw_currentload_system: (totalSystem - _current_cpu.system), + raw_currentload_nice: (totalNice - _current_cpu.nice), + raw_currentload_idle: (totalIdle - _current_cpu.idle), + raw_currentload_irq: (totalIrq - _current_cpu.irq), cpus: cores }; _current_cpu = { @@ -613,17 +636,31 @@ function getLoad() { currentload_user: result.currentload_user, currentload_system: result.currentload_system, currentload_nice: result.currentload_nice, + currentload_idle: result.currentload_idle, currentload_irq: result.currentload_irq, + raw_currentload: result.raw_currentload, + raw_currentload_user: result.raw_currentload_user, + raw_currentload_system: result.raw_currentload_system, + raw_currentload_nice: result.raw_currentload_nice, + raw_currentload_idle: result.raw_currentload_idle, + raw_currentload_irq: result.raw_currentload_irq, }; } else { let cores = []; for (let i = 0; i < _corecount; i++) { cores[i] = {}; - cores[i].load = _cpus[i].load; - cores[i].load_user = _cpus[i].load_user; - cores[i].load_system = _cpus[i].load_system; - cores[i].load_nice = _cpus[i].load_nice; - cores[i].load_irq = _cpus[i].load_irq; + cores[i].load = _cpus[i].load / _cpus[i].currentTick * 100; + cores[i].load_user = _cpus[i].load_user / _cpus[i].currentTick * 100; + cores[i].load_system = _cpus[i].load_system / _cpus[i].currentTick * 100; + cores[i].load_nice = _cpus[i].load_nice / _cpus[i].currentTick * 100; + cores[i].load_idle = _cpus[i].load_idle / _cpus[i].currentTick * 100; + cores[i].load_irq = _cpus[i].load_irq / _cpus[i].currentTick * 100; + cores[i].raw_load = _cpus[i].load; + cores[i].raw_load_user = _cpus[i].load_user; + cores[i].raw_load_system = _cpus[i].load_system; + cores[i].raw_load_nice = _cpus[i].load_nice; + cores[i].raw_load_idle = _cpus[i].load_idle; + cores[i].raw_load_irq = _cpus[i].load_irq; } result = { avgload: avgload, @@ -631,7 +668,14 @@ function getLoad() { currentload_user: _current_cpu.currentload_user, currentload_system: _current_cpu.currentload_system, currentload_nice: _current_cpu.currentload_nice, + currentload_idle: _current_cpu.currentload_idle, currentload_irq: _current_cpu.currentload_irq, + raw_currentload: _current_cpu.raw_currentload, + raw_currentload_user: _current_cpu.raw_currentload_user, + raw_currentload_system: _current_cpu.raw_currentload_system, + raw_currentload_nice: _current_cpu.raw_currentload_nice, + raw_currentload_idle: _current_cpu.raw_currentload_idle, + raw_currentload_irq: _current_cpu.raw_currentload_irq, cpus: cores }; } diff --git a/lib/filesystem.js b/lib/filesystem.js index 117dd25..de5f5f6 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -172,6 +172,7 @@ function parseBlk(lines) { let data = []; lines.filter(line => line !== '').forEach((line) => { + // line = line.replace(/\\/g,'\\\\'); let disk = JSON.parse(line); data.push({ 'name': disk.name, diff --git a/lib/index.js b/lib/index.js index d1d067b..9b5fc75 100644 --- a/lib/index.js +++ b/lib/index.js @@ -91,7 +91,7 @@ const util = require('./util'); const system = require('./system'); const osInfo = require('./osinfo'); const cpu = require('./cpu'); -const mem = require('./memory'); +const memory = require('./memory'); const battery = require('./battery'); const graphics = require('./graphics'); const filesystem = require('./filesystem'); @@ -138,7 +138,7 @@ function getStaticData(callback) { cpu.cpuFlags(), graphics.graphics(), network.networkInterfaces(), - mem.memLayout(), + memory.memLayout(), filesystem.diskLayout() ]).then(res => { data.system = res[0]; @@ -255,7 +255,7 @@ function getDynamicData(srv, iface, callback) { functionProcessed(); }); - mem.mem().then(res => { + memory.mem().then(res => { data.mem = res; functionProcessed(); }); @@ -348,8 +348,8 @@ exports.cpuTemperature = cpu.cpuTemperature; exports.currentLoad = cpu.currentLoad; exports.fullLoad = cpu.fullLoad; -exports.mem = mem.mem; -exports.memLayout = mem.memLayout; +exports.mem = memory.mem; +exports.memLayout = memory.memLayout; exports.battery = battery; diff --git a/lib/network.js b/lib/network.js index 639bbcc..46d34dc 100644 --- a/lib/network.js +++ b/lib/network.js @@ -27,6 +27,7 @@ const NOT_SUPPORTED = 'not supported'; let _network = {}; let _default_iface; +let _mac = {}; function getValue(lines, property, separator) { separator = separator || ':'; @@ -83,6 +84,47 @@ function getDefaultNetworkInterface() { exports.getDefaultNetworkInterface = getDefaultNetworkInterface; +function getMacAddresses() { + let iface = ''; + let mac = ''; + let result = {}; + if (_linux) { + const cmd = 'export LC_ALL=C; /sbin/ifconfig; unset LC_ALL'; + let res = execSync(cmd); + const lines = res.toString().split('\n'); + for (let i = 0; i < lines.length; i++) { + if (lines[i] && lines[i][0] !== ' ') { + iface = lines[i].split(' ')[0]; + mac = lines[i].split('HWaddr ')[1]; + if (iface && mac) { + result[iface] = mac.trim(); + iface = ''; + mac = ''; + } + } + } + + } + if (_darwin) { + const cmd = '/sbin/ifconfig'; + let res = execSync(cmd); + const lines = res.toString().split('\n'); + for (let i = 0; i < lines.length; i++) { + if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) { + iface = lines[i].split(':')[0]; + } else if (lines[i].indexOf('\tether ') === 0) { + mac = lines[i].split('\tether ')[1]; + if (iface && mac) { + result[iface] = mac.trim(); + iface = ''; + mac = ''; + } + } + } + } + return result +} + function networkInterfaceDefault(callback) { return new Promise((resolve, reject) => { @@ -118,7 +160,13 @@ function networkInterfaces(callback) { if (details.family === 'IPv6') { ip6 = details.address } - mac = details.mac + mac = details.mac; + if (mac.indexOf('00:00:0') > -1 && (_linux || _darwin)) { + if (Object.keys(_mac).length === 0) { + _mac = getMacAddresses(); + } + mac = _mac[dev] || ''; + } }); let internal = (ifaces[dev] && ifaces[dev][0]) ? ifaces[dev][0].internal : null; result.push({ iface: dev, ip4: ip4, ip6: ip6, mac: mac, internal: internal })