lm_sensors(Linux监控传感器)
Linux服务器运维时非常重要的一项监控就是服务器内部温度监控。当出现服务器内部温度过高,例如风扇故障,就会导致CPU因温度过高降频,甚至出现死机或者其他数据异常现象。
在Linux中,软件包 lm_sensors (即Linux-monitoring sensors)提供了基础工具和驱动来监控CPU温度,电压,湿度和风扇。同时也提供了主板入侵检测(非授权开启机箱)。通过该工具结合监控软件,可以用来发现硬件异常,及时更换受损部件。
安装lm_sensors
Arch linux安装:
sudo pacman -S lm_sensors
RHEL/CentOS,Fedora:
sudo yum install lm_sensors
Debian, Ubuntu:
sudo apt install lm-sensors
SUSE/openSUSE:
sudo zypper in sensors
配置lm_sensors
安装以后,运行以下命令配置 lm_sensors :
sudo sensors-detect
sensors-detect 是一个独立程序用来检测已经安装的硬件以及加载推荐的特定模块。默认的交互回答就是安全的,所以通常只需要回车接受默认配置就可以。根据最后提示修订配置文件,例如 /etc/modules-load.d/lm-sensors (不建议直接修改 /etc/modules ,详见该配置文件内系统说明) 配置文件用于 lm_sensors.service 服务自动在启动时加载模块。
以下是我的组装机 纳斯NASSE C246 ITX主板 上实践记录,参考gemini分析说明:
第1步开始扫描,检测到 Intel digital thermal sensor ,驱动是 coretemp : 这是CPU 内核驱动已经直接集成了核显温度监控,扫描 Super I/O 和 CPU 传感器时加载的 coretemp 驱动,或者运行 intel_gpu_top ,就能直接看到核显的温度和负载。
sensor-detect 交互步骤1# sensors-detect version 3.6.2
# System: Cloudstar ITX-C246 [Default string]
# Kernel: 7.0.0-38-generic x86_64
# Processor: Intel(R) Xeon(R) E-2274G CPU @ 4.00GHz (6/158/10)
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): yes
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
AMD Family 11h thermal sensors... No
AMD Family 12h and 14h thermal sensors... No
AMD Family 15h thermal sensors... No
AMD Family 16h thermal sensors... No
AMD Family 17h thermal sensors... No
AMD Family 15h power sensors... No
AMD Family 16h power sensors... No
Hygon Family 18h thermal sensors... No
AMD Family 19h thermal sensors... No
Intel digital thermal sensor... Success!
(driver `coretemp')
Intel AMB FB-DIMM thermal sensor... No
Intel 5500/5520/X58 thermal sensor... No
VIA C7 thermal sensor... No
VIA Nano thermal sensor... No
第2步扫描 Super I/O sensors ,就是 C246 主板上负责管理风扇 PWM 和电压的芯片(如 Nuvoton 或 ITE 芯片),这里可以看到检测到 ITE IT8613E Super IO Sensors
sensor-detect 交互步骤2Some Super I/O chips contain embedded 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): yes
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor/ITE'... No
Trying family `SMSC'... No
Trying family `VIA/Winbond/Nuvoton/Fintek'... No
Trying family `ITE'... Yes
Found `ITE IT8613E Super IO Sensors' Success!
(address 0xa30, driver `to-be-written')
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor/ITE'... No
Trying family `SMSC'... No
Trying family `VIA/Winbond/Nuvoton/Fintek'... No
Trying family `ITE'... No
第3步扫描 IPMI ,不过我的兼容台式机并没有提供硬件支持
sensor-detect 交互步骤3Some systems (mainly servers) implement IPMI, a set of common interfaces
through which system health data may be retrieved, amongst other things.
We first try to get the information from SMBIOS. If we don't find it
there, we have to read from arbitrary I/O ports to probe for such
interfaces. This is normally safe. Do you want to scan for IPMI
interfaces? (YES/no): yes
# DMI data unavailable, please consider installing dmidecode 2.7
# or later for better results.
Probing for `IPMI BMC KCS' at 0xca0... No
Probing for `IPMI BMC SMIC' at 0xca8... No
第4步扫描 ISA I/O 端口,不过现代主机上已经取消了ISA接口,所以这里直接选择 no
sensor-detect 交互步骤4Some hardware monitoring chips are 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): no
第5步扫描 I2C/SMBus ,这是现代硬件中的主要监控接口,所以回答 yes 可以看到检测到 Cannon Lake-H (PCH) 并使用驱动 i2c-i801
sensor-detect 交互步骤5Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no): yes
Using driver `i2c-i801' for device 0000:00:1f.4: Cannon Lake-H (PCH)
第6步扫描 i2c-i801 (SMBus I801 adapter)详情,因为是重点设备,所以将默认的 No 调整为 yes ,可以看到扫描出了 Dallas Semiconductor DS75 (使用驱动 lm75 )
SMBus(System Management Bus) 是一条硬件底层总线,除了挂载温度传感器外,内存条(SPD 芯片)、主板供电管理芯片(VRM)等敏感设备也挂在这条总线上
sensors-detect在盲目探测 SMBus 上的未知地址时,可能会尝试向某些寄存器写入测试数据。在极少数主板上,这有可能导致内存配置文件(XMP/SPD)损坏或导致系统瞬间死机。
sensors-detect将 SMBus(I801 适配器)扫描默认设置为NO是出于历史兼容性与极端安全防护考量在 纳斯NASSE C246 ITX主板 (即上面扫描出的
Intel Cannon Lake-H PCH)现代化主板,Intel PCH SMBus 控制器非常成熟,没有任何写破坏风险,主板上的硬件监控芯片(如 Nuvoton 或 ITE 监控芯片)以及部分内存/主板温度传感器,往往正是挂载在 SMBus (i2c-0) 总线 上,所以我这里 将默认的 No 调整为 yes
sensor-detect 交互步骤6Next adapter: SMBus I801 adapter at 0000:00:1f.4 (i2c-0)
Do you want to scan it? (yes/NO/selectively): yes
Client found at address 0x4f
Probing for `National Semiconductor LM75'... No
Probing for `National Semiconductor LM75A'... No
Probing for `Dallas Semiconductor DS75'... Success!
(confidence 3, driver `lm75')
Probing for `Maxim MAX6642'... No
Probing for `Texas Instruments TMP421'... No
Probing for `Texas Instruments TMP422'... No
Probing for `Texas Instruments TMP435'... No
Probing for `Texas Instruments TMP441'... No
Probing for `Maxim MAX6633/MAX6634/MAX6635'... No
Probing for `NXP/Philips SA56004'... No
Client found at address 0x50
Handled by driver `ee1004' (already loaded), chip type `ee1004'
(note: this is probably NOT a sensor chip!)
Client found at address 0x52
Handled by driver `ee1004' (already loaded), chip type `ee1004'
(note: this is probably NOT a sensor chip!)
第7步扫描 i915 gmbus dpb (i2c-1) / i915 gmbus dpc (i2c-2) / i915 gmbus misc (i2c-3) / i915 gmbus dpd (i2c-4) / AUX B/DDI B/PHY B (i2c-5) ,根据gemini建议,都选择 no :
和
i915核显相关的gmbus(Graphic Management Bus) 和dpb(DisplayPort Port B) 都是和显示通讯相关的接口,这些接口没有任何风扇或主板传感器
gmbus(Graphic Management Bus)是 Intel 核显专门用来和显示器进行 DDC/CI 通讯的物理通道。它的作用是传输类似“这台显示器叫 Dell U2720Q”、“最高支持 4K 60Hz”这样的静态描述文件(EDID),或者用来让你在操作系统里调节显示器的硬件亮度。Intel 核显(i915):CPU 内核驱动已经直接集成了核显温度监控,扫描 Super I/O 和 CPU 传感器时加载的 coretemp 驱动,或者运行 intel_gpu_top,就能直接看到核显的温度和负载。
NVIDIA 独显( NVIDIA Tesla A2 GPU运算卡 )显卡的温度、功耗、显存使用率等所有监控数据,全部由专用的
nvidia-smi或nvml接口直接提供,完全绕过了 Linux 传统的lm-sensors/hwmon框架
AUX B/DDI B/PHY B (i2c-5)是 Intel Xeon E-2274G 处理器自带核显(Intel UHD Graphics P630)的显示输出通道(DisplayPort / HDMI 辅助通道 Aux Channel),这个接口只用于连接显示器和传输图形握手信号,里面没有任何主板风扇、转速或电压温度传感器。
最后, sensor-detect 输出了配置信息调整,也就是最后需要添加到模块加载的配置:
Now follows a summary of the probes I have just done.
Just press ENTER to continue:
Driver `to-be-written':
* ISA bus, address 0xa30
Chip `ITE IT8613E Super IO Sensors' (confidence: 9)
Driver `lm75':
* Bus `SMBus I801 adapter at 0000:00:1f.4'
Busdriver `i2c_i801', I2C address 0x4f
Chip `Dallas Semiconductor DS75' (confidence: 3)
Driver `coretemp':
* Chip `Intel digital thermal sensor' (confidence: 9)
Note: there is no driver for ITE IT8613E Super IO Sensors yet.
Check https://hwmon.wiki.kernel.org/device_support_status for updates.
To load everything that is needed, add this to /etc/modules:
#----cut here----
# Chip drivers
coretemp
lm75
#----cut here----
If you have some drivers built into your kernel, the list above will
contain too many modules. Skip the appropriate ones!
Do you want to add these lines automatically to /etc/modules? (yes/NO)yes
Successful!
Monitoring programs won't work until the needed modules are
loaded. You may want to run '/etc/init.d/kmod start'
to load them.
Unloading cpuid... OK
现在准备工作都已经完成
重新加载系统模块驱动:
sudo systemctl restart systemd-modules-load
查看CPU温度
简单执行以下命令就可以查看Linux:
sensors 命令sensors
默认输出的单位是摄氏度,要输出为华氏度,则使用参数 -f
sensors 命令输出信息coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +35.0°C (high = +80.0°C, crit = +100.0°C)
Core 0: +34.0°C (high = +80.0°C, crit = +100.0°C)
Core 1: +33.0°C (high = +80.0°C, crit = +100.0°C)
Core 2: +31.0°C (high = +80.0°C, crit = +100.0°C)
Core 3: +32.0°C (high = +80.0°C, crit = +100.0°C)
nvme-pci-0a00
Adapter: PCI adapter
Composite: +40.9°C (low = -273.1°C, high = +80.8°C)
(crit = +84.8°C)
Sensor 1: +40.9°C (low = -273.1°C, high = +65261.8°C)
Sensor 2: +48.9°C (low = -273.1°C, high = +65261.8°C)
acpitz_0-acpi-0
Adapter: ACPI interface
temp1: +27.8°C
mt7921_phy0-virtual-0
Adapter: Virtual device
temp1: +50.0°C
pch_cannonlake_1-virtual-0
Adapter: Virtual device
temp1: +61.0°C
nvme-pci-0500
Adapter: PCI adapter
Composite: +43.9°C (low = -0.1°C, high = +71.8°C)
(crit = +89.8°C)
这里的输出信息中:
coretemp-isa-0000( Intel Xeon E-2274G ) 实时温度 35°C ,各个CPU核心温差不大,大约31-34°C 。可以看到告警阀值(high)温度是80°C,危险宕机阀值(crit)温度是100°C,当前远没有达到告警阀值,所以非常安全
nvme-pci-0a00和nvme-pci-0500两块NVme固态硬盘温度在 40.9°C - 43.9°C 左右,属于非常舒适的正常工作温度
pch_cannonlake_1-virtual-0: C246 南桥 PCH 芯片温度 +61.0°C。南桥无风扇被动散热达到 60°C 左右属于 Intel 芯片组的常规物理特性,完全正常
mt7921_phy0-virtual-0: Wi-Fi / 无线网卡芯片温度 +50.0°C,正常
为了持续查看温度变化(以下案例每2秒刷新一次),可以使用命令:
wtach -n 2 sensors