平台:Debian 4.7.2
一、安装lm-sensors
CentOS: yum install *sensors*
Ubuntu: apt-get install lm_sensors
deb包安装: https://packages.debian.org/jessie/lm-sensors
二、sensors-detect命令探测
输入命令,一路Yes或者Enter即可
三、执行sensors得到输出
root@Debian:~# sensors
i350bb-pci-0400
Adapter: PCI adapter
loc1: +38.0 C (high = +120.0 C, crit = +110.0 C)
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +26.0 C (high = +84.0 C, crit = +100.0 C)
Core 0: +22.0 C (high = +84.0 C, crit = +100.0 C)
Core 1: +23.0 C (high = +84.0 C, crit = +100.0 C)
Core 2: +24.0 C (high = +84.0 C, crit = +100.0 C)
Core 3: +23.0 C (high = +84.0 C, crit = +100.0 C)
此时发现仅输出了温度信息,温度信息是记录在/sys/devices/platform/coretemp.N目录下tempN_input中
root@Debian:~# cat /sys/devices/platform/coretemp.0/temp1_input
27000
由内核模块coretemp提供
root@Debian:~# lsmod | grep coretemp
coretemp 12854 0
四、补充相应内核模块
如果要输出风扇信息,首先需要有nct6775之类的设备,其次需要insmod nct6775.ko。nct6775.ko是与风扇相关的
驱动模块。这里贴一个源码地址:https://github.com/killghost/nct6775
拿到源码后按内核头文件存放位置及自身需求更改Makefile文件,执行make生成nct6775.ko文件。这里有一点需要注
意:linux4.x后判断版本会使用kstrtoul函数,在我贴出的源码的compat.h中存在这几行代码,注释掉即可编译通过。
#ifndef kstrtol
#define kstrtol strict_strtol
#endif
#ifndef kstrtoul
#define kstrtoul strict_strtoul
#endif
编译好nct6775.ko后挂载模块,再执行sensors查看,就得到了想要的CPU温度及有关风扇的信息:
root@Debian:~# insmod nct6775.ko
root@Debian:~# sensors
nct6776-isa-0a10
Adapter: ISA adapter
in0: +1.13 V (min = +0.00 V, max = +1.74 V)
in1: +1.02 V (min = +0.00 V, max = +0.00 V) ALARM
in2: +3.36 V (min = +0.00 V, max = +0.00 V) ALARM
in3: +3.36 V (min = +0.00 V, max = +0.00 V) ALARM
in4: +1.02 V (min = +0.00 V, max = +0.00 V) ALARM
in5: +1.21 V (min = +0.00 V, max = +0.00 V) ALARM
in6: +1.02 V (min = +0.00 V, max = +0.00 V) ALARM
in7: +3.33 V (min = +0.00 V, max = +0.00 V) ALARM
in8: +3.09 V (min = +0.00 V, max = +0.00 V) ALARM
fan1: 3452 RPM (min = 0 RPM)
fan2: 3461 RPM (min = 0 RPM)
fan3: 3400 RPM (min = 0 RPM)
fan4: 7848 RPM (min = 0 RPM)
fan5: 0 RPM (min = 0 RPM)
SYSTIN: +22.0 C (high = +0.0 C, hyst = +0.0 C) ALARM sensor = CPU diode
CPUTIN: +123.5 C (high = +80.0 C, hyst = +75.0 C) ALARM sensor = CPU diode
AUXTIN: +25.0 C (high = +80.0 C, hyst = +75.0 C) sensor = thermistor
PCH_CHIP_TEMP: +0.0 C
PCH_CPU_TEMP: +0.0 C
PCH_MCH_TEMP: +0.0 C
intrusion0: ALARM
intrusion1: ALARM
beep_enable: disabled
i350bb-pci-0400
Adapter: PCI adapter
loc1: +38.0 C (high = +120.0 C, crit = +110.0 C)
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +26.0 C (high = +84.0 C, crit = +100.0 C)
Core 0: +22.0 C (high = +84.0 C, crit = +100.0 C)
Core 1: +23.0 C (high = +84.0 C, crit = +100.0 C)
Core 2: +26.0 C (high = +84.0 C, crit = +100.0 C)
Core 3: +22.0 C (high = +84.0 C, crit = +100.0 C)