CPU/HDD temperature graph in Linux

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
    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

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).


One Comment on “CPU/HDD temperature graph in Linux”

  1. DR says:

    Very nice. I’ll try this when I have the time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s