I’m a big fan of collectd, the pluggable metrics collection daemon, and I came across this post about checking the temperature, so I decided to get collectd up and running on my Pi and pull some graphs out to see if there are any trends.

Previous related posts:

Installation

Because collectd defaults to a 10 second quantum, it will either keep my USB disk drive awake the whole time or wear out my SD card. One option would be to use the ‘network‘ plugin for collectd and ship the readings off to a bigger machine, but in the interests of being self contained, I’ll use a tmpfs filesystem (which is basically a RAM disk).

sudo apt-get install collectd-core
sudo mount -t tmpfs tmpfs /var/lib/collectd/

It won’t start because it’s missing a configuration, so lets put a basic one together, in /etc/collectd/collectd.conf:

LoadPlugin "logfile"
LoadPlugin "rrdtool"

LoadPlugin "interface"
<Plugin "interface">
  Interface "/(veth.*|lo|br)/"
  IgnoreSelected true
</Plugin>

#LoadPlugin "thermal"
#<Plugin "thermal">
#  Device "thermal_zone0"
#  IgnoreSelected false
#</Plugin>

LoadPlugin "table"
<Plugin table>
  <Table "/sys/class/thermal/thermal_zone0/temp">
    Instance thermal
    Separator " "
    <Result>
      Type gauge
      InstancePrefix "pi"
      ValuesFrom 
    </Result>
  </Table>
</Plugin>

You can see a commented out section referencing the thermal plugin- unfortunately this was broken in the version of collectd that is currently in Raspian Wheezy. The fix is in this commit, but I didn’t really want to build collect from source, for instead I’m using the table plugin, and cheating by omitting the PrefixFrom parameter.

Start collectd with sudo /etc/init.d/collectd start and within a few seconds you should see files start to appear in /var/lib/collectd/<your hostname>/table-thermal/. If you don’t have a collectd graphing utility, you can generate one using rrdtool. (I use my own dashboard that I wrote at work usually, but it’s not been updated for collectd 5.1, as Ubuntu still ships 4.10 in their LTS releases).

An example rrdtool incantation, and the graph to go with it:

rrdtool graph ~/temperature.png -s -4hour -w 500 -h 100 \
--lower-limit 0 --alt-autoscale-max --slope-mode \
'DEF:o=/var/lib/collectd/pi/table-thermal/gauge-pi.rrd:value:MAX' \
'CDEF:oo=o,1000,/' 'AREA:oo#ffcc00'

A temperature graph from my Raspberry Pi