Raspberry Pi sensors – Munin graphing plugin

I love Munin!  I’ve finally got one of the Raspberry Pi’s to be reasonably stable, so I’ve set up a munin-node on it.  The standard Linux sensord stuff doesn’t run on the arm core, so I had assumed I wouldn’t be able to see any exciting temperature graphs, but I was wrong!

The Raspberry Pi Debian image includes a command called vcgencmd, which allows root to interrogate various settings and measurements.  That includes the temperature, clock frequencies and voltages across various components.

So I’ve knocked up a quick plugin for Munin which gathers that stuff and graphs it.  You can get it over at GitHub here.  The current code looks like this (but the GitHub copy will be most up-to-date),

[sourcecode language=”bash”]
#!/bin/bash
# -*- sh -*-

: << =cut

=head1 NAME

pisense_ – Wildcard-plugin to monitor Raspberry Pi sensors (temp, volts, clock speed)

=head1 CONFIGURATION

This plugin needs to be run as root for vcgencmd to work.

[pisense_*]
user root

=head2 ENVIRONMENT VARIABLES

This plugin does not use environment variables.

=head2 WILDCARD PLUGIN

This is a wildcard plugin. To specify if you want temperature,
clock speed or volts, link this file to _volt, _temp
or _clock.

For example,

ln -s /usr/share/munin/plugins/pisense_ \
/etc/munin/plugins/pisense_clock

will monitor the clock speeds of your pi.

=head1 BUGS

None known.

=head1 NOTES

This plugin is shamelessley based on the ip_ plugin (structure).

=head1 MAGIC MARKERS

#%# family=auto
#%# capabilities=autoconf suggest

=head1 AUTHOR

Tony (tony@darkstorm.co.uk).

=head1 LICENSE

It’s yours, do with it what you like.

=cut

. $MUNIN_LIBDIR/plugins/plugin.sh

sensor=${0##*/pisense_}

if [[ "$1" == "autoconf" ]]; then
if ! /opt/vc/bin/vcgencmd firmware >/dev/null 2>/dev/null; then
echo "no (could not run /opt/vc/bin/vcgencmd as user $(whoami))"
exit 0
else
echo yes
exit 0
fi
fi

# this is flawed, vcgencmd always returns with RC 0. Needs expanding.
if [[ "$1" == "suggest" ]]; then
if /opt/vc/bin/vcgencmd measure_temp >/dev/null 2>/dev/null; then
echo temp
fi
if /opt/vc/bin/vcgencmd measure_volts >/dev/null 2>/dev/null; then
echo volt
fi
if /opt/vc/bin/vcgencmd measure_clock core >/dev/null 2>/dev/null; then
echo clock
fi
exit 0
fi

if [[ "$1" == "config" ]]; then

if [[ "$sensor" == "temp" ]]
then
echo "graph_title Raspberry Pi core temp"
echo "graph_args –base 1000"
echo "graph_vlabel dgrees Celsius"
echo "graph_category sensors"
echo "temp.label Core Temperature"
echo "temp.min 0"
fi
if [[ "$sensor" == "clock" ]]
then
echo "graph_title Raspberry Pi clock frequencies"
echo "graph_args –base 1000"
echo "graph_vlabel herz"
echo "graph_category sensors"
for clock in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi
do
echo "clock$clock.label $clock clock Frequency"
echo "clock$clock.min 0"
echo "clock$clock.type GAUGE"
done
fi
if [[ "$sensor" == "volt" ]]
then
echo "graph_title Raspberry Pi voltages"
echo "graph_args –base 1000"
echo "graph_vlabel volts"
echo "graph_category sensors"
for volt in core sdram_c sdram_i sdram_p
do
echo "volt$volt.label $volt voltage"
echo "volt$volt.min 0"
echo "volt$volt.type GAUGE"
done
fi

exit 0
fi;

if [[ "$sensor" == "temp" ]]
then
temp=$(/opt/vc/bin/vcgencmd measure_temp | awk -F"=" ‘{print $2}’ | awk -F"’" ‘{print $1}’)
echo "temp.value $temp"
fi
if [[ "$sensor" == "clock" ]]
then
for clock in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi
do
clockval=$(/opt/vc/bin/vcgencmd measure_clock $clock | awk -F"=" ‘{print $2}’)
echo "clock$clock.value $clockval"
done
fi
if [[ "$sensor" == "volt" ]]
then
for volt in core sdram_c sdram_i sdram_p
do
voltage=$(/opt/vc/bin/vcgencmd measure_volts $volt | awk -F"=" ‘{print $2}’ | tr -d "V")
echo "volt$volt.value $voltage"
done
fi
[/sourcecode]

I’ll post some sample screenshots in a bit!

WordPress Plugins

Wrote my first WordPress plugin today (for www.bookthing.co.uk), it’s a pretty simple plugin architecture especially if you’re not trying to do anything too clever.  I just wanted a shortcode (some text you put into a post which is expanded by a plugin) to read some values from some custom fields and include them in the article footer.  It saves having to paste lots of formatting HTML into each post and lets you just suck content from the custom fields.

I was surprised I couldn’t find a simple ‘template’ style plugin on the WordPress site, maybe I was just using the wrong search terms.  It’s the kind of thing that would be very useful for building common information boxes for reviews, etc.  Anyway, I hacked together a 59 line php file, of which around 1/3rd is info and license to read two custom fields and whack them into a div.

Took about 9000% less time than I expected.

Stats, stats and more stats (and lies!)

I’m a bit of a web-stat-aholic.  Despite the fact that this is a personal blog with hardly any relevance to the outside world, I still feel the need to see how many people read it.  But then that’s true of all the websites I throw up.  In some ways I find the stats just interesting, even if the numbers are really small, it amuses me how people find the sites, what search strings they use, and how certain pages get more hits.

I use three stats systems on this site, Google Analytics, the WordPress.com stats plugin, and the CyStats plugin.  Clearly the whole area of ‘what constitutes a visitor’ is murky at best, and when a page is made up of lots of resources that each generate a request to the web server, it gets a little harder to work out how many hits you’ve had, but I’m amused by the difference in information the three systems provide, and the apparent totally useless WordPress.com stats plugin.

When I moved the blog to WordPress I thought the WordPress.com stats plugin would be a good option, and indeed it looked like it was reasonably accurate when the visitor count was 1 or 2 people a day.  However, as the site gets found by google and random hits start to increase, the stats look more and more crazy, in particular the ‘top posts and pages’ section.

Here’s the current info from that plugin for pages visited today and yesterday,

stats1So yesterday, apparently the only two pages read on the site were the Watchmen post and the Wii Fit page.  And today, people are only reading the Watchmen post and nothing else.  I kinda find that hard to believe, and in fact, the other two stats systems agree that it’s complete bollocks.  I’ve no idea what-so-ever what the WordPress.com stats plugin is doing but it’s certainly not recording which pages are being viewed.

Total visitors or page views being different I can live with because how they’re measured is pretty vague, but you would think a stats plugin would know which pages were being read, that is kind of the whole point.  In contrast, this is what CyStats thinks has been read today,

Windows 7 Beta - file sharing                           8   14%
Main page                                               8   14%
of protein and fat and blood sugar                      4   7%
So, what went wrong (or WordPress, Cron and Squid)      3   5%
Lord of the Rings Online - a review - part one          3   5%
Windows 7 Beta in Sun's xVM VirtualBox                  3   5%
Where oh where has my Gallium gone?                     3   5%
/category/politics                                      2   3%
/tag/dvd                                                2   3%
A month with WordPress                                  2   3%
Old photo's                                             2   3%
First real go at non-drybrush skin                      2   3%
Whiskey & Red Bull                                      2   3%
Windows 7 beta + Lord of the Rings Online               2   3%
David Gemmell Legend Award news                         2   3%
About                                                	2   3%
Eating without thinking                                 2   3%
/2006/08                                                2   3%
Archives                                                2   3%

which as you can see is rather more varied (and slightly more believable).  However, the list of visited pages on Google Analytics for today is different again, not just the numbers, but the actual pages, listing some not viewed above and missing out some that were viewed.

Ultimately, I have the logs from my web hosting account (when they work), and that means I can see, for real, which pages are being accessed and how often, but reading those logs can be a pain and using tools to interpret them just introduce more interpretation that leads to yet another set of figures.

I guess where I’m going with this post is that trusting the stats for your site is impossible, but some tools are clearly more broken than others, and the WordPress.com stats plugin is entirely useless, since it’s clearly unable to work out which page your visitors are reading.  Don’t trust it.