使用较为简单
数据组织方式
Linux的hwmon
子系统将所有硬件传感器(温度、风扇、电压等)以文件形式暴露在/sys/class/hwmon/
目录下,每个传感器设备对应一个hwmonX
目录(如hwmon0
、hwmon7
等)。
每个目录中包含以下关键文件:
文件/目录名 | 作用 | 示例值/说明 |
---|
name | 设备名称(驱动标识) | fan_control 、k10temp |
label | 传感器标签(用户友好名称) | CPU Temp 、Fan1 |
pwm1 | 风扇调速(PWM占空比) | 93 (范围通常0-255或0-100) |
fan1_input | 风扇转速(RPM) | 2500 (转/分钟) |
temp1_input | 温度(毫摄氏度) | 45000 (表示45.0°C) |
## 常用命令 | | |
name,label概览,大致包含那些数据 | | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| ls -alh /sys/class/hwmon/hwmon*/name cat /sys/class/hwmon/hwmon*/name
ls -alh /sys/class/hwmon/hwmon*/*label cat /sys/class/hwmon/hwmon*/*label
(base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ ls -alh /sys/class/hwmon/hwmon*/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon0/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon1/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon2/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon3/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/name -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon5/name (base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ cat /sys/class/hwmon/hwmon*/name ACAD BAT1 nvme k10temp amdgpu hidpp_battery_0
(base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ ls -alh /sys/class/hwmon/hwmon*/*label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon2/temp1_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon2/temp2_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon2/temp3_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon3/temp1_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/freq1_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/in0_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/in1_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/power1_label -r--r--r-- 1 root root 4.0K 4月 20 15:55 /sys/class/hwmon/hwmon4/temp1_label (base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ cat /sys/class/hwmon/hwmon*/*label Composite Sensor 1 Sensor 2 Tctl sclk vddgfx vddnb PPT edge (base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$
|
| | |
温度数据有哪些
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| 综合命令: ls /sys/class/hwmon/hwmon*/ | grep -i "temp" cat /sys/class/hwmon/hwmon*/temp*
(base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ ls /sys/class/hwmon/hwmon*/ | grep -i "temp" temp1_alarm temp1_crit temp1_input temp1_label temp1_max temp1_min temp2_input temp2_label temp2_max temp2_min temp3_input temp3_label temp3_max temp3_min temp1_input temp1_label temp1_input temp1_label (base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$ cat /sys/class/hwmon/hwmon*/temp* 0 84850 43850 Composite 83850 -273150 43850 Sensor 1 65261850 -273150 40850 Sensor 2 65261850 -273150 41000 Tctl 40000 edge (base) john@john-HLYL-WXX9:/sys/class/hwmon/hwmon4$
|
参考
Linux hwmon子系统分析之一 系统框架说明:https://blog.csdn.net/lickylin/article/details/106449262
Linux hwmon 子系统分析之三 新版本hwmon子系统说明;https://blog.csdn.net/lickylin/article/details/106449418