To get the CPU temperature in Celsius in Rust, we can use the sysinfo
crate which provides a platform-agnostic way to get system information. Here's how you do it:
sysinfo
crate to your Cargo.toml
file:34 chars3 lines
SystemExt
trait and create a new System
instance:main.rs81 chars6 lines
Processor
(i.e. CPU) and convert it to Celsius:main.rs126 chars2 lines
The get_temperature()
method returns the temperature in millidegrees Celsius, so we divide it by 1000 to convert it to regular Celsius.
Here's the full code:
main.rs257 chars8 lines
gistlibby LogSnag