Skip to content

Commit

Permalink
cpuTemperature() added socket and chipset temp (linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Mar 3, 2021
1 parent d40b85c commit bb82868
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -46,6 +46,7 @@ We had to make **several interface changes** to keep systeminformation as consis
- `cpu()`: extended socket list (win)
- `cpu()`: added virtualization if cpu supports virtualization
- `cpu()`: now flags are part of this function
- `cpuTemperature()` added added socket and chipset temp (linux)
- `diskLayout()`: added USB drives (mac OS)
- `fsSize()`: added available
- `fsSize()`: improved calculation of used
Expand Down Expand Up @@ -76,6 +77,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.

| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 5.6.0 | 2021-03-03 | `cpuTemperature()` added socket and chipset temp (linux) |
| 5.5.0 | 2021-02-25 | `dockerVolumes()` added |
| 5.4.0 | 2021-02-24 | `dockerImages()` added |
| 5.3.5 | 2021-02-23 | `dockerContainerStats()` fixed parameter * |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -103,14 +103,13 @@ si.cpu()

(last 7 major and minor version releases)

- Version 5.6.0: `cpuTemperature()` added added socket and chipset temp (linux)
- Version 5.5.0: `dockerVolumes()` added
- Version 5.4.0: `dockerImages()` added
- Version 5.3.0: `osInfo()` added remoteSession (win only)
- Version 5.2.0: `wifiInterfaces()` and `wifiConnections()` added
- Version 5.1.0: `memLayout()` added ECC flag, `bios()` added language, features (linux)
- Version 5.0.0: new version 5 - attention there are some breaking changes. See [detailed version 5 changes here][changes5-url].
- Version 4.34.0: `system()` added flag virtual (linux, windows)
- Version 4.33.0: `graphics()` added nvidia-smi support (linux, windows)
- ...

You can find all changes here: [detailed changelog][changelog-url]
Expand Down Expand Up @@ -224,6 +223,8 @@ Full function reference with examples can be found at [https://systeminformation
| | main | X | X | X | X | | main temperature (avg) |
| | cores | X | X | X | X | | array of temperatures |
| | max | X | X | X | X | | max temperature |
| | socket | X | | | | | array socket temperatures |
| | chipset | X | | | | | chipset temperature |

#### 4. Memory

Expand Down
1 change: 1 addition & 0 deletions docs/changes.html
Expand Up @@ -173,6 +173,7 @@ <h4>Other Improvements and Changes</h4>
<li><span class="code">cpu()</span>: extended socket list (win)</li>
<li><span class="code">cpu()</span>: added <span class="code">virtualization</span> if cpu supports virtualization</li>
<li><span class="code">cpu()</span>: now <span class="code">flags</span> are part of this function</li>
<li><span class="code">cpuTemperature()</span>: added socket and chipset temperature (linux)</li>
<li><span class="code">fsSize()</span>: added <span class="code">available</span></li>
<li><span class="code">fsSize()</span>: improved calculation of <span class="code">used</span></li>
<li><span class="code">getData()</span>: support for passing parameters and filters (see <a href="general.html">section General / getData</a>)</li>
Expand Down
31 changes: 30 additions & 1 deletion docs/cpu.html
Expand Up @@ -545,14 +545,43 @@ <h5>Example</h5>
<td></td>
<td>max temperature</td>
</tr>
<tr>
<td></td>
<td>socket</td>
<td>X</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>array socket temperatures</td>
</tr>
<tr>
<td></td>
<td>chipset</td>
<td>X</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>chipset temperature</td>
</tr>
<tr class="example">
<td></td>
<td colspan="7">
<h5>Example</h5>
<pre><code class="js">const si = require('systeminformation');
si.cpuTemperature().then(data => console.log(data));</code></pre class="example">
<pre class="example">
{ main: 42, cores: [], max: 42 }
{
main: 42,
cores: [
34, 35, 33, 32,
37, 32, 35, 33
],
max: 42,
socket: [ 16.8, 27.8 ],
chipset: 49
}
</pre>
</tr>
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions docs/history.html
Expand Up @@ -56,6 +56,11 @@ <h3>Full version history</h3>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.6.0</th>
<td>2021-03-03</td>
<td><span class="code">cpuTemperature()</span> added socket and chipset temp (linux)</td>
</tr>
<tr>
<th scope="row">5.5.0</th>
<td>2021-02-25</td>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Expand Up @@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.5.0</span></div>
<div class="version">New Version: <span id="version">5.6.0</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">
Expand Down Expand Up @@ -201,15 +201,15 @@
</div>
<div class="row number-section">
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">14,053</div>
<div class="numbers">14,121</div>
<div class="title">Lines of code</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div id="downloads" class="numbers">...</div>
<div class="title">Downloads last month</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">389</div>
<div class="numbers">390</div>
<div class="title">Dependents</div>
</div>
</div>
Expand Down
49 changes: 47 additions & 2 deletions lib/cpu.js
Expand Up @@ -930,9 +930,32 @@ function cpuTemperature(callback) {
let result = {
main: null,
cores: [],
max: null
max: null,
socket: [],
chipset: null
};
if (_linux) {
// CPU Chipset, Socket
try {
const cmd = 'cat /sys/class/thermal/thermal_zone*/type; echo "-----"; cat /sys/class/thermal/thermal_zone*/temp;';
const parts = execSync(cmd).toString().split('-----\n');
if (parts.length === 2) {
const lines = parts[0].split('\n');
const lines2 = parts[1].split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('acpi') && lines2[i]) {
result.socket.push(Math.round(parseInt(lines2[i], 10) / 100) / 10);
}
if (line.startsWith('pch') && lines2[i]) {
result.chipset = Math.round(parseInt(lines2[i], 10) / 100) / 10;
}
}
}
} catch (e) {
util.noop();
}

const cmd = 'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=$(echo $label | rev | cut -c 7- | rev)_input; if [ -f "$value" ]; then echo $(cat "$label")___$(cat "$value"); fi; fi; done; done;';
try {
exec(cmd, function (error, stdout) {
Expand Down Expand Up @@ -963,15 +986,37 @@ function cpuTemperature(callback) {
resolve(result);
return;
}
// }
exec('sensors', function (error, stdout) {
if (!error) {
let lines = stdout.toString().split('\n');
let tdieTemp = null;
let newSectionStarts = true;
let section = '';
lines.forEach(function (line) {
// determine section
if (line.trim() === '') {
newSectionStarts = true;
} else if (newSectionStarts) {
if (line.trim().toLowerCase().startsWith('acpi')) { section = 'acpi'; }
if (line.trim().toLowerCase().startsWith('pch')) { section = 'pch'; }
if (line.trim().toLowerCase().startsWith('core')) { section = 'core'; }
newSectionStarts = false;
}
let regex = /[+-]([^°]*)/g;
let temps = line.match(regex);
let firstPart = line.split(':')[0].toUpperCase();
if (section === 'acpi') {
// socket temp
if (firstPart.indexOf('TEMP') !== -1) {
result.socket.push(parseFloat(temps));
}
} else if (section === 'pch') {
// chipset temp
if (firstPart.indexOf('TEMP') !== -1) {
result.chipset = parseFloat(temps);
}
}
// cpu temp
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
result.main = parseFloat(temps);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Expand Up @@ -104,6 +104,8 @@ export namespace Systeminformation {
main: number;
cores: number[];
max: number;
socket?: number[];
chipset?: number;
}

interface MemData {
Expand Down

0 comments on commit bb82868

Please sign in to comment.