Where can I find the log file of my system temperature?
Solution 1:
Here is what I have done to log temps.
Prerequisites : lm-sensors dateutils gnuplot
(gnuplot
for visualization, not necessary)
One can install the above using the following command in terminal.
sudo apt install lm-sensors dateutils gnuplot
Coming to the main script :
#!/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---------------------------------------------------------
The gnuplot
command in the end needs two more files which are following.
file : plot_day
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
file: 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 '%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
Running the script Save it, make it executable and run it as,
./script_name $nd$nh$nm$ns m
n
is some number, while d=days, h=hours, m=minutes, s=seconds
m
step size of measurement in seconds. Measurement will be taken after interval of m
seconds
Example of usage.
./log_script.sh 3d12h 30
(explanation: log for 3 days 12 hrs with measurement at each 30 seconds)
./log_script.sh 12m30s 10
./log_script.sh 45m 2
./log_script.sh 55s 1
{It can be used with cron
for regular logs. I use this script only when benchmarking and/or overclocking.}
Output
This scripts generates a log file as t_log.txt
which has the temperature of the CPU cores. (For system with different cores there will be a small change. Edit the line in gnuplot script files which are plot_time
and plot_day
specifically, "t_log.txt" using last_column:column_for_each_core with lines title "core:6" linewidth 3
).
The output in t_log.txt
looks like following,
(since this is a six core machine hence 6 columns of temps.)
28.0 28.0 27.0 27.0 27.0 27.0 12/18/2016 00:50:21
28.0 26.0 27.0 26.0 27.0 27.0 12/18/2016 00:50:23
27.0 27.0 26.0 26.0 27.0 26.0 12/18/2016 00:50:25
28.0 27.0 29.0 26.0 27.0 26.0 12/18/2016 00:50:27
26.0 27.0 26.0 28.0 27.0 26.0 12/18/2016 00:50:29
27.0 26.0 28.0 26.0 27.0 26.0 12/18/2016 00:50:31
27.0 26.0 26.0 26.0 27.0 26.0 12/18/2016 00:50:33
27.0 27.0 28.0 28.0 27.0 27.0 12/18/2016 00:50:35
And the plot generated looks like following :
The script can generate such plots for very long logs or many other parameters. It is also possible to plot in between logging which just needs modification of the script. The script can be improved a lot and logging of several other parameters like RAM usage, CPU load, HDD activity can be added. Enjoy !