diff --git a/CHANGELOG.md b/CHANGELOG.md index c2bf333..042886c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.19.4 | 2020-01-24 | `mem()` prevent log messages, `memgetDefaultNetworkInterface()` catch errors | | 4.19.3 | 2020-01-24 | `memLayout()` bank info fix macOS | | 4.19.2 | 2020-01-19 | `cpu()` muli-processor fix windows | | 4.19.1 | 2020-01-14 | `osInfo()` uefi fix windows | diff --git a/docs/history.html b/docs/history.html index 27ec030..1028130 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.19.4 + 2020-01-24 + mem() prevent log messages + 4.19.3 2020-01-24 diff --git a/docs/index.html b/docs/index.html index 591024f..29de977 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.19.3
+
Current Version: 4.19.4
diff --git a/lib/memory.js b/lib/memory.js index fe99a5a..bfe9632 100644 --- a/lib/memory.js +++ b/lib/memory.js @@ -142,7 +142,7 @@ function mem(callback) { }; if (_linux) { - exec('export LC_ALL=C; cat /proc/meminfo ; unset LC_ALL', function (error, stdout) { + exec('export LC_ALL=C; cat /proc/meminfo 2>/dev/null ; unset LC_ALL', function (error, stdout) { if (!error) { const lines = stdout.toString().split('\n'); result.total = parseInt(util.getValue(lines, 'memtotal'), 10); @@ -174,7 +174,7 @@ function mem(callback) { }); } if (_freebsd || _openbsd || _netbsd) { - exec('/sbin/sysctl -a | grep -E "hw.realmem|hw.physmem|vm.stats.vm.v_page_count|vm.stats.vm.v_wire_count|vm.stats.vm.v_active_count|vm.stats.vm.v_inactive_count|vm.stats.vm.v_cache_count|vm.stats.vm.v_free_count|vm.stats.vm.v_page_size"', function (error, stdout) { + exec('/sbin/sysctl -a 2>/dev/null | grep -E "hw.realmem|hw.physmem|vm.stats.vm.v_page_count|vm.stats.vm.v_wire_count|vm.stats.vm.v_active_count|vm.stats.vm.v_inactive_count|vm.stats.vm.v_cache_count|vm.stats.vm.v_free_count|vm.stats.vm.v_page_size"', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); const pagesize = parseInt(util.getValue(lines, 'vm.stats.vm.v_page_size'), 10); @@ -202,7 +202,7 @@ function mem(callback) { resolve(result); } if (_darwin) { - exec('vm_stat | grep "Pages active"', function (error, stdout) { + exec('vm_stat 2>/dev/null | grep "Pages active"', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); @@ -210,7 +210,7 @@ function mem(callback) { result.buffcache = result.used - result.active; result.available = result.free + result.buffcache; } - exec('sysctl -n vm.swapusage', function (error, stdout) { + exec('sysctl -n vm.swapusage 2>/dev/null', function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); if (lines.length > 0) { diff --git a/lib/network.js b/lib/network.js index fe9bf3b..f25556f 100644 --- a/lib/network.js +++ b/lib/network.js @@ -61,45 +61,48 @@ function getDefaultNetworkInterface() { } ifacename = ifacename || ifacenameFirst || ''; - if (_windows) { - // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml - const cmd = 'netstat -r'; - const result = execSync(cmd); - const lines = result.toString().split(os.EOL); - let defaultIp = ''; - lines.forEach(line => { - line = line.replace(/\s+/g, ' ').trim(); - if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !(/[a-zA-Z]/.test(line))) { - const parts = line.split(' '); - if (parts.length >= 5) { - defaultIp = parts[parts.length - 2]; + try { + if (_windows) { + // https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml + const cmd = 'netstat -r'; + const result = execSync(cmd); + const lines = result.toString().split(os.EOL); + let defaultIp = ''; + lines.forEach(line => { + line = line.replace(/\s+/g, ' ').trim(); + if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !(/[a-zA-Z]/.test(line))) { + const parts = line.split(' '); + if (parts.length >= 5) { + defaultIp = parts[parts.length - 2]; + } } - } - }); - if (defaultIp) { - for (let dev in ifaces) { - if ({}.hasOwnProperty.call(ifaces, dev)) { - ifaces[dev].forEach(function (details) { - if (details && details.address && details.address === defaultIp) { - ifacename = dev; - } - }); + }); + if (defaultIp) { + for (let dev in ifaces) { + if ({}.hasOwnProperty.call(ifaces, dev)) { + ifaces[dev].forEach(function (details) { + if (details && details.address && details.address === defaultIp) { + ifacename = dev; + } + }); + } } } } - } - if (_linux || _darwin || _freebsd || _openbsd || _netbsd || _sunos) { - let cmd = ''; - if (_linux) cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\''; - if (_darwin) cmd = 'route get 0.0.0.0 2>/dev/null | grep interface: | awk \'{print $2}\''; - if (_freebsd || _openbsd || _netbsd || _sunos) cmd = 'route get 0.0.0.0 | grep interface:'; - let result = execSync(cmd); - ifacename = result.toString().split('\n')[0]; - if (ifacename.indexOf(':') > -1) { - ifacename = ifacename.split(':')[1].trim(); + if (_linux || _darwin || _freebsd || _openbsd || _netbsd || _sunos) { + let cmd = ''; + if (_linux) cmd = 'ip route 2> /dev/null | grep default | awk \'{print $5}\''; + if (_darwin) cmd = 'route get 0.0.0.0 2>/dev/null | grep interface: | awk \'{print $2}\''; + if (_freebsd || _openbsd || _netbsd || _sunos) cmd = 'route get 0.0.0.0 | grep interface:'; + let result = execSync(cmd); + ifacename = result.toString().split('\n')[0]; + if (ifacename.indexOf(':') > -1) { + ifacename = ifacename.split(':')[1].trim(); + } } + } catch (e) { + util.noop(); } - if (ifacename) _default_iface = ifacename; return _default_iface; }