Added temperatures sensors for macOS and Linux#334
Merged
shirou merged 2 commits intoshirou:masterfrom Apr 10, 2017
Merged
Conversation
shirou
requested changes
Mar 20, 2017
Owner
shirou
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
Could you change to use HostSys and add some tests to host/host_test.go ?
|
|
||
| func SensorsTemperatures() ([]TemperatureStat, error) { | ||
| var temperatures []TemperatureStat | ||
| files, err := filepath.Glob("/sys/class/hwmon/hwmon*/temp*_*") |
Owner
There was a problem hiding this comment.
Could you use common.HostSys to change /sys path via environment variable?
Owner
|
Thank you! It works like a charm at least on my Darwin environment. awesome! |
Added TemperatureStat string test
660e857 to
22aefb4
Compare
Contributor
Author
|
Sure! I didn't add any unit tests for |
shirou
approved these changes
Apr 10, 2017
Owner
|
I'm very sorry. I have not noticed your update. It seems good for me. Thank you for your contribution! |
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.
This pull request, following #329, introduces in the
hostpackage :TemperatureStat, that stores a temperature key and its sensor value. This is to ensure a standard portable structure for temperature sensors data for the package:A new function,
SensorsTemperatures(), available for the moment on macOS and Linux builds. This function returns a list ofTemperatureStatobjects - each of these objects represent the value of a temperature sensor.On Linux, the data is obtained the same way as psutil, through the
hwmoninterface. It is syntaxically correct and follows the psutil's procedure, but hasn't been tested properly yet - if a Linux-using contributor could test this is on their machine, I would be grateful for it.On macOS, the data is obtained through the System Management Controller, with a C library acting as a middleman (
host/include/smc.{c,h}). This C library is GNU-licensed, and the license has been kept as-is. Thus, the function is only available for Cgo-enabled builds. Match between a sensor key and what it represents is available in thehost/include/smc.hfile. The function returns 0 for a sensor value if there was an error on the SMC side or that the sensor is not available, which is the normal behaviour of the SMC function - but if we only want values that could have been accessed, we could ignored sensor values that are equal to 0.This is my first contribution to the project, so if any contributor has any comment on this, please feel free to speak up!