pub struct Component { /* private fields */ }Expand description
Getting a component temperature information.
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
if let Some(temperature) = component.temperature() {
println!("{} {temperature}°C", component.label());
} else {
println!("{} (unknown temperature)", component.label());
}
}Implementations§
Source§impl Component
impl Component
Sourcepub fn temperature(&self) -> Option<f32>
pub fn temperature(&self) -> Option<f32>
Returns the temperature of the component (in celsius degree).
§Linux
Returns f32::NAN if it failed to retrieve it.
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
if let Some(temperature) = component.temperature() {
println!("{temperature}°C");
}
}Sourcepub fn max(&self) -> Option<f32>
pub fn max(&self) -> Option<f32>
Returns the maximum temperature of the component (in celsius degree).
Note: if temperature is higher than the current max,
max value will be updated on refresh.
§Linux
May be computed by sysinfo from kernel.
Returns f32::NAN if it failed to retrieve it.
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
if let Some(max) = component.max() {
println!("{max}°C");
}
}Sourcepub fn critical(&self) -> Option<f32>
pub fn critical(&self) -> Option<f32>
Returns the highest temperature before the component halts (in celsius degree).
§Linux
Critical threshold defined by chip or kernel.
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
if let Some(critical) = component.critical() {
println!("{critical}°C");
}
}Sourcepub fn label(&self) -> &str
pub fn label(&self) -> &str
Returns the label of the component.
§Linux
Since components information is retrieved thanks to hwmon,
the labels are generated as follows.
Note: it may change and it was inspired by sensors own formatting.
| name | label | device_model | id_sensor | Computed label by sysinfo |
|---|---|---|---|---|
| ✓ | ✓ | ✓ | ✓ | "{name} {label} {device_model}" |
| ✓ | ✓ | ✗ | ✓ | "{name} {label}" |
| ✓ | ✗ | ✓ | ✓ | "{name} {device_model}" |
| ✓ | ✗ | ✗ | ✓ | "{name} temp{id}" |
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
println!("{}", component.label());
}Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
Returns the identifier of the component.
Note: The identifier should be reasonably unique but is provided by the kernel. It could change if the hardware changes or after a reboot.
| OS | Computed ID by sysinfo | Example |
|---|---|---|
| Linux/hwmon | hwmon file concatenated with the temp index. | hwmon0_1 if the temperature data comes from the hwmon0/temp1_input file. |
| Linux/thermal | thermal file name | thermal_zone0 |
| FreeBSD | cpu_ concatenated with the core index. | cpu_1 for the first core. |
| macOS/arm | Serial ID reported by the HID driver. | |
| macOS/x86 | Technical ID sent to the OS (see below) | TXCX |
| Windows | Computer (same as the label) | Computer |
| appstore | Components are not available | None |
| unknown | Components are not available | None |
For macOS on X86 the following identifiers are possible:
TXCXorTXCxfor PECI CPU (depending on if run on iMac or MacBook)TC0Pfor CPU ProximityTG0Pfor GPUTB0Tfor Battery
use sysinfo::Components;
let components = Components::new_with_refreshed_list();
for component in &components {
if let Some(id) = component.id() {
println!("{id}");
}
}