mem() prevent log messages, memgetDefaultNetworkInterface() catch errors

This commit is contained in:
Sebastian Hildebrandt 2020-01-24 23:13:04 +01:00
parent 777b51fd40
commit 51bb375ca3
5 changed files with 47 additions and 38 deletions

View File

@ -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 |

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.19.4</th>
<td>2020-01-24</td>
<td><span class="code">mem()</span> prevent log messages</td>
</tr>
<tr>
<th scope="row">4.19.3</th>
<td>2020-01-24</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.19.3</span></div>
<div class="version">Current Version: <span id="version">4.19.4</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -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) {

View File

@ -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;
}