Saturday, June 09, 2007

Visualize hard disk temperature with gnuplot

When the kernel issue I blogged about hit me I first suspected a(nother) defective hard disk. I opened the case to find my 250GB Samsung Spinpoint SP2504C so hot that I could barely touch it without burning my fingers. Mentally preparing to reinstall Ubuntu on a disk yet to be bought I remembered that this disk was not needed to boot at all, because it just contains data files. (Anyone else losing track of what is stored where with the disk sizes these days?)

So I decided to just let everything cool down and then start again - in the meantime I had noticed that the latest kernel update had caused the effect and that starting with 2.6.20-15-386 would work. Once I was back to my desktop I installed some packages for hardware monitoring:

ds@yavin:~$ sudo apt-get install hddtemp sensors-applet lmsensors

Once they (and their dependencies) had all been installed I first started toying with hddtemp:

ds@yavin:~$ sudo hddtemp /dev/sd[abc]
/dev/sda: IC35L080AVVA07-0                        : 46°C
/dev/sdb: SAMSUNG SP2504C                         : 34°C
/dev/sdc: SAMSUNG HD403LJ                         : 32°C

This little script collects the data from disks /dev/sd[abc] and stores them in a space separated format into a logfile:

timestamp=$( date +%T );
temps=$( hddtemp /dev/sd[abc] | awk -F: ' { print $3 } ' | cut -c2-3 | tr "\n" " " );
echo "${timestamp} ${temps}" >> ${logfile}

It is invoked via cron once per minute. This was added to /etc/crontab

*/1 *    * * *   root   /usr/local/bin/ 

This data can now be plotted graphically using gnuplot:

#!/usr/bin/gnuplot -persist
#       G N U P L O T
#       Version 4.0 patchlevel 0
#       last modified Thu Apr 15 14:44:22 CEST 2004
#       System: Linux 2.6.20-15-386
#       Copyright (C) 1986 - 1993, 1998, 2004
#       Thomas Williams, Colin Kelley and many others
#       This is gnuplot version 4.0.  Please refer to the documentation
#       for command syntax changes.  The old syntax will be accepted
#       throughout the 4.0 series, but all save files use the new syntax.
#       Type `help` to access the on-line reference manual.
#       The gnuplot FAQ is available from
#       Send comments and requests for help to
#               <>
#       Send bugs, suggestions and mods to
#               <>
# set terminal x11 
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000
set border 31 lt -1 lw 1.000
set xdata time
set ydata
set zdata
set x2data
set y2data
set timefmt x "%H:%M:%S"
set timefmt y "%H:%M:%S"
set timefmt z "%H:%M:%S"
set timefmt x2 "%H:%M:%S"
set timefmt y2 "%H:%M:%S"
set timefmt cb "%H:%M:%S"
set boxwidth
set style fill empty border
set dummy x,y
set format x "% g"
set format y "% g"
set format x2 "% g"
set format y2 "% g"
set format z "% g"
set format cb "% g"
set angles radians
unset grid
set key title ""
set key right top Right noreverse enhanced box linetype -2 linewidth 1.000 samplen 4 spacing 1 width 0 height 0 autotitles
unset label
unset arrow
unset style line
unset style arrow
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set encoding default
unset polar

unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 100, 100
set isosamples 10, 10
set surface
unset contour
set clabel '%8.3g'
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
set xzeroaxis lt -2 lw 1.000
set yzeroaxis lt -2 lw 1.000
set x2zeroaxis lt -2 lw 1.000
set y2zeroaxis lt -2 lw 1.000
set tics in
set ticslevel 0.5
set ticscale 1 0.5
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set xtics border mirror norotate autofreq 
set ytics border mirror norotate autofreq 
set ztics border nomirror norotate autofreq 
set nox2tics
set noy2tics
set cbtics border mirror norotate autofreq 
set title "Plattentemperaturverlauf" 0.000000,0.000000  font ""
set timestamp "" bottom norotate 0.000000,0.000000  ""
set rrange [ * : * ] noreverse nowriteback  # (currently [0.00000:10.0000] )
set trange [ * : * ] noreverse nowriteback  # (currently ["31/12/99,23:59":"01/01/00,00:00"] )
set urange [ * : * ] noreverse nowriteback  # (currently ["31/12/99,23:59":"01/01/00,00:00"] )
set vrange [ * : * ] noreverse nowriteback  # (currently ["31/12/99,23:59":"01/01/00,00:00"] )
set xlabel "Time" 0.000000,0.000000  font ""
set x2label "" 0.000000,0.000000  font ""
set xrange [ "00:00:00" : "23:55:00" ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set ylabel "Temperature (C) " 0.000000,0.000000  font ""
set y2label "" 0.000000,0.000000  font ""
set yrange [ 20.0000 : 60.0000 ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set zlabel "" 0.000000,0.000000  font ""
set zrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set cblabel "" 0.000000,0.000000  font ""
set cbrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set zero 1e-08
set lmargin -1
set bmargin -1
set rmargin -1
set tmargin -1
set locale "C"
set pm3d scansautomatic flush begin noftriangles nohidden3d implicit corners2color mean
unset pm3d
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB 
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin 0.9,0.2 size 0.1,0.63 bdefault
set loadpath 
set fontpath 
set fit noerrorvariables
plot '/var/log/hddtemp.log' using 1:2 with line title "hda", '/var/log/hddtemp.log' using 1:3 with line title "hdb", '/var/log/hddtemp.log' using 1:4 with line title "hdc"
#    EOF

Running the gnuplot script above displays a graph with the temperature curves for my three hard disks. You will need to modify both scripts to match your disk configuration. Furthermore logrotate should be configured to start a new file every day, otherwise the graph will look somewhat strange.

sample graph

You need not care about the

sh: kpsexpand: not found
sh: kpsexpand: not found
sh: kpsexpand: not found
sh: kpsexpand: not found

messages when you run the script. This seems to be a packaging problem with gnuplot. kpsexpand seems to belong to the tetex-package, which however is not really needed for it to work.

Additionally I have installed the Gnome Sensors applet that now continuously displays data from several sensors, including CPU temperature and fan speeds.

BTW: The temperaturs above were taken after I installed a fan in the front panel of my PC's case. Before that all disks were 10-15°C warmer, bringing them close to their specified limits.


Anonymous said...

Great post! You can just use the -n flag on hddtemp which outputs only the temp. Save some confusion with awk and cut.

coldrever said...

if the degree of my HD is 46 (according to hddtemp) what it mean ?
i must change my ventilator

acer tm4100 / hd: IDE / Ubuntu 8.10