12个版本

0.3.0 2024年6月14日
0.2.2 2024年3月27日
0.2.1 2024年1月20日
0.2.0 2023年10月9日
0.1.3 2021年11月27日

#201 in Unix APIs

Download history 29/week @ 2024-04-25 31/week @ 2024-05-02 9/week @ 2024-05-09 24/week @ 2024-05-16 16/week @ 2024-05-23 26/week @ 2024-05-30 11/week @ 2024-06-06 197/week @ 2024-06-13 14/week @ 2024-06-20 24/week @ 2024-06-27 36/week @ 2024-07-04 4/week @ 2024-07-11 18/week @ 2024-07-18 69/week @ 2024-07-25 16/week @ 2024-08-01

每月下载量 105次

MIT 许可证

155KB
3.5K SLoC

crates.io docs.rs license

基于LM Sensors的Linux系统硬件监控

lm-sensors为Linux中的硬件监控驱动程序提供了用户空间支持。

此crate针对Linux特定。为非Linux平台或Linux内核构建它会导致crate为空。

此crate链接到libsensors,并需要安装它。通过依赖sensors-sys crate来间接链接到libsensors。其他sensors-sys crate文档说明了如何安装libsensors以及如何控制链接的各个方面。

列出所有可用传感器

// Initialize LM sensors library.
let sensors = lm_sensors::Initializer::default().initialize()?;

// Print all chips.
for chip in sensors.chip_iter(None) {
    if let Some(path) = chip.path() {
        println!("chip: {} at {} ({})", chip, chip.bus(), path.display());
    } else {
        println!("chip: {} at {}", chip, chip.bus());
    }

    // Print all features of the current chip.
    for feature in chip.feature_iter() {
        let name = feature.name().transpose()?.unwrap_or("N/A");
        println!("    {}: {}", name, feature);

        // Print all sub-features of the current chip feature.
        for sub_feature in feature.sub_feature_iter() {
            if let Ok(value) = sub_feature.value() {
                println!("        {}: {}", sub_feature, value);
            } else {
                println!("        {}: N/A", sub_feature);
            }
        }
    }
}
# Ok::<(), lm_sensors::errors::Error>(())

以下是在上述示例中的输出示例

chip: iwlwifi_1-virtual-0 at Virtual device (/sys/class/hwmon/hwmon8)
    temp1: temp1
        temp1_input: N/A
chip: pch_cometlake-virtual-0 at Virtual device (/sys/class/hwmon/hwmon6)
    temp1: temp1
        temp1_input: 67 C
chip: ucsi_source_psy_USBC000:001-isa-0000 at ISA adapter (/sys/class/hwmon/hwmon10)
    in0: in0
        in0_input: 5 V
        in0_min: 5 V
        in0_max: 5 V
    curr1: curr1
        curr1_input: 0 A
        curr1_max: 1.5 A
chip: coretemp-isa-0000 at ISA adapter (/sys/class/hwmon/hwmon4)
    temp1: Package id 0
        temp1_input: 71 C
        temp1_max: 100 C
        temp1_crit: 100 C
        temp1_crit_alarm:
    temp2: Core 0
        temp2_input: 62 C
        temp2_max: 100 C
        temp2_crit: 100 C
        temp2_crit_alarm:
    temp3: Core 1
        temp3_input: 63 C
        temp3_max: 100 C
        temp3_crit: 100 C
        temp3_crit_alarm:
    temp4: Core 2
        temp4_input: 63 C
        temp4_max: 100 C
        temp4_crit: 100 C
        temp4_crit_alarm:
    temp5: Core 3
        temp5_input: 71 C
        temp5_max: 100 C
        temp5_crit: 100 C
        temp5_crit_alarm:
    temp6: Core 4
        temp6_input: 62 C
        temp6_max: 100 C
        temp6_crit: 100 C
        temp6_crit_alarm:
    temp7: Core 5
        temp7_input: 63 C
        temp7_max: 100 C
        temp7_crit: 100 C
        temp7_crit_alarm:
    temp8: Core 6
        temp8_input: 61 C
        temp8_max: 100 C
        temp8_crit: 100 C
        temp8_crit_alarm:
    temp9: Core 7
        temp9_input: 61 C
        temp9_max: 100 C
        temp9_crit: 100 C
        temp9_crit_alarm:
chip: nvme-pci-0200 at PCI adapter (/sys/class/hwmon/hwmon2)
    temp1: Composite
        temp1_input: 52.85 C
        temp1_max: 84.85 C
        temp1_min: -273.15 C
        temp1_crit: 84.85 C
        temp1_alarm:
    temp2: Sensor 1
        temp2_input: 52.85 C
        temp2_max: 65261.85 C
        temp2_min: -273.15 C
    temp3: Sensor 2
        temp3_input: 45.85 C
        temp3_max: 65261.85 C
        temp3_min: -273.15 C
chip: acpitz-acpi-0 at ACPI interface (/sys/class/hwmon/hwmon0)
    temp1: temp1
        temp1_input: 61 C
        temp1_crit: 128 C
chip: thinkpad-isa-0000 at ISA adapter (/sys/class/hwmon/hwmon7)
    fan1: fan1
        fan1_input: 2657 RPM
    fan2: fan2
        fan2_input: 2583 RPM
    temp1: CPU
        temp1_input: 61 C
    temp2: GPU
        temp2_input: 58 C
    temp3: temp3
        temp3_input: 64 C
    temp4: temp4
        temp4_input: 1 C
    temp5: temp5
        temp5_input: 60 C
    temp6: temp6
        temp6_input: 65 C
    temp7: temp7
        temp7_input: 68 C
    temp8: temp8
        temp8_input: 0 C
chip: ucsi_source_psy_USBC000:002-isa-0000 at ISA adapter (/sys/class/hwmon/hwmon11)
    in0: in0
        in0_input: 0 V
        in0_min: 0 V
        in0_max: 0 V
    curr1: curr1
        curr1_input: 0 A
        curr1_max: 0 A
chip: nvme-pci-5500 at PCI adapter (/sys/class/hwmon/hwmon3)
    temp1: Composite
        temp1_input: 51.85 C
        temp1_max: 83.85 C
        temp1_min: -273.15 C
        temp1_crit: 84.85 C
        temp1_alarm: 
    temp2: Sensor 1
        temp2_input: 51.85 C
        temp2_max: 65261.85 C
        temp2_min: -273.15 C
    temp3: Sensor 2
        temp3_input: 48.85 C
        temp3_max: 65261.85 C
        temp3_min: -273.15 C
chip: BAT0-acpi-0 at ACPI interface (/sys/class/hwmon/hwmon1)
    in0: in0
        in0_input: 12.255 V

版本控制

本项目遵循语义版本控制CHANGELOG.md文件详细说明了随时间的变化。

依赖项

~0.8–8.5MB
~73K SLoC