Files
hermes-config/skills/devops/cockpit-custom-packages/references/cpu-temp-data-format.md
T
2026-07-12 10:17:17 -04:00

90 lines
3.2 KiB
Markdown

# CPU Temperature Data Format (from nvidia-gpu-monitor)
The monitor script has been extended to write CPU temperatures alongside GPU data.
## cpu.txt (added by cockpit-custom-packages SKILL.md user session)
Written by the same systemd service (`nvidia-gpu-monitor`) that writes GPU data, every 5 seconds.
```
48,43,46
```
Comma-separated integers (no spaces):
| Index | Sensor | Source | Notes |
|-------|--------|--------|-------|
| 0 | CPU Package | `/sys/class/thermal/thermal_zone3/temp` | Main CPU temp, integer °C |
| 1 | PCH | `/sys/class/thermal/thermal_zone2/temp` | Platform Controller Hub temp |
| 2 | ACPI | `/sys/class/thermal/thermal_zone0/temp` | ACPI zone temp |
**Parsing**: `data.trim().split(',')` gives a 3-element array. Check `s.length >= 3` before accessing.
**Reading from shell**: `cat /sys/class/thermal/thermal_zone3/temp` returns millidegrees (e.g. `48000` = 48°C). Divide by 1000 for °C.
## Adding to the monitor script
Insert this block before the `sleep 5` in the monitor loop:
```bash
# CPU temps
pkg=$(cat /sys/class/thermal/thermal_zone3/temp 2>/dev/null || echo 0)
pch=$(cat /sys/class/thermal/thermal_zone2/temp 2>/dev/null || echo 0)
acpi=$(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null || echo 0)
echo "$((pkg/1000)),$((pch/1000)),$((acpi/1000))" > /usr/share/cockpit/nvidia-gpu/cpu.txt
```
## Adding a CPU Card to the Dashboard
Use the `accent-cyan` color class to distinguish from GPU cards:
```css
.card.accent-cyan{border-top:3px solid #06b6d4}
```
HTML pattern (compact, big-temp + mini stats):
```html
<div class="card accent-cyan"><h2>🔥 CPU</h2>
<div class="temp-group">
<div class="temp-big"><span class="temp-cold" id="cpu-temp">--</span><span class="unit">°C</span></div>
<div class="temp-mini">
<div class="temp-mini-item"><span>PCH</span><span class="val" id="pch-temp">-</span></div>
<div class="temp-mini-item"><span>ACPI</span><span class="val" id="acpi-temp">-</span></div>
</div>
</div>
<div class="bar-track"><div class="bar-fill temp" id="cpu-bar" style="width:0%"></div></div>
<div class="bar-labels"><span></span><span>50°</span><span>75°</span><span>100°</span></div>
</div>
```
JS to populate (inserted before the CUDA read):
```javascript
cockpit.spawn(["cat",PKG+"/cpu.txt"],{err:"message"}).done(function(d){
if(d&&d.trim()){var s=d.trim().split(',');if(s.length>=3){
var cp=parseInt(s[0]);$('cpu-temp').textContent=isNaN(cp)?'--':cp;
$('pch-temp').textContent=s[1]+'°';$('acpi-temp').textContent=s[2]+'°';
var tp=Math.min(100,Math.max(0,cp));$('cpu-bar').style.width=tp+'%';
var tc='temp-cold';if(cp>=50)tc='temp-mild';if(cp>=65)tc='temp-warm';if(cp>=80)tc='temp-hot';
$('cpu-temp').className=tc;
}}
});
```
Also add the 7th animation delay entry:
```css
.grid>*:nth-child(7){animation-delay:0.24s}
```
## Sensor Availability
Not all systems have all three thermal zones. The script uses `|| echo 0` fallback. Common zone mappings:
| Zone index | Typical sensor | Common on |
|------------|---------------|-----------|
| 0 | ACPI | All x86_64 |
| 1 | ACPI (secondary) | Laptops, multi-zone |
| 2 | PCH | Intel Comet Lake+ |
| 3 | x86_pkg_temp | All modern CPUs |