大致strace跟踪了下sensors命令,发现是读取类似/sys/class/hwmon/hwmon1/temp1_input中的值,再结合google下的如下几篇文章:

https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

总结如下:

# ls -al /sys/class/hwmon/
total 0
drwxr-xr-x  2 root root 0 Aug 11 10:09 .
drwxr-xr-x 64 root root 0 Aug 11 10:09 ..
lrwxrwxrwx  1 root root 0 Aug 11 10:09 hwmon0 -> ../../devices/platform/coretemp.0/hwmon/hwmon0
lrwxrwxrwx  1 root root 0 Aug 11 10:09 hwmon1 -> ../../devices/platform/coretemp.1/hwmon/hwmon1
lrwxrwxrwx  1 root root 0 Aug 11 10:09 hwmon2 -> ../../devices/LNXSYSTM:00/device:00/ACPI000D:00/hwmon/hwmon2

可以发现hwmon0目录是cpu0的温度监测,hwmon1是cpu1的温度

注意下,这个对应关系不同机器不一样,同时重启后该对应关系也可能会变化。

再进入目录:

# cat /sys/class/hwmon/hwmon0/temp1_input 
33000
# cat /sys/class/hwmon/hwmon0/temp2_input 
31000
# sensors
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +33.0°C  (high = +87.0°C, crit = +97.0°C)
Core 0:         +31.0°C  (high = +87.0°C, crit = +97.0°C)
Core 1:         +27.0°C  (high = +87.0°C, crit = +97.0°C)
Core 2:         +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 3:         +30.0°C  (high = +87.0°C, crit = +97.0°C)
Core 4:         +27.0°C  (high = +87.0°C, crit = +97.0°C)
Core 8:         +30.0°C  (high = +87.0°C, crit = +97.0°C)
Core 9:         +29.0°C  (high = +87.0°C, crit = +97.0°C)
Core 10:        +30.0°C  (high = +87.0°C, crit = +97.0°C)
Core 11:        +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 12:        +31.0°C  (high = +87.0°C, crit = +97.0°C)
Core 16:        +26.0°C  (high = +87.0°C, crit = +97.0°C)
Core 17:        +29.0°C  (high = +87.0°C, crit = +97.0°C)
Core 18:        +26.0°C  (high = +87.0°C, crit = +97.0°C)
Core 19:        +29.0°C  (high = +87.0°C, crit = +97.0°C)
Core 20:        +31.0°C  (high = +87.0°C, crit = +97.0°C)
Core 24:        +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 25:        +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 26:        +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 27:        +28.0°C  (high = +87.0°C, crit = +97.0°C)
Core 28:        +29.0°C  (high = +87.0°C, crit = +97.0°C)

temp1_input对应的是整个cpu的温度

temp1_input对应的是core0,temp2_input对应的是core1,依次类推。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐