Linux 使用 lm-sensors 读取 CPU 温度传感器芯片数据(包括电压和风扇转速)
您可以使用名为 lm_sensor 的 Linux 硬件监控工具。此工具提供了一些必要的命令行实用程序,用于监控 Linux 系统的硬件健康状况,其中包括硬件健康监控硬件,例如 LM78、LM75 等。
教程详细信息 | |
---|---|
难度等级 | 简单的 |
Root 权限 | 是的 |
要求 | Linux 上的 lm_sensor |
预计阅读时间 | 10 分钟 |
此工具使用系统管理总线 (SMBus 或 SMB),这是一种简单的双线总线,源自 I²C,用于与主板上的低带宽设备进行通信,尤其是电源相关芯片,例如笔记本电脑的可充电电池子系统。其他设备可能包括温度、风扇或电压传感器;以及盖子开关。PCI 附加卡可以连接到 SMBus 段。
安装
lm_sensors(也称为“sensors”或“lm-sensors”)包可能已安装或尚未安装在您的服务器或笔记本电脑上:
在 CentOS / RHEL 上安装 lm_sensors
输入以下yum 命令在 CentOS / RHEL / Fedora Linux(旧版本)上安装软件:
$ sudo yum install lm_sensors
在 Fedora 上安装 lm_sensors
键入以下 dnf 命令:
$ sudo dnf install lm_sensors
在 Debian / Ubuntu Linux 上安装 lm-sensors
输入以下apt-get 命令:
$ sudo apt-get install lm-sensors
如何在 OpenSuse/Suse Linux 上安装 lm-sensors
键入以下 zypper 命令:
# zypper in sensors
Arch Linux 安装 lm-sensors
输入以下 pacman 命令:
# pacman -S lm_sensors
示例输出:
resolving dependencies... looking for conflicting packages... Packages (1) lm_sensors-3.4.0-2 Total Download Size: 0.12 MiB Total Installed Size: 0.44 MiB :: Proceed with installation? [Y/n] y :: Retrieving packages... lm_sensors-3.4.0-2-x86_64 124.8 KiB 204K/s 00:01 [##############################################################] 100% (1/1) checking keys in keyring [##############################################################] 100% (1/1) checking package integrity [##############################################################] 100% (1/1) loading package files [##############################################################] 100% (1/1) checking for file conflicts [##############################################################] 100% (1/1) checking available disk space [##############################################################] 100% :: Processing package changes... (1/1) installing lm_sensors [##############################################################] 100% Optional dependencies for lm_sensors rrdtool: for logging with sensord
配置 lm_sensors
要检测硬件监控芯片,请以 root 用户身份输入以下命令:
# sensors-detect
或
$ sudo sensors-detect
示例输出:
# sensors-detect revision 4609 (2007-07-14 09:28:39 -0700)
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.
We can start with probing for (PCI) I2C or SMBus adapters. Do you want to probe now? (YES/no): Probing for PCI bus adapters... Use driver `i2c-i801' for device 0000:00:1f.3: Intel 82801G ICH7
We will now try to load each adapter module in turn. Module `i2c-i801' already loaded. If you have undetectable or unsupported adapters, you can have them scanned by manually loading the modules before running this script.
To continue, we need module `i2c-dev' to be loaded. Do you want to load `i2c-dev' now? (YES/no): Module loaded successfully.
We are now going to do the I2C/SMBus adapter probings. Some chips may be double detected; we choose the one with the highest confidence value in that case. If you found that the adapter hung after probing a certain address, you can specify that address to remain unprobed.
Next adapter: saa7133[0] (i2c-0) Do you want to scan it? (YES/no/selectively): Client found at address 0x47 Handled by driver `ir-kbd-i2c' (already loaded), chip type `Pinnacle PCTV' (note: this is probably NOT a sensor chip!) Client found at address 0x4b Handled by driver `tuner' (already loaded), chip type `tda8290+75a' (note: this is probably NOT a sensor chip!) Client found at address 0x50 Probing for `Analog Devices ADM1033'... No Probing for `Analog Devices ADM1034'... No Probing for `SPD EEPROM'... No Probing for `EDID EEPROM'... No
Next adapter: SMBus I801 adapter at 4000 (i2c-1) Do you want to scan it? (YES/no/selectively): Client found at address 0x2e Probing for `Myson MTP008'... No Probing for `National Semiconductor LM78'... No Probing for `National Semiconductor LM78-J'... No Probing for `National Semiconductor LM79'... No Probing for `National Semiconductor LM80'... No Probing for `National Semiconductor LM85 or LM96000'... No Probing for `Analog Devices ADM1027, ADT7460 or ADT7463'... No Probing for `SMSC EMC6D100, EMC6D101 or EMC6D102'... No Probing for `Analog Devices ADT7462'... No Probing for `Analog Devices ADT7467 or ADT7468'... No Probing for `Analog Devices ADT7470'... No Probing for `Analog Devices ADT7473'... No Probing for `Analog Devices ADT7475'... No Probing for `Analog Devices ADT7476'... No Probing for `Andigilog aSC7611'... No Probing for `Andigilog aSC7621'... Success! (confidence 5, driver `to-be-written') Probing for `National Semiconductor LM87'... No Probing for `National Semiconductor LM93'... No Probing for `Winbond W83781D'... No Probing for `Winbond W83782D'... No Probing for `Winbond W83792D'... No Probing for `Winbond W83793R/G'... No Probing for `Winbond W83791SD'... No Probing for `Winbond W83627HF'... No Probing for `Winbond W83627EHF'... No Probing for `Winbond W83627DHG'... No Probing for `Asus AS99127F (rev.1)'... No Probing for `Asus AS99127F (rev.2)'... No Probing for `Asus ASB100 Bach'... No Probing for `Winbond W83L785TS-S'... No Probing for `Analog Devices ADM9240'... No Probing for `Dallas Semiconductor DS1780'... No Probing for `National Semiconductor LM81'... No Probing for `Analog Devices ADM1026'... No Probing for `Analog Devices ADM1025'... No Probing for `Analog Devices ADM1024'... No Probing for `Analog Devices ADM1029'... No Probing for `Analog Devices ADM1030'... No Probing for `Analog Devices ADM1031'... No Probing for `Analog Devices ADM1022'... No Probing for `Texas Instruments THMC50'... No Probing for `Analog Devices ADM1028'... No Probing for `ITE IT8712F'... No Probing for `SMSC DME1737'... No Probing for `Fintek F75373S/SG'... No Probing for `Fintek F75375S/SP'... No Probing for `Fintek F75387SG/RG'... No Probing for `Winbond W83791D'... No Client found at address 0x44 Probing for `Maxim MAX6633/MAX6634/MAX6635'... No Client found at address 0x50 Probing for `Analog Devices ADM1033'... No Probing for `Analog Devices ADM1034'... No Probing for `SPD EEPROM'... Yes (confidence 8, not a hardware monitoring chip) Probing for `EDID EEPROM'... No
Some chips are also accessible through the ISA I/O ports. We have to write to arbitrary I/O ports to probe them. This is usually safe though. Yes, you do have ISA I/O ports even if you do not have any ISA slots! Do you want to scan the ISA I/O ports? (YES/no): Probing for `National Semiconductor LM78' at 0x290... No Probing for `National Semiconductor LM78-J' at 0x290... No Probing for `National Semiconductor LM79' at 0x290... No Probing for `Winbond W83781D' at 0x290... No Probing for `Winbond W83782D' at 0x290... No Probing for `Silicon Integrated Systems SIS5595'... No Probing for `VIA VT82C686 Integrated Sensors'... No Probing for `VIA VT8231 Integrated Sensors'... No Probing for `IPMI BMC KCS' at 0xca0... No Probing for `IPMI BMC SMIC' at 0xca8... No
Some Super I/O chips may also contain sensors. We have to write to standard I/O ports to probe them. This is usually safe. Do you want to scan for Super I/O sensors? (YES/no): Probing for Super-I/O at 0x2e/0x2f Trying family `National Semiconductor'... No Trying family `SMSC'... Yes Found `SMSC LPC47M182 Super IO Fan Sensors' (but not activated) Probing for Super-I/O at 0x4e/0x4f Trying family `National Semiconductor'... No Trying family `SMSC'... No Trying family `VIA/Winbond/Fintek'... No Trying family `ITE'... No
Some CPUs or memory controllers may also contain embedded sensors. Do you want to scan for them? (YES/no): AMD K8 thermal sensors... No Intel Core family thermal sensor... Success! (driver `coretemp') Intel AMB FB-DIMM thermal sensor... No
Now follows a summary of the probes I have just done. Just press ENTER to continue:
Driver `to-be-written' (should be inserted): Detects correctly: * Bus `SMBus I801 adapter at 4000' Busdriver `i2c-i801', I2C address 0x2e Chip `Andigilog aSC7621' (confidence: 5)
Driver `coretemp' (should be inserted): Detects correctly: * Chip `Intel Core family thermal sensor' (confidence: 9)
I will now generate the commands needed to load the required modules. Just press ENTER to continue:
To make the sensors modules behave correctly, add these lines to /etc/modules:
#----cut here---- # I2C adapter drivers i2c-i801 # Chip drivers # no driver for Andigilog aSC7621 yet coretemp #----cut here---- Do you want to add these lines to /etc/modules automatically? (yes/NO)
这是一个交互式程序,它将引导您完成扫描系统以查找 libsensors 或更一般地由 lm_sensors 工具套件支持的各种硬件监控芯片或传感器的过程。对于我的系统,需要加载 coretemp 和 i2c-i801 驱动程序才能查看传感器数据。输入“YES”以更新 /etc/modules 文件。现在您需要重新启动该框。或者,您可以使用modprobe 命令加载所有驱动程序:
# modprobe coretemp
# modprobe i2c-i801
如何读取传感器芯片数据(例如温度和风扇速度)?
在 shell 提示符下输入以下命令:
$ sensors
示例输出:
coretemp-isa-0000 Adapter: ISA adapter Core 0: +59°C (high = +100°C) coretemp-isa-0001 Adapter: ISA adapter Core 1: +59°C (high = +100°C) coretemp-isa-0002 Adapter: ISA adapter Core 2: +55°C (high = +100°C) coretemp-isa-0003 Adapter: ISA adapter Core 3: +56°C (high = +100°C)
以下是 Intel Xeon 服务器的另一个输出:
w83627hf-i2c-0-2d Adapter: SMBus I801 adapter at 1100 VCore 1: +4.08 V (min = +1.34 V, max = +1.49 V) ALARM VCore 2: +4.08 V (min = +1.34 V, max = +1.49 V) ALARM +3.3V: +4.08 V (min = +3.14 V, max = +3.46 V) ALARM +5V: +5.11 V (min = +4.73 V, max = +5.24 V) +12V: +11.73 V (min = +10.82 V, max = +13.19 V) -12V: +1.21 V (min = -13.18 V, max = -10.88 V) ALARM -5V: +2.24 V (min = -5.25 V, max = -4.75 V) ALARM V5SB: +5.51 V (min = +4.73 V, max = +5.24 V) ALARM VBat: +0.54 V (min = +2.40 V, max = +3.60 V) ALARM fan1: 0 RPM (min = 0 RPM, div = 2) fan2: 0 RPM (min = 2689 RPM, div = 2) ALARM fan3: 0 RPM (min = 6553 RPM, div = 2) ALARM temp1: -48°C (high = -1°C, hyst = -25°C) sensor = thermistor temp2: -48.0°C (high = +80°C, hyst = +75°C) sensor = thermistor temp3: -48.0°C (high = +80°C, hyst = +75°C) sensor = thermistor vid: +1.419 V (VRM Version 11.0) alarms: beep_enable: Sound alarm enabled w83627hf-isa-0290 Adapter: ISA adapter VCore 1: +4.08 V (min = +1.34 V, max = +1.49 V) ALARM VCore 2: +4.08 V (min = +1.34 V, max = +1.49 V) ALARM +3.3V: +4.08 V (min = +3.14 V, max = +3.46 V) ALARM +5V: +5.11 V (min = +4.73 V, max = +5.24 V) +12V: +11.73 V (min = +10.82 V, max = +13.19 V) -12V: +1.29 V (min = -13.18 V, max = -10.88 V) ALARM -5V: +2.24 V (min = -5.25 V, max = -4.75 V) ALARM V5SB: +5.48 V (min = +4.73 V, max = +5.24 V) ALARM VBat: +0.54 V (min = +2.40 V, max = +3.60 V) ALARM fan1: 0 RPM (min = 0 RPM, div = 2) fan2: 0 RPM (min = 2689 RPM, div = 2) ALARM fan3: 0 RPM (min = 6553 RPM, div = 2) ALARM temp1: -48°C (high = -1°C, hyst = -25°C) sensor = thermistor temp2: -48.0°C (high = +80°C, hyst = +75°C) sensor = thermistor temp3: -48.0°C (high = +80°C, hyst = +75°C) sensor = thermistor vid: +1.419 V (VRM Version 11.0) alarms: beep_enable: Sound alarm enabled
提示:实时查看传感器数据
键入以下监视命令:
# watch sensors
或
# watch -d sensors
Gif 01:传感器在运行
结论
我们解释了如何在 Linux 下读取 CPU 温度数据(包括风扇速度)。使用 man 命令查看以下手册页:
更多推荐阅读:
man sensors
man sensors-detect
- 使用 disktemp实用程序读取硬盘温度
- lm-sensors项目主页
已更新以提高准确性。