在哪里可以找到系统温度的日志文件?

jrg*_*jrg 8 logging temperature

因此,我已经lm-sensors安装了该软件包,并且可以运行sensors并获取系统温度的详细信息,如下所示:

acpitz-virtual-0
Adapter: Virtual device
temp1:        +45.0°C  (crit = +120.0°C)

k10temp-pci-00c3
Adapter: PCI adapter
temp1:        +46.5°C  (high = +70.0°C)
                       (crit = +115.0°C, hyst = +115.0°C)
Run Code Online (Sandbox Code Playgroud)

我想要做的是能够查看温度的日志(例如,每 5 分钟)。这可能吗?

ank*_*540 7

这是我为记录临时文件所做的工作。

先决条件:lm-sensors dateutils gnuplotgnuplot用于可视化,没有必要)

可以在终端中使用以下命令安装上述内容。

sudo apt install lm-sensors dateutils gnuplot
Run Code Online (Sandbox Code Playgroud)

来到主脚本:

sudo apt install lm-sensors dateutils gnuplot
Run Code Online (Sandbox Code Playgroud)

最后的gnuplot命令还需要另外两个文件。

文件 : plot_day

#!/bin/bash 
# Log temperature over some time  interval given as days, hours, minutes or seconds.
# enter the variables according to your usage in the following seciton :
duration="$1"  #duration format is  ndnhnmns where n is some number and d is day,
# h is hours, m is minutes and s is seconds. For example, 4d , 4d5h30m , 5m30s, 6h30m30s are all valid.

step="$2"
#----------------------------------------------------------------------
#starting time taken as current
dt=$(date '+%Y-%m-%dT%H:%M:%S');
#et=$(date '+%Y-%m-%dT%H:%M:%S');

#----------------------------------------------------------------------
a=$(dateutils.dadd $dt  $duration )
b=$(dateutils.ddiff $dt $a -f '%S')
echo $a $b

ntimes=$((b/step))
echo $ntimes


echo "logging...";
rm t_log.txt
nms=0
while [  $nms -lt $ntimes ];  do
        sensors | grep -A 0  'Core' | cut -c18-21 |tr "\n" "\t" >> temp.txt
        let nms=nms+1
        sleep  $step
        now=$(date +"%m/%d/%Y %T")
#       echo $now
        echo -e "$(cat temp.txt)""\t$now"  >> t_log.txt
        rm temp.txt
done


#plotting using gnuplot to get a beautiful plot. 
day=86400 #different x-axis for different  time duration. A day = 86400 seconds

fcode=$(date "+%Y-%m-%d_%H%M%S") # generate a time stamp 
#echo $fcode
if [[ "$b" > "$day" ]]
then
        gnuplot -e "filename='temp_plot_$fcode'" plot_day
else
        gnuplot -e "filename='temp_plot_$fcode'" plot_time
fi
#end-of-script---------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

文件: plot_time

set terminal pngcairo size 1200,600 enhanced font 'Verdana'
set output sprintf('%s.png', filename)
set timefmt '%d/%m/%Y %H:%M:%S'
set xdata time
set format x '%m/%d'
set grid ytics lc rgb "#bbbbbb" lw 2 lt 1
set yr [20:100]
set title "Temperature log"
set xlabel "Date (month:day)"
set ylabel "degree Celcius"

plot "t_log.txt" using 7:1 with lines title "core:1" linewidth 3,\
     "t_log.txt" using 7:2 with lines title "core:2" linewidth 3 ,\
     "t_log.txt" using 7:3 with lines title "core:3" linewidth 3 ,\
     "t_log.txt" using 7:4 with lines title "core:4" linewidth 3 ,\
     "t_log.txt" using 7:5 with lines title "core:5" linewidth 3 ,\
     "t_log.txt" using 7:6 with lines title "core:6" linewidth 3
replot
Run Code Online (Sandbox Code Playgroud)

运行脚本 保存它,使其可执行并运行它,

set terminal pngcairo size 1200,600 enhanced font 'Verdana'
set output sprintf('%s.png', filename)
set timefmt '%d/%m/%Y %H:%M:%S'
set xdata time
set format x '%H:%M:%S'
set grid ytics lc rgb "#bbbbbb" lw 2 lt 1
set yr [20:100]
set title "Temperature log"
set xlabel "Time (Hour:Minute:Second) "
set ylabel "degree Celcius"
plot "t_log.txt" using 7:1 with lines title "core:1" linewidth 3,\
     "t_log.txt" using 7:2 with lines title "core:2" linewidth 3 ,\
     "t_log.txt" using 7:3 with lines title "core:3" linewidth 3 ,\
     "t_log.txt" using 7:4 with lines title "core:4" linewidth 3 ,\
     "t_log.txt" using 7:5 with lines title "core:5" linewidth 3 ,\
     "t_log.txt" using 7:6 with lines title "core:6" linewidth 3 
replot
Run Code Online (Sandbox Code Playgroud)

n 是一些数字,而 d=days, h=hours, m=minutes, s=seconds

m以秒为单位的测量步长。将在m几秒钟的间隔后进行测量

用法示例。

./script_name $nd$nh$nm$ns m
Run Code Online (Sandbox Code Playgroud)

(说明:记录 3 天 12 小时,每 30 秒测量一次)

./log_script.sh  3d12h 30
Run Code Online (Sandbox Code Playgroud)

{它可以cron用于常规日志。我仅在基准测试和/或超频时使用此脚本。}


输出

此脚本生成一个日志文件,t_log.txt其中包含 CPU 内核的温度。(对于具有不同内核的系统,会有一个小的变化。编辑 gnuplot 脚本文件中的行plot_timeplot_day特别是,"t_log.txt" using last_column:column_for_each_core with lines title "core:6" linewidth 3)。

中的输出t_log.txt 如下所示,(因为这是一台六核机器,因此有 6 列临时数据。)

./log_script.sh  12m30s 10

./log_script.sh  45m 2

./log_script.sh  55s 1
Run Code Online (Sandbox Code Playgroud)

生成的图如下所示:

从 gnuplot 生成的图

该脚本可以为很长的日志或许多其他参数生成这样的图。也可以在只需要修改脚本的日志记录之间进行绘图。该脚本可以进行很多改进,并且可以添加其他几个参数的日志记录,例如 RAM 使用率、CPU 负载、HDD 活动。享受 !