CPU/HDD temperature graph in LinuxPosted: May 30, 2011
I’m loving Linux. I wanted a graph of the various temperatures the computer monitors. I wasn’t able to find anything pre-packaged that seemed useful, so I found the tools to make my own. Turned out very simple. First, a shell script to log the temperature values as reported by sensors and smartctl, every ten minutes:
#!/bin/sh -e while true do sensors > temp echo -n "\t" `grep CPU temp | cut -c 16-19` >> log smartctl -A /dev/sda > temp echo -n "\t" `grep Temperature_Celsius temp | cut -c 88-` >> log echo -n "\n" >> log sleep 600 done
I used a temp file to allow extraction of multiple fields from a command without running it more than once. I couldn’t get cut’s field mode to work, so I resorted to character counts, which is brittle in that any change in the commands’ columns might break this. Run script with sudo, as smartctl needs it.
Next, use gnuplot to generate a graph. We feed command via stdin, rather than interactively or as a separate file:
echo 'plot "log" using 1 with line title "CPU", "" using 2 with line title "HDD"' | gnuplot -persist -
I’m surprised how simple this roll-your-own solution turned out. Totally flexible, and not some bloated program I have to keep running all the time (just the script’s sleep command).