Repository navigation
feat: add cpu temperature readings for other cpu architectures and OS's - #14
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cpuTempCnow reads sensors through gopsutil and pins one sensor for thelifetime of the process, so successive readings always come from the same
source.
Fixes #6
Why
gopsutil doesn't guarantee the order of the sensors it returns, so picking
temps[0](or the first match) can return a different sensor from one call tothe next. Package and per-core temperatures can differ by several degrees, so
the displayed value could jump without any real change in temperature.
Changes
cpuSensorPrefixesin preference order, sopackage-level sensors win over per-core ones. The first successful call pins
that sensor's full
SensorKey.function returns
(0, false)rather than falling back to another sensor./sys/class/thermalread withgithub.com/shirou/gopsutil/v4/sensors(pure Go, no cgo).go.modandgo.sumare updated.Behavior to be aware of
(0, false)is returned on any error fromSensorsTemperatures(includingwarnings about individual unreadable sensors) and when no sensor matches.
This is the normal result on VMs, containers, WSL, and Windows.
renames it) means no temperature until restart. This is deliberately strict;
I can add a reset after N consecutive misses if you'd prefer.
elevated. It isn't guaranteed to be the CPU, so I left it out of
cpuSensorPrefixes. The function reports a real CPU measurement or says itcan't.
Testing
fake sysfs tree via
HOST_SYScontainingcoretemp_package_id_0andcoretemp_core_0. The package sensor was selected and its readingdisplayed.
(0, false).it exposes one ACPI thermal zone (
ACPI\ThermalZone\TZ00_0) that doesn'treliably map to the CPU, so
cpuTempCreturns(0, false)and the UI showsn/a.
go vet ./...andgo test ./...pass on Linux/WSL. On Windows,TestKeyFilesAreNotWorldReadableandTestStateFileIsPrivateAndValidfailbecause Go reports
0666/0777there regardless of real permissions. Theyare unrelated to this change, and I left them alone to keep the PR focused.
pinning if you'd like them.