-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hardware temperatures (sensors_temperatures()) #371
Comments
From g.rodola on April 27, 2013 09:36:58 Committed in revision 22a650567ba7 in a separate branch by parsing files in /sys/class/hwmon/hwmon_/temp1__. Status: Started |
From g.rodola on June 17, 2013 03:53:59
|
From [email protected] on June 17, 2013 11:49:37 Neither of these works on my macbook running 10.8.4: [root@macbook ]# sysctl kern.cpu_temp_is_valid [root@macbook ]$ sysctl kern.cpu_temp I also don't see any reference to temp sensors in sysctlbyname docs: |
Would also like to see this feature. For RaspberryPi I'm now using: def get_cpu_temperature():
"""
Get CPU temperature.
"""
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as f:
temp = float(f.read()) / 1000.0
return temp But this doesn't work on OSX for example. |
Here's some C-code that gets the OSX temperature: https://github.com/lavoiesl/osx-cpu-temp |
Attaching a modified version of osx-cpu-temp C source code which I managed to compile (by modifying the Makefile). I get temperature == |
I'm not gonna have a chance to implement this on OSX as I don't have the hardware. |
@giampaolo if you can slap it in a branch, i can test it on osx |
OK, I've just merged the Linux implementation into master. For now this functionality is Linux only as:
|
@giampaolo coincidentally I decided to test your osx-cpu-temp on my osx when it's been on an ice-cold floor in its' case but your
Tested on macOS 10.11.6;
The iStats ruby package also provides CPU stats (
If you can also provide more decimals, that would be great but this seems to work fine. iStats also provides battery temperature:
|
Also tested it on the latest Raspbian (on raspberrypi)
and both master and 5.1.2 return not much:
|
@thijstriemstra Can you show what |
Like I mentioned, on an RPi it seems to be
|
That would be the problem then. ;) There's a comment about this for Ubuntu as well in the code. |
Should I open a new ticket? |
I believe it's working in those OSes but they provide more than one interface for CPU temperature (thermal_zone and hwmon) whereas Raspbian appears to only provide thermal_zone. And opening a ticket would probably be helpful. :) |
I see! |
Right now psutil reads temperatures from |
|
Closing out as fixed. |
I see that the issue is closed as fixed, but there doesn't seem to be any support for any sensors on macOS. I'm curious: why didn't this get implemented for macOS? There seem to be two pretty good libraries (SMCKit and iStats) that provide the necessary functionality (temps, fans, and battery.) I understand bloat might be a concern, but this seems like a reasonable use. |
I didn't implement this on OSX because I don't have the hardware. I virtualize OSX via VirtualBox but with that method it shows no temperatures (or battery). As such somebody else has to do it. |
Go for it! ;) |
On that note though, since as of now everything is self contained, what's the policy on using other libraries? |
I am against that as I don't want to introduce any installation requirement other than the C compiler. |
I started working on this in branch: https://github.com/Infinidat/psutil/tree/osx_sensors.
|
Great work! Some considerations:
|
I created a separate namedtuple for OSX for now, however the interface still doesn't look good. On Linux, every key in the returned dict returns a list of temperatures, while on OSX we only have one temperature per component.
|
I used to really like Windows API, but I don't think I'll have time to get into that 😉 |
No because |
Information about sensors on OSX in general: The code in my branch decodes only a few of the values (battery temperature, cpu temperature, fan current speed) but maybe it can read more values (e.g. there are "min/max fan speed" values and more temperatures). There is also still the question about the interface(s). It doesn't look like the Linux interface matches here exactly. @giampaolo the "sensors_battery" information uses a separate API that is documented and doesn't need the SMC. Would you be open to accepting a separate PR with this function implemented only? |
Thanks @JMY1000 . iStats only pulls a small subset of the codes (I already look at these codes in my branch - cpu temperature, battery temperature, fan speed). SMCKit pulls some more, but still far from all of the available list. |
@wiggin15 The iStats that I linked is not the same as iStat Menus or iStat Pro–it's a Ruby gem that actually goes through every sensor AFAIK. Run |
Of course. |
Most important ones are CPUs. I wouldn't mind other sensors for now. E.g. voltages don't exist at all in psutil. It would be nice to have CPU min / max limits though, because they are useful to implement apps which emit alarms. It sucks these APIs are so poorly documented. |
@giampaolo, I have been looking for a solution to this issue. Is there any way to know the |
|
@amanusk Not sure how you'd define what high is, but it seems like critical should be when it starts throttling. For Intel processors at least, you could pull the TJMAX from ARK, but there's got to be a better way of getting that info. I don't think it's baked into the CPUID info unfortunately. |
@giampaolo I have noticed it is not implemented ;), I might be able to work on it if I get access to hardware. My question is, whether you know of a method to get
In |
@amanusk Gotcha. If you'd be interested, I think I could set up access to hardware over ssh or something. Seems like @wiggin15 hasn't touched his stuff in a while. I'd also be happy to help. Not sure how to obtain that info. The official Intel Power Gadget seems to rely on a kext, but I'm not sure how it's grabbing the info below that. |
I compiled a list of all the temperature sensors accessible via the SMC
Note the underscores indicating the possibility of multiple sensors. These values will need to be scanned in a smart manner. |
Hoping to work on that PR some time in the next few months :/ |
From g.rodola on April 24, 2013 14:59:32
Proposal
I borrowed this idea from glances: https://github.com/nicolargo/glances
...which internally uses pysensors: https://pypi.python.org/pypi/PySensors/
API may look like this:
psutil.cpu_temperature(celsius=False)
could be used to express temperature infahrenheit. The order in which CPUs are returned should be the same as other
cpu_*
functions and be consistent across calls so that:
...and:
...will refer to the same CPU.
FreeBSD: http://superuser.com/questions/344498/get-temperature-of-cpu-intel-core-i5-in-freebsd
Original issue: http://code.google.com/p/psutil/issues/detail?id=371
The text was updated successfully, but these errors were encountered: