This is a proposition for an additional feature for gopsutil.
I've noticed CPU temperature measures were not available in gopsutil. I need such measures in one of my projects for macOS and Linux where I use gopsutil, so I started looking into a possible implementation of this.
Linux
The python psutil exposes a sensors_temperatures() function, that returns the current temperatures of multiple sensors. It is, however, only available for Linux for the moment. The way it is implemented is detailed in the source code: they use the /sys/class/hwmon interface. The drawback with this implementation is that it isn't explicitly indicated which sensors measure CPU temperature - which means it is up to the user to determinate it.
macOS
Even though their implementation doesn't support macOS, I've started to look if there were pieces of software that allowed the same thing. There is a Ruby program, called iStats, that shows system stats, including CPU temperature:
$ iStats
--- CPU Stats ---
CPU temp: 55.0°C ▁▂▃▅▆▇
--- Fan Stats ---
Total fans in system: 1
Fan 0 speed: 0.0 RPM ▁▂▃▅▆▇
[...]
The way it is implemented in the package is through a C library, smc.c, that acts as an interface to the Apple System Management Control tool (that has such information).
Implementation proposition
Given that we would like a platform-agnostic implementation, what we could do is provide a global get_sensors_temperatures() function, that would:
- In the case of a Linux machine, return all the sensors' temperatures as a list
- In the case of a macOS, return only the CPU's temperature, but as a list, to match the types of the Linux implementation (unless there are other temperature sensors that could be interesting to expose?).
Information retrieval would be trivial on Linux, considering the source code of the python version of psutil, but the macOS implementation would either require to import smc.c through Cgo, or using a full-Go version. It seems there is a Go port of smc, that is built with Cgo.
What do active contributors think? Do you think it could be worth it to implement this? If so, what approach should we take into implementing this?
This is a proposition for an additional feature for gopsutil.
I've noticed CPU temperature measures were not available in gopsutil. I need such measures in one of my projects for macOS and Linux where I use gopsutil, so I started looking into a possible implementation of this.
Linux
The python psutil exposes a
sensors_temperatures()function, that returns the current temperatures of multiple sensors. It is, however, only available for Linux for the moment. The way it is implemented is detailed in the source code: they use the/sys/class/hwmoninterface. The drawback with this implementation is that it isn't explicitly indicated which sensors measure CPU temperature - which means it is up to the user to determinate it.macOS
Even though their implementation doesn't support macOS, I've started to look if there were pieces of software that allowed the same thing. There is a Ruby program, called iStats, that shows system stats, including CPU temperature:
The way it is implemented in the package is through a C library,
smc.c, that acts as an interface to the Apple System Management Control tool (that has such information).Implementation proposition
Given that we would like a platform-agnostic implementation, what we could do is provide a global
get_sensors_temperatures()function, that would:Information retrieval would be trivial on Linux, considering the source code of the python version of
psutil, but the macOS implementation would either require to importsmc.cthrough Cgo, or using a full-Go version. It seems there is a Go port of smc, that is built with Cgo.What do active contributors think? Do you think it could be worth it to implement this? If so, what approach should we take into implementing this?