lm_sensors
lm_sensors (Linux 监控传感器) 是一个免费且开源的应用程序,提供用于监控温度、电压和风扇的工具和驱动程序。本文档解释了如何安装、配置和使用 lm_sensors。
安装
安装 lm_sensors 软件包。
配置
使用 sensors-detect 以 root 身份检测并生成内核模块列表
Enter
)。请参阅 #运行 sensors-detect 后笔记本电脑屏幕出现问题。# sensors-detect
它将询问是否探测各种硬件。“安全”答案是默认值,因此通常只需对所有问题按 Enter
即可,不会造成任何问题。这将创建 /etc/conf.d/lm_sensors
配置文件,lm_sensors.service
使用该文件在启动时自动加载内核模块。
--auto
标志自动接受 sensors-detect
的所有安全答案。检测完成后,将显示探测摘要。
示例
# sensors-detect
This program will help you determine which kernel modules you need to load to use lm_sensors most effectively. It is generally safe and recommended to accept the default answers to all questions, unless you know what you're doing. Some south bridges, CPUs or memory controllers contain embedded sensors. Do you want to scan for them? This is totally safe. (YES/no): Module cpuid loaded successfully. Silicon Integrated Systems SIS5595... No VIA VT82C686 Integrated Sensors... No VIA VT8231 Integrated Sensors... No AMD K8 thermal sensors... No AMD Family 10h thermal sensors... No ... Now follows a summary of the probes I have just done. Just press ENTER to continue: Driver `coretemp': * Chip `Intel digital thermal sensor' (confidence: 9) Driver `lm90': * Bus `SMBus nForce2 adapter at 4d00' Busdriver `i2c_nforce2', I2C address 0x4c Chip `Winbond W83L771AWG/ASG' (confidence: 6) Do you want to overwrite /etc/conf.d/lm_sensors? (YES/no): ln -s '/usr/lib/systemd/system/lm_sensors.service' '/etc/systemd/system/multi-user.target.wants/lm_sensors.service' Unloading i2c-dev... OK Unloading cpuid... OK
/etc/conf.d/lm_sensors
时回答 YES,则会自动启用 systemd 服务。回答 YES 也会自动启动该服务。运行 sensors
运行 sensors
的示例
$ sensors
coretemp-isa-0000 Adapter: ISA adapter Core 0: +35.0°C (crit = +105.0°C) Core 1: +32.0°C (crit = +105.0°C) w83l771-i2c-0-4c Adapter: SMBus nForce2 adapter at 4d00 temp1: +28.0°C (low = -40.0°C, high = +70.0°C) (crit = +85.0°C, hyst = +75.0°C) temp2: +37.4°C (low = -40.0°C, high = +70.0°C) (crit = +110.0°C, hyst = +100.0°C)
添加 DIMM 温度传感器
要查找 DIMM 的温度传感器,安装 i2c-tools 软件包。安装完成后,加载 i2c-dev
内核模块。
# modprobe i2c_dev
要显示所有列,请以 root 身份使用 i2cdetect
# i2cdetect -l
i2c-2 smbus SMBus PIIX4 adapter port 2 at 0b00 SMBus adapter i2c-2 smbus SMBus PIIX4 adapter port 1 at 0b20 SMBus adapter i2c-0 smbus SMBus PIIX4 adapter port 0 at 0b00 SMBus adapter
否则,其输出将如下所示
i2c-2 unknown SMBus PIIX4 adapter port 2 at 0b00 N/A i2c-2 unknown SMBus PIIX4 adapter port 1 at 0b20 N/A i2c-0 unknown SMBus PIIX4 adapter port 0 at 0b00 N/A
在以下示例中,RAM 内存条连接到总线 SMBus 0
。i2cdetect 命令将显示连接到总线的设备。-y 0
参数使用 i2c-0
smbus。如果需要,请检查其他总线。
# i2cdetect -y 0
___ 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- 0c -- -- -- 10: 10 -- -- -- -- -- -- -- 18 19 -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4f 50: 50 51 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- 77
RAM SPD (serial presence detect) 从地址 0x50
开始,RAM 温度传感器从同一总线的 0x18
开始。在此示例中,有 2 个 DIMM 可用。地址 0x18
和 0x19
是 DIMM 温度传感器。
要读取 RAM 内存条的温度,我们需要加载 jc42
内核模块。您需要告知模块要使用的地址。此过程包括将 module_name
和 address
写入 smbus_path
。例如
# modprobe jc42 # echo jc42 0x18 > /sys/bus/i2c/devices/i2c-0/new_device # echo jc42 0x19 > /sys/bus/i2c/devices/i2c-0/new_device
之后,您的内存条温度将可见
$ sensors
jc42-i2c-0-19 Adapter: SMBus PIIX4 adapter port 0 at 0b00 temp1: +50.7°C (low = +0.0°C) ALARM (HIGH, CRIT) (high = +0.0°C, hyst = +0.0°C) (crit = +0.0°C, hyst = +0.0°C) jc42-i2c-0-18 Adapter: SMBus PIIX4 adapter port 0 at 0b00 temp1: +51.8°C (low = +0.0°C) ALARM (HIGH, CRIT) (high = +0.0°C, hyst = +0.0°C) (crit = +0.0°C, hyst = +0.0°C)
从内存模块读取 SPD 值 (可选)
要从内存模块读取 SPD 时序值,请安装 i2c-tools 软件包。安装完成后,加载 at24
或 eeprom
(已弃用)内核模块。
# modprobe at24
最后,使用 decode-dimms
查看内存信息。
这是来自一台机器的部分输出
# decode-dimms
Memory Serial Presence Detect Decoder By Philip Edelbrock, Christian Zuckschwerdt, Burkart Lingner, Jean Delvare, Trent Piepho and others Decoding EEPROM: /sys/bus/i2c/drivers/eeprom/0-0050 Guessing DIMM is in bank 1 ---=== SPD EEPROM Information ===--- EEPROM CRC of bytes 0-116 OK (0x583F) # of bytes written to SDRAM EEPROM 176 Total number of bytes in EEPROM 512 Fundamental Memory type DDR3 SDRAM Module Type UDIMM ---=== Memory Characteristics ===--- Fine time base 2.500 ps Medium time base 0.125 ns Maximum module speed 1066MHz (PC3-8533) Size 2048 MB Banks x Rows x Columns x Bits 8 x 14 x 10 x 64 Ranks 2 SDRAM Device Width 8 bits tCL-tRCD-tRP-tRAS 7-7-7-33 Supported CAS Latencies (tCL) 8T, 7T, 6T, 5T ---=== Timing Parameters ===--- Minimum Write Recovery time (tWR) 15.000 ns Minimum Row Active to Row Active Delay (tRRD) 7.500 ns Minimum Active to Auto-Refresh Delay (tRC) 49.500 ns Minimum Recovery Delay (tRFC) 110.000 ns Minimum Write to Read CMD Delay (tWTR) 7.500 ns Minimum Read to Pre-charge CMD Delay (tRTP) 7.500 ns Minimum Four Activate Window Delay (tFAW) 30.000 ns ---=== Optional Features ===--- Operable voltages 1.5V RZQ/6 supported? Yes RZQ/7 supported? Yes DLL-Off Mode supported? No Operating temperature range 0-85C Refresh Rate in extended temp range 1X Auto Self-Refresh? Yes On-Die Thermal Sensor readout? No Partial Array Self-Refresh? No Thermal Sensor Accuracy Not implemented SDRAM Device Type Standard Monolithic ---=== Physical Characteristics ===--- Module Height (mm) 15 Module Thickness (mm) 1 front, 1 back Module Width (mm) 133.5 Module Reference Card B ---=== Manufacturer Data ===--- Module Manufacturer Invalid Manufacturing Location Code 0x02 Part Number OCZ3G1600LV2G ...
使用传感器数据
图形前端
有各种用于传感器数据的前端。
- psensor — 用于监控硬件传感器的 GTK 应用程序,包括温度和风扇速度。监控主板和 CPU(使用 lm-sensors)、Nvidia GPU(使用 XNVCtrl)和硬盘(使用 hddtemp 或 libatasmart)。
- xsensors — lm_sensors 的 X11 界面。
- Netdata — 基于 Web 的系统监控器 (netdata)。
- CoolerControl — 用于监控和控制冷却设备的程序。
对于特定的 桌面环境
- Freon (GNOME Shell 扩展) — 用于在 GNOME Shell 中显示 CPU 温度、磁盘温度、显卡温度、电压和风扇转速的扩展。
- GNOME Sensors Applet — 用于 GNOME 面板的小程序,用于显示来自硬件传感器的读数,包括 CPU 温度、风扇速度和电压读数。
- lm-sensors (LXPanel 插件) — 通过 lm-sensors 在 LXDE 中监控温度/电压/风扇速度。
- MATE Sensors Applet — 在 MATE 面板中显示来自硬件传感器的读数。
- Sensors (Xfce4 面板插件) — 用于 Xfce 面板的硬件传感器插件。
- Thermal Monitor (Plasma 小部件) — 用于显示系统温度的 KDE Plasma 小部件。
sensord
有一个可选的守护程序 sensord(包含在 lm_sensors 软件包中),它可以将数据记录到循环数据库 (rrd) 中,并在以后以图形方式可视化。有关详细信息,请参阅 sensord(8) 手册页。
技巧与诀窍
调整数值
在某些情况下,显示的数据可能不正确,或者用户可能希望重命名输出。用例包括
- 由于错误的偏移导致温度值不正确(即,报告的温度比实际温度高 20 °C)。
- 用户希望重命名某些传感器的输出。
- 核心可能以不正确的顺序显示。
以上所有问题(以及更多问题)都可以通过创建 /etc/sensors.d/foo
来覆盖 /etc/sensors3.conf
中软件包提供的设置来调整,其中任意数量的调整将覆盖默认值。建议将“foo”重命名为主板品牌和型号,但此命名规则是可选的。
许多主板的自定义配置文件可以在 lm-sensors 软件包的 configs 目录中找到,并可以用作模板。
/etc/sensors3.conf
,因为软件包更新将覆盖任何更改,从而丢失这些更改。示例 1. 调整温度偏移
这是 Zotac ION-ITX-A-U 主板上的一个真实示例。coretemp 值偏移了 20 °C(过高),并已向下调整为 Intel 规格。
$ sensors
coretemp-isa-0000 Adapter: ISA adapter Core 0: +57.0°C (crit = +125.0°C) Core 1: +55.0°C (crit = +125.0°C) ...
运行带有 -u
开关的 sensors
以查看每个物理芯片可用的选项(原始模式)。如果您看到的某些原始标签似乎不可配置,请查看 /sys/class/hwmon
目录树。那里提到的每个设备都有一个 name
文件,可用于匹配它引用的设备。然后尝试该目录引用的标签。
$ sensors -u
coretemp-isa-0000 Adapter: ISA adapter Core 0: temp2_input: 57.000 temp2_crit: 125.000 temp2_crit_alarm: 0.000 Core 1: temp3_input: 55.000 temp3_crit: 125.000 temp3_crit_alarm: 0.000 ...
创建以下文件以覆盖默认值
/etc/sensors.d/Zotac-IONITX-A-U
chip "coretemp-isa-0000" label temp2 "Core 0" compute temp2 @-20,@-20 label temp3 "Core 1" compute temp3 @-20,@-20
现在调用 sensors
显示调整后的值
$ sensors
coretemp-isa-0000 Adapter: ISA adapter Core 0: +37.0°C (crit = +105.0°C) Core 1: +35.0°C (crit = +105.0°C) ...
示例 2. 重命名标签
这是 Asus A7M266 上的一个真实示例。用户希望温度标签 temp1
和 temp2
使用更详细的名称
$ sensors
as99127f-i2c-0-2d Adapter: SMBus Via Pro adapter at e800 ... temp1: +35.0°C (high = +0.0°C, hyst = -128.0°C) temp2: +47.5°C (high = +100.0°C, hyst = +75.0°C) ...
创建以下文件以覆盖默认值
/etc/sensors.d/Asus_A7M266
chip "as99127f-*" label temp1 "Mobo Temp" label temp2 "CPU0 Temp"
现在调用 sensors
显示调整后的值
$ sensors
as99127f-i2c-0-2d Adapter: SMBus Via Pro adapter at e800 ... Mobo Temp: +35.0°C (high = +0.0°C, hyst = -128.0°C) CPU0 Temp: +47.5°C (high = +100.0°C, hyst = +75.0°C) ...
示例 3. 为多 CPU 系统重新编号核心
这是配备双 Xeon 的 HP Z600 工作站上的一个真实示例。物理核心的实际编号不正确:编号为 0、1、9、10,并在第二个 CPU 中重复。大多数用户希望核心温度按顺序报告,即 0,1,2,3,4,5,6,7。
$ sensors
coretemp-isa-0000 Adapter: ISA adapter Core 0: +65.0°C (high = +85.0°C, crit = +95.0°C) Core 1: +65.0°C (high = +85.0°C, crit = +95.0°C) Core 9: +66.0°C (high = +85.0°C, crit = +95.0°C) Core 10: +66.0°C (high = +85.0°C, crit = +95.0°C) coretemp-isa-0004 Adapter: ISA adapter Core 0: +54.0°C (high = +85.0°C, crit = +95.0°C) Core 1: +56.0°C (high = +85.0°C, crit = +95.0°C) Core 9: +60.0°C (high = +85.0°C, crit = +95.0°C) Core 10: +61.0°C (high = +85.0°C, crit = +95.0°C) ...
再次,运行带有 -u
开关的 sensors
以查看每个物理芯片可用的选项
$ sensors -u coretemp-isa-0000
coretemp-isa-0000 Adapter: ISA adapter Core 0: temp2_input: 61.000 temp2_max: 85.000 temp2_crit: 95.000 temp2_crit_alarm: 0.000 Core 1: temp3_input: 61.000 temp3_max: 85.000 temp3_crit: 95.000 temp3_crit_alarm: 0.000 Core 9: temp11_input: 62.000 temp11_max: 85.000 temp11_crit: 95.000 Core 10: temp12_input: 63.000 temp12_max: 85.000 temp12_crit: 95.000
$ sensors -u coretemp-isa-0004
coretemp-isa-0004 Adapter: ISA adapter Core 0: temp2_input: 53.000 temp2_max: 85.000 temp2_crit: 95.000 temp2_crit_alarm: 0.000 Core 1: temp3_input: 54.000 temp3_max: 85.000 temp3_crit: 95.000 temp3_crit_alarm: 0.000 Core 9: temp11_input: 59.000 temp11_max: 85.000 temp11_crit: 95.000 Core 10: temp12_input: 59.000 temp12_max: 85.000 temp12_crit: 95.000 ...
创建以下文件以覆盖默认值
/etc/sensors.d/HP_Z600
chip "coretemp-isa-0000" label temp2 "Core 0" label temp3 "Core 1" label temp11 "Core 2" label temp12 "Core 3" chip "coretemp-isa-0004" label temp2 "Core 4" label temp3 "Core 5" label temp11 "Core 6" label temp12 "Core 7"
现在调用 sensors
显示调整后的值
$ sensors
coretemp-isa-0000 Adapter: ISA adapter Core0: +64.0°C (high = +85.0°C, crit = +95.0°C) Core1: +63.0°C (high = +85.0°C, crit = +95.0°C) Core2: +65.0°C (high = +85.0°C, crit = +95.0°C) Core3: +66.0°C (high = +85.0°C, crit = +95.0°C) coretemp-isa-0004 Adapter: ISA adapter Core4: +53.0°C (high = +85.0°C, crit = +95.0°C) Core5: +54.0°C (high = +85.0°C, crit = +95.0°C) Core6: +59.0°C (high = +85.0°C, crit = +95.0°C) Core7: +60.0°C (high = +85.0°C, crit = +95.0°C) ...
自动 lm_sensors 部署
希望在多台机器上部署 lm_sensors 的用户可以使用以下命令接受所有问题的默认值
# sensors-detect --auto
S.M.A.R.T. 驱动器温度
自内核 5.6[1] 起,drivetemp
模块将通过 hwmon 报告 SATA/SAS 温度,但 sensors-detect
不会自动检测到这一点,因此必须手动加载该模块。
# modprobe drivetemp
您现在应该在 sensors
输出中看到类似于以下的条目
sensors
drivetemp-scsi-1-0 Adapter: SCSI adapter temp1: +33.0°C drivetemp-scsi-2-0 Adapter: SCSI adapter temp1: +32.0°C (low = +0.0°C, high = +70.0°C) (crit low = +0.0°C, crit = +70.0°C) (lowest = +29.0°C, highest = +41.0°C)
您现在可以在启动时加载模块。或者,手动将其添加到 /etc/conf.d/lm-sensors
的 HWMON_MODULES
行。请注意,当允许 sensors-detect
再次写入此文件时,它不会自动添加。
持久设备名称
许多软件期望传感器设备保持在 /sys/class/hwmon/hwmonX
中,但通常情况下,在具有超过 1-2 个设备提供 hwmon 接口的系统上,它们不会保持在那里。软件可能应该解析 hwmon?/name
或使用 lmsensors 库,但不幸的是,它们通常不会这样做。某些软件(例如:Monitorix 或其某些模块,即 amdgpu)期望在其他地方使用持久名称。
因此,以下类型的 udev 规则可能很有用。并非所有软件都可以使用它们(例如,KDE 系统监视器 - 不幸的是,这使得这些软件在许多系统上几乎无用)。对于许多情况,只需匹配 udev 规则中的 hwmon 子系统和合适的名称就足够了 - 但并非总是如此!有关编写规则的更多信息,请参阅 Udev 页面。
不能在 /sys
层次结构下重命名或符号链接。SYMLINK+=
语句也不会起作用。因此,我们需要使用 RUN+=
语句(注意,符号链接不需要像本例中那样位于 /dev
下 - 没有标准也没有好的位置来放置它们)。
/etc/udev/rules.d/99-persistent-hwmon-names.rules
# my motherboard sensor chip: ACTION=="add", SUBSYSTEM=="hwmon", ATTRS{name}=="nct6687", RUN+="/bin/sh -c 'ln -s /sys$devpath /dev/nct6678'" # an USB device providing sensors: ACTION=="add", SUBSYSTEM=="hwmon", ATTRS{name}=="corsaircpro", RUN+="/bin/sh -c 'ln -s /sys$devpath /dev/corsaircpro'" # my GPU: ACTION=="add", SUBSYSTEM=="hwmon", ATTRS{vendor}=="0x1002", ATTRS{device}=="0x73bf", RUN+="/bin/sh -c 'ln -s /sys$devpath /dev/rx6900xt'"
故障排除
K10Temp 模块
某些 K10 处理器存在温度传感器问题。有关更多信息,请参阅 k10temp 文档。
在受影响的机器上,模块将报告“不可靠的 CPU 热传感器;监控已禁用”。要强制继续监控,您可以运行以下命令
# rmmod k10temp # modprobe k10temp force=1
确认传感器实际上是有效且可靠的。如果是,可以编辑 /etc/modprobe.d/k10temp.conf
并添加
options k10temp force=1
这将允许模块在启动时加载。
华硕 B450M-A/A320M-K/A320M-K-BR 主板
这些主板使用 IT8655E 芯片,截至 2020 年 11 月 [2],it87 内核驱动程序不支持该芯片。但是,上游版本的内核驱动程序 [3] 支持该芯片。DKMS 变体包含在 it87-dkms-gitAUR 中。
华硕 B450/X399/X470 AM4 插槽主板
一些最新的华硕主板使用 ITE IT8665E 芯片,访问温度、风扇和电压传感器可能需要 asus-wmi-sensors
模块。自 5.17 起,它是主线内核的一部分:加载 asus-wmi-sensors
内核模块,该模块使用 UEFI 接口,并且可能需要在某些主板上更新 BIOS [4]。
或者,it87
模块直接从芯片读取值,安装 it87-dkms-gitAUR 并加载 it87
内核模块。
华硕 H97/Z97/Z170/Z370i/X570/B550/B650-PLUS/X670 主板
对于某些最新的华硕主板,风扇和电压传感器访问可能需要加载 nct6775
内核模块。
您可能还需要添加以下 内核参数
acpi_enforce_resources=lax
有关更多信息,请参阅 https://bugzilla.kernel.org/show_bug.cgi?id=204807。
华擎 Deskmini H470
Deskmini H470 的 STX 主板使用 NCT6683 芯片,要访问温度、风扇和电压传感器,需要加载 nct6683
模块。
为了获得 nct6683
模块的正确值,请创建一个模块配置文件
/etc/modprobe.d/nct6683.conf
options nct6683 force=1
技嘉 B250/Z370/B450M/B560M/B660M/Z690/B550 主板
一些技嘉主板使用 ITE IT8686E、ITE8689(用于 B560 和 B660M)或 ITE8689E(用于 Z690 和 B550)芯片,截至 2019 年 5 月 [5],it87 内核驱动程序不支持该芯片。但是,上游版本的内核驱动程序 [6] 支持该芯片。DKMS 变体包含在 it87-dkms-gitAUR 中。与 #华硕 H97/Z97/Z170/Z370i/X570/B550/B650-PLUS/X670 主板 一样,在尝试安装模块之前,需要 内核参数
acpi_enforce_resources=lax
此外,在加载模块时提供芯片的 ID,如下所示
# modprobe it87 force_id=0x8686 or # modprobe it87 force_id=0x8689 # for B560 # modprobe it87 force_id=0x8628 # for Z690 and B550
或者,您可以在启动过程中加载模块,方法是创建以下两个文件
/etc/modules-load.d/it87.conf
it87
对于 Z690 和 B550
/etc/modprobe.d/it87.conf
options it87 force_id=0x8628
对于其他主板
/etc/modprobe.d/it87.conf
options it87 ignore_resource_conflict=1
加载模块后,您可以使用 sensors 工具探测芯片。现在您还可以使用 fancontrol 来控制机箱风扇的转速步进。
可选地安装 zenpower3-dkmsAUR 可能会允许更精细地调整主板的冷却系统。但是,它确实禁用了默认的 k10temp 模块。
技嘉 GA-J1900N-D3V
此主板使用 ITE IT8620E 芯片(也可用于读取电压、主板温度、风扇速度)。截至 2014 年 10 月,lm_sensors 没有对 ITE IT8620E 芯片的驱动程序支持 [7][死链 2024-10-12 ⓘ] [8]。lm_sensors 开发人员报告称,该芯片在硬件监控部分与 IT8728F 有些兼容。但是,截至 2016 年 8 月,[9] 列出了 IT8620E 受支持。
您可以使用 modprobe 在运行时加载模块
$ modprobe it87 force_id=0x8728
或者,您可以在启动过程中加载模块,方法是创建以下两个文件
/etc/modules-load.d/it87.conf
it87
/etc/modprobe.d/it87.conf
options it87 force_id=0x8603
加载模块后,您可以使用 sensors 工具探测芯片。
现在您还可以使用 fancontrol 来控制机箱风扇的转速步进。
微星 B650 TOMAHAWK WIFI (MS-7D75)/微星 B550 MORTAR WIFI (MS-7C94)
这些主板使用 Nuvoton NCT6687-R 芯片进行风扇、电压和温度读数。您需要内核模块 nct6687d-dkms-gitAUR 才能访问这些值。
安装完成后,您可以加载模块
$ modprobe nct6687
然后检查传感器的输出
$ sensors
华擎 B650M Pro RS / B850M Pro RS / X870 Pro RS
这些主板使用 Nuvoton NCT6796D-S 进行风扇、电压和温度读数。此芯片的确切变体具有不同的 ID,因此如果没有模块配置文件,则无法检测到
/etc/modprobe.d/nct6775.conf
options nct6775 force_id=0xd801
运行 sensors-detect 后笔记本电脑屏幕出现问题
这是由 lm-sensors 在探测传感器时干扰屏幕的 Vcom 值引起的。这已在论坛上讨论并解决:https://bbs.archlinux.org/viewtopic.php?id=193048。但是,在运行任何建议的命令之前,请务必仔细阅读该帖子。
华擎 X870 Steel Legend WiFi
此主板使用较新的 Nuvoton NCT6686D 进行风扇、电压和温度读数。nct6683 驱动程序文档指出,该驱动程序仅在 Intel CPU 上实例化。AMD CPU 需要将 force 设置为 1。
/etc/modprobe.d/nct6683.conf
options nct6683 force=1