cpuTemperature() fix try catch (linux)
This commit is contained in:
parent
659f2b1225
commit
dfc19f55bb
@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 4.27.5 | 2020-09-18 | `cpuTemperature()` fix try catch (linux) |
|
||||||
| 4.27.4 | 2020-09-16 | `networkInterfaceDefault()` optimization (macOS) |
|
| 4.27.4 | 2020-09-16 | `networkInterfaceDefault()` optimization (macOS) |
|
||||||
| 4.27.3 | 2020-08-26 | updated typescript typings |
|
| 4.27.3 | 2020-08-26 | updated typescript typings |
|
||||||
| 4.27.2 | 2020-08-26 | fixed issue breaking node v4 compatibility |
|
| 4.27.2 | 2020-08-26 | fixed issue breaking node v4 compatibility |
|
||||||
|
|||||||
@ -83,6 +83,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">4.27.5</th>
|
||||||
|
<td>2020-09-18</td>
|
||||||
|
<td><span class="code">cpuTemperature()</span> fixed try catch (linux)</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">4.27.4</th>
|
<th scope="row">4.27.4</th>
|
||||||
<td>2020-09-16</td>
|
<td>2020-09-16</td>
|
||||||
|
|||||||
@ -168,7 +168,7 @@
|
|||||||
<img class="logo" src="assets/logo.png">
|
<img class="logo" src="assets/logo.png">
|
||||||
<div class="title">systeminformation</div>
|
<div class="title">systeminformation</div>
|
||||||
<div class="subtitle"><span id="typed"></span></div>
|
<div class="subtitle"><span id="typed"></span></div>
|
||||||
<div class="version">Current Version: <span id="version">4.27.4</span></div>
|
<div class="version">Current Version: <span id="version">4.27.5</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>
|
<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>
|
||||||
<div class="down">
|
<div class="down">
|
||||||
|
|||||||
246
lib/cpu.js
246
lib/cpu.js
@ -758,100 +758,105 @@ function cpuTemperature(callback) {
|
|||||||
};
|
};
|
||||||
if (_linux) {
|
if (_linux) {
|
||||||
const cmd = 'cat /sys/class/hwmon/hwmon1/temp*_la*;echo "---";cat /sys/class/hwmon/hwmon1/temp*_i*';
|
const cmd = 'cat /sys/class/hwmon/hwmon1/temp*_la*;echo "---";cat /sys/class/hwmon/hwmon1/temp*_i*';
|
||||||
exec(cmd, function (error, stdout) {
|
try {
|
||||||
if (!error) {
|
exec(cmd, function (error, stdout) {
|
||||||
let parts = stdout.toString().split('---');
|
|
||||||
let labels = parts[0].split('\n');
|
|
||||||
let temps = parts[1].split('\n');
|
|
||||||
temps.shift();
|
|
||||||
for (let i = 0; i < temps.length; i++) {
|
|
||||||
if (temps[i] && (labels[i] === undefined || (labels[i] && labels[i].toLowerCase().startsWith('core')))) {
|
|
||||||
result.cores.push(Math.round(parseInt(temps[i], 10) / 100) / 10);
|
|
||||||
} else if (temps[i] && labels[i] && result.main === -1) {
|
|
||||||
result.main = Math.round(parseInt(temps[i], 10) / 100) / 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.cores.length > 0) {
|
|
||||||
if (result.main === -1) {
|
|
||||||
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
|
|
||||||
}
|
|
||||||
let maxtmp = Math.max.apply(Math, result.cores);
|
|
||||||
result.max = (maxtmp > result.main) ? maxtmp : result.main;
|
|
||||||
}
|
|
||||||
if (result.main !== -1) {
|
|
||||||
if (result.max === -1) {
|
|
||||||
result.max = result.main;
|
|
||||||
}
|
|
||||||
if (callback) { callback(result); }
|
|
||||||
resolve(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exec('sensors', function (error, stdout) {
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let parts = stdout.toString().split('---');
|
||||||
let tdieTemp = -1;
|
let labels = parts[0].split('\n');
|
||||||
lines.forEach(function (line) {
|
let temps = parts[1].split('\n');
|
||||||
let regex = /[+-]([^°]*)/g;
|
temps.shift();
|
||||||
let temps = line.match(regex);
|
for (let i = 0; i < temps.length; i++) {
|
||||||
let firstPart = line.split(':')[0].toUpperCase();
|
if (temps[i] && (labels[i] === undefined || (labels[i] && labels[i].toLowerCase().startsWith('core')))) {
|
||||||
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
|
result.cores.push(Math.round(parseInt(temps[i], 10) / 100) / 10);
|
||||||
result.main = parseFloat(temps);
|
} else if (temps[i] && labels[i] && result.main === -1) {
|
||||||
|
result.main = Math.round(parseInt(temps[i], 10) / 100) / 10;
|
||||||
}
|
}
|
||||||
if (firstPart.indexOf('CORE ') !== -1) {
|
}
|
||||||
result.cores.push(parseFloat(temps));
|
|
||||||
}
|
|
||||||
if (firstPart.indexOf('TDIE') !== -1 && tdieTemp === -1) {
|
|
||||||
tdieTemp = parseFloat(temps);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (result.cores.length > 0) {
|
if (result.cores.length > 0) {
|
||||||
if (result.main === -1) {
|
if (result.main === -1) {
|
||||||
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
|
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
|
||||||
}
|
}
|
||||||
let maxtmp = Math.max.apply(Math, result.cores);
|
let maxtmp = Math.max.apply(Math, result.cores);
|
||||||
result.max = (maxtmp > result.main) ? maxtmp : result.main;
|
result.max = (maxtmp > result.main) ? maxtmp : result.main;
|
||||||
} else {
|
|
||||||
if (result.main === -1 && tdieTemp !== -1) {
|
|
||||||
result.main = tdieTemp;
|
|
||||||
result.max = tdieTemp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (result.main !== -1.0 || result.max !== -1.0) {
|
if (result.main !== -1) {
|
||||||
|
if (result.max === -1) {
|
||||||
|
result.max = result.main;
|
||||||
|
}
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
|
exec('sensors', function (error, stdout) {
|
||||||
if (err === null) {
|
if (!error) {
|
||||||
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
let lines = stdout.toString().split('\n');
|
||||||
if (!error) {
|
let tdieTemp = -1;
|
||||||
let lines = stdout.toString().split('\n');
|
lines.forEach(function (line) {
|
||||||
if (lines.length > 0) {
|
let regex = /[+-]([^°]*)/g;
|
||||||
result.main = parseFloat(lines[0]) / 1000.0;
|
let temps = line.match(regex);
|
||||||
result.max = result.main;
|
let firstPart = line.split(':')[0].toUpperCase();
|
||||||
}
|
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
|
||||||
|
result.main = parseFloat(temps);
|
||||||
}
|
}
|
||||||
|
if (firstPart.indexOf('CORE ') !== -1) {
|
||||||
|
result.cores.push(parseFloat(temps));
|
||||||
|
}
|
||||||
|
if (firstPart.indexOf('TDIE') !== -1 && tdieTemp === -1) {
|
||||||
|
tdieTemp = parseFloat(temps);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (result.cores.length > 0) {
|
||||||
|
if (result.main === -1) {
|
||||||
|
result.main = Math.round(result.cores.reduce((a, b) => a + b, 0) / result.cores.length);
|
||||||
|
}
|
||||||
|
let maxtmp = Math.max.apply(Math, result.cores);
|
||||||
|
result.max = (maxtmp > result.main) ? maxtmp : result.main;
|
||||||
|
} else {
|
||||||
|
if (result.main === -1 && tdieTemp !== -1) {
|
||||||
|
result.main = tdieTemp;
|
||||||
|
result.max = tdieTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result.main !== -1.0 || result.max !== -1.0) {
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
return;
|
||||||
} else {
|
}
|
||||||
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
|
|
||||||
if (!error) {
|
|
||||||
let lines = stdout.toString().split('\n');
|
|
||||||
if (lines.length > 0 && lines[0].indexOf('=')) {
|
|
||||||
result.main = parseFloat(lines[0].split('=')[1]);
|
|
||||||
result.max = result.main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (callback) { callback(result); }
|
|
||||||
resolve(result);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
|
||||||
|
if (err === null) {
|
||||||
|
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
||||||
|
if (!error) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
if (lines.length > 0) {
|
||||||
|
result.main = parseFloat(lines[0]) / 1000.0;
|
||||||
|
result.max = result.main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (callback) { callback(result); }
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
|
||||||
|
if (!error) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
if (lines.length > 0 && lines[0].indexOf('=')) {
|
||||||
|
result.main = parseFloat(lines[0].split('=')[1]);
|
||||||
|
result.max = result.main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (callback) { callback(result); }
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
} catch (er) {
|
||||||
|
if (callback) { callback(result); }
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_freebsd || _openbsd || _netbsd) {
|
if (_freebsd || _openbsd || _netbsd) {
|
||||||
exec('sysctl dev.cpu | grep temp', function (error, stdout) {
|
exec('sysctl dev.cpu | grep temp', function (error, stdout) {
|
||||||
@ -962,29 +967,35 @@ function cpuFlags(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_linux) {
|
if (_linux) {
|
||||||
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
|
try {
|
||||||
if (!error) {
|
|
||||||
let lines = stdout.toString().split('\n');
|
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
|
||||||
lines.forEach(function (line) {
|
if (!error) {
|
||||||
if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
|
let lines = stdout.toString().split('\n');
|
||||||
result = line.split(':')[1].trim().toLowerCase();
|
lines.forEach(function (line) {
|
||||||
}
|
if (line.split(':')[0].toUpperCase().indexOf('FLAGS') !== -1) {
|
||||||
});
|
result = line.split(':')[1].trim().toLowerCase();
|
||||||
}
|
}
|
||||||
if (!result) {
|
});
|
||||||
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
}
|
||||||
if (!error) {
|
if (!result) {
|
||||||
let lines = stdout.toString().split('\n');
|
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
||||||
result = util.getValue(lines, 'features', ':', true).toLowerCase();
|
if (!error) {
|
||||||
}
|
let lines = stdout.toString().split('\n');
|
||||||
|
result = util.getValue(lines, 'features', ':', true).toLowerCase();
|
||||||
|
}
|
||||||
|
if (callback) { callback(result); }
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
if (callback) { callback(result); }
|
} catch (e) {
|
||||||
resolve(result);
|
if (callback) { callback(result); }
|
||||||
}
|
resolve(result);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if (_freebsd || _openbsd || _netbsd) {
|
if (_freebsd || _openbsd || _netbsd) {
|
||||||
exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; unset LC_ALL', function (error, stdout) {
|
exec('export LC_ALL=C; dmidecode -t 4 2>/dev/null; unset LC_ALL', function (error, stdout) {
|
||||||
@ -1041,28 +1052,33 @@ function cpuCache(callback) {
|
|||||||
l3: -1,
|
l3: -1,
|
||||||
};
|
};
|
||||||
if (_linux) {
|
if (_linux) {
|
||||||
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
|
try {
|
||||||
if (!error) {
|
exec('export LC_ALL=C; lscpu; unset LC_ALL', function (error, stdout) {
|
||||||
let lines = stdout.toString().split('\n');
|
if (!error) {
|
||||||
lines.forEach(function (line) {
|
let lines = stdout.toString().split('\n');
|
||||||
let parts = line.split(':');
|
lines.forEach(function (line) {
|
||||||
if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
|
let parts = line.split(':');
|
||||||
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
if (parts[0].toUpperCase().indexOf('L1D CACHE') !== -1) {
|
||||||
}
|
result.l1d = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
||||||
if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
|
}
|
||||||
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
if (parts[0].toUpperCase().indexOf('L1I CACHE') !== -1) {
|
||||||
}
|
result.l1i = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
||||||
if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
|
}
|
||||||
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
if (parts[0].toUpperCase().indexOf('L2 CACHE') !== -1) {
|
||||||
}
|
result.l2 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
||||||
if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
|
}
|
||||||
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
if (parts[0].toUpperCase().indexOf('L3 CACHE') !== -1) {
|
||||||
}
|
result.l3 = parseInt(parts[1].trim()) * (parts[1].indexOf('K') !== -1 ? 1024 : 1);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
if (callback) { callback(result); }
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if (_freebsd || _openbsd || _netbsd) {
|
if (_freebsd || _openbsd || _netbsd) {
|
||||||
exec('export LC_ALL=C; dmidecode -t 7 2>/dev/null; unset LC_ALL', function (error, stdout) {
|
exec('export LC_ALL=C; dmidecode -t 7 2>/dev/null; unset LC_ALL', function (error, stdout) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user