如何在没有第三方软件的情况下找到温度?

14 software-recommendation temperature

sensors-detect在我的系统上运行,lm-sensors因为当我观看 YouTube 视频时我的系统一直关闭

所以我想知道如何在没有 3rd 方软件的情况下手动找到风扇和 cpu 的温度lm-sensors?我只是不确定它们存储在哪里。

processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 16
model       : 6
model name  : AMD Athlon(tm) II X2 240e Processor
power management: ts ttp tm stc 100mhzsteps hwpstate
Run Code Online (Sandbox Code Playgroud)

x86_64

Aus*_*arn 15

听起来你想要的是/sys/class/hwmon/sys/class/thermal

这两者都提供了对所需数据的简单基于 shell 的访问(hwmon 目录还将包括其他传感器类型)。每个系统中的每个传感器接口都有一个目录(可能有多个传感器)。

但要注意的其他三件事:

  • 除非您的系统非常糟糕,否则sensors即使每秒运行一次命令也不应该有任何明显的效果。事实上,定期读取上述目录中的文件可能会产生更大的影响。
  • 图表是您的朋友。我建议运行 netdata 或 collectd 之类的东西,以便您可以查看实时(或接近实时)数据。
  • 也检查你的电压。您所描述的情况也可能是由于电源无法满足系统的电源要求。这将通过系统处于高负载时电压显着下降来表示。

  • 你好@DougSmythies 和 Aaron F,我最初选择 DougSmythies 作为主要答案,因为他是第一个提供帮助的人,他的回答非常清楚如何手动搜索温度以及使用手动解决方案变得易于使用有 mdmsr 支持的程序,这实际上是一个艰难的决定,因为两个答案都非常有用,但是因为你们都同意这个答案是最好的。我回复了 Aaron 的主要答案,感谢您的支持。快乐狩猎 (2认同)

Dou*_*ies 9

这个答案是关于通过直接访问机器特定寄存器 (MSR) 来手动监控某些英特尔处理器的处理器温度的一种方法。

首先要注意的是,在这种情况下,从 MSR 读出的内容与 Tcc(极限温度)有关,因此需要额外计算以确定实际温度。

请参阅Intel® 64 and IA-32 Architectures Software Developer's Manual,或者在您的情况下参考 AMD 等效产品。

就我而言,我想要 0x1B1 处的 MSR 的第 22-16 位,也就是 IA32_PACKAGE_THERM_STATUS。我较旧的 i7-2600K 的 Tcc 是 98 度。

这是一个手动监控温度(和 CPU 频率)的简单脚本:

#! /bin/dash
#
# temp_mon3 Smythies 2016.10.05
#       a simplified version of temp_mon2,
#       for monitoring temp.
#       Note: it is on purpose that -a is not used.
#       Also CPU0 frequency (1 is good enough, when all
#       are loaded).
#
# temp_mon2 Smythies 2016.09.29
#       Monitor Package temperatures.
#       Use clock modulation to control temps.
#       i.e. simulate the second to last level
#       of defense.
#       Use simple primatives.
#       run as sudo
#       hardcoded for my tcc of 98 degrees.
#
echo ... begin package temperature monitoring ...

#
# In case I forgot (which I often do)

modprobe msr

#
# first let the drastic effect of the sudo command decay
# Done later in temp_mon3.

#
# some stuff

COMMAND="rdmsr --bitfield 22:16 -u 0x1B1"
COMMAND2="cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq"

#
# then get on with it

while [ 1 ];do
  sleep 4
  TEMP_RAW=$(eval $COMMAND)
  CPU0_FREQ=$(eval $COMMAND2)
  TEMP_ACT=$((98-TEMP_RAW))
  echo "$TEMP_ACT   $CPU0_FREQ"
done
Run Code Online (Sandbox Code Playgroud)

这是一些示例输出,我在一段时间后添加了一些 CPU 负载(温度从 31 度变为 73 度):

$ sudo ./temp_mon3
[sudo] password for doug:
... begin package temperature monitoring ...
31   1605275
31   1605154
32   1605164
30   1605148
31   1605176
51   3511279
54   3511278
55   3511279
57   3511283
58   3511279
60   3511278
61   3511284
63   3511279
64   3511280
64   3511280
66   3511280
67   3511278
68   3511280
68   3511281
69   3511278
71   3511280
70   3511281
71   3511281
71   3511280
72   3511276
72   3511277
73   3511283
73   3511279
^C
Run Code Online (Sandbox Code Playgroud)


abu*_*bua 7

LM-传感器项目(以及因此sensors命令)利用了的libsensor文库; 库和包是:

我还建议安装开发人员包(包括手册页),这对于 LTS 18.04 和 LTS 20.04 是相同的:

sudo apt install libsensors4-dev
Run Code Online (Sandbox Code Playgroud)

无法在以下位置找到某些背景信息:

man libsensors
man sensors.conf
Run Code Online (Sandbox Code Playgroud)

顺便说一句,这是读取sys目录中温度的同一个库。

综上所述,传感器是一个不错的选择。从命令行观察温度可以很容易地完成

watch -n 1 sensors
Run Code Online (Sandbox Code Playgroud)

如果您打算编写程序,请查看 libsensors 手册man libsensors或使用您的/usr/share/doc/文档。在 C 程序中,您必须包含#include <sensors/sensors.h>标题。它将使用sensors.conf文件/etc/sensors3.conf和/或/etc/sensors.conf/etc/sensors.d/如果您使用此选项,可以在 中找到更多(用户)配置。

如果您认为缺少某些传感器,请查看/sys/class/thermal或链接/sys/devices/virtual/thermal目录。

要获取所有热区的温度,请使用命令

$ cat /sys/devices/virtual/thermal/thermal_zone?/temp

77000
66000
67000
Run Code Online (Sandbox Code Playgroud)

温度以摄氏度 (mC) 为单位测量,在上述情况下,以摄氏度为单位测量的温度为:77.0、66.0、67.0 °C。

要连续观察温度,请使用

watch -n 1 cat /sys/devices/virtual/thermal/thermal_zone?/temp
Run Code Online (Sandbox Code Playgroud)

在此目录中,您还可以找到有关冷却(风扇)设备以及 PID 调节器如何编程的信息。

此外,一些过热保护是基于固件/硬件的编码(这是一个好主意),其设置数据位于您的 bios 中。

如果您更喜欢以 °C 而不是 °mC 显示温度,请使用 bash 计算$((value / 1000 ))或 awk 进行此转换:

cat /sys/devices/virtual/thermal/thermal_zone?/temp | awk '{printf " %5.2f °C\n" , $1/1000}'
Run Code Online (Sandbox Code Playgroud)


kar*_*rel 6

从默认的 Ubuntu 存储库安装 Psensor ( psensor ) 并配置 Psensor 以在温度超过用户确定的最大值时自动播放警报声。这样做的目的是让您系统关闭之前听到警告声音,而不会给系统增加额外的应用程序开销。

Psensor 在桌面右上角的通知区域中显示为一个小温度计图标。您可以随时右键单击温度计图标以显示硬件温度。