Archive for May 16th, 2013

Raspberry Pi :: Monitoring CPU temperature with RRDTOOL

Recently I’ve got wondering about how hot is the processor in my Raspberry Pi, and how this temperature changes throughout the day/night. There’s a beautiful and simple tool for that purpose, called rrdtool, that stores the data (any kind of data) in the round-robin database and creates nice looking graphs.

The installation of rrdtool is pretty straight forward:

sudo apt-get install rrdtool

And here’s the bash script, that runs every five minutes by cron and saves temperature and creates the picture:

# update .rrd database with CPU temperature
# $Id: update_cputemp 275 2013-05-16 05:20:56Z lenik $

cd /home/lenik

# create database if not exists
[ -f cputemp.rrd ] || {
/usr/bin/rrdtool create cputemp.rrd –step 300 \
DS:cputemp:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \

# read the temperature and convert “59234″ into “59.234″ (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`

/usr/bin/rrdtool update cputemp.rrd `date +”%s”`:$TEMPERATURE

/usr/bin/rrdtool graph cputemp.png DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00 –width 800


No Comments