Last weekend was time to upgrade my RPi from Debian 7 (Wheezy) to Debian 9 (Stretch).
One of the main reasons to do this was i wanted to install collectd and collectd isn’t available for Arm architectures on Debian 7, also the source code doesn’t compile (or at least very easily – I got all sorts of ./configure macro errors).
This RPi monitors my central heating by monitoring the temperature of the pipework in and out of the boiler. I use a DS9490 USB to 1-wire dongle and a whole heap of DS1820 temperature sensors wired in parallel.
Download the latest raspbian image from https://www.raspberrypi.org/downloads/raspbian/
I grabbed Raspbian Stretch Lite, mainly as I like to build my services/servers from the ground up or from a little as I can – something I do at work. 🙂
Drop the image onto an SDcard and mount it on your laptop/desktop. There are lots of good resources on how to do that so i won’t LMGTFY.
To get SSH available from first boot in the /boot partition and do the following as root;
# touch ssh
So you get usable NIC names (eg. eth0) do the following on the /boot partition;
# echo -n " net.ifnames=0 biosdevname=0" >> cmdline.txt
This also makes setting up the collectd config easier.
The other thing to do is setup the hostname – find your main root partition on the RPi.
# echo "rpi-test" > /etc/hostname
Now you can boot the new RPi and access it remotely. Of course you need to know it’s DHCP address – which you can find on your DHCP server (or home router).
post boot setup
Once booted, it’s time to patch, considering the latest build is two months old, there will be a load of patches to add.
# apt-get update && apt-get upgrade -y
Now we can get to the good part installing 1-wire.
# apt-get install owfs ow-shell -y
Then stop the services and create the 1-wire filesystem mountpoint.
# /etc/init.d/owhttpd stop # /etc/init.d/owserver stop # mkdir /mnt/1wire
Next stop was to copy over the saved copies of my configs and restart the services.
/etc/hosts /etc/owfs.conf /etc/owfs.aliases /etc/init.d/owserver start /etc/init.d/owhttpd start
Now I can run the usual owfs shell tools to see my temperature sensors.
$ owdir / /CH_return /Two /CH_feed /Hot_water /Cold_water /One /USB_dongle /bus.0 /uncached /settings /system /statistics /structure /simultaneous /alarm
Incidentally if you are looking for a USB Active Repeater (a long USB extension) then get one of these: https://www.amazon.co.uk/gp/product/B00A30FOD0/
It works really well, plug and play, it just looks like a 4-port USB hub.
collectd is simple to install. I use collectd to collect stats from my Linux devices.
#apt-get install collectd
Then I stop the service and copy over my config and restart it again.
# systemctl restart collectd
You will probably notice that I use the Exec plugin to read the 1-wire, which enables collectd to push it back out as metrics to the receiver.
Apart from reading 1-wire the interesting bit is how the data is written back to standard out (unbuffered) with the PUTVAL format. This is what collectd expects.
To get the plugin to run you need to install the python module for 1-wire.
# apt-get install python-pip # pip install pyownet
Also to make sure I get my logs over at my central server, I push all my syslog to that host.
# vi /etc/rsyslog.conf *.* @10.0.0.67
As this is a RPi, I pretty much delete all the rules, just use that one and restart rsyslog
systemctl restart syslog
On the splunk side of things to get the metrics you need to create an index (collectd) and http event collector (with the secret used in the collectd config). You can find examples easily enough on the splunk site on how to do that.
Checking to see if the metric are appearing is done with this search:
| mcatalog values(metric_name) WHERE index=collectd AND metric_name=owfs*
which will give you something like this:
owfs_CH_feed.temperature.value owfs_CH_return.temperature.value owfs_Cold_water.temperature.value owfs_Hot_water.temperature.value owfs_One.temperature.value owfs_Two.temperature.value
Graphing the metrics was a little more complex
| mstats avg(_value) as "Temp" prestats=t WHERE metric_name="owfs_*" span=1m by metric_name | rex field=metric_name "owfs_(?P<tname>.*?)\.temperature.value" | timechart avg(_value) as "Temp" span=1m by tname
I used a regular expression to cut out the sensor name from the metric_name
Analytics for Linux on Splunk
There is a great free plugin for graphing metrics called Analytics for Linux, which will graph all your collectd metrics very easily. It does require an up to date version of collectd (Debian 9 version).
So that’s the end of my reminder to myself on how I setup, RPi, 1-wire, collectd and splunk.
I hope you found it useful too.