by Aaron Cieslicki


My Compost Pile Sends Nagios Notifications

If you needed any more proof that Nagios can monitor just about anything, here you go: Nagios monitors my compost pile. And while this article is focused on compost, what it really is about is how easy it can be to do environmental monitoring with Nagios using off-the-shelf sensors and chip sets.

It turns out that the hotter a compost pile is, the faster the pile is turning raw materials into compost. As soon as I learned that I can tell how fast the composting process is happening by the internal temperature of the compost pile, I had to know what was going on in there.


The Science of Compost Temperature

Now, the science of composting tells us that the compost pile heats up because there are microorganisms in there feasting on the raw materials. As they feast, their work generates heat, and the temperature starts to rise.

This work, though, uses oxygen from the pile. As the oxygen gets used up, it limits the work the microorganisms can do, and the pile starts to cool. At a certain point, the pile needs to be turned to add more oxygen so it will reheat.


It Started Innocently Enough

I decided to use the DS18B20 waterproof temperature sensor. The base of the compost pile is a hot (up to 140 degrees Fahrenheit), wet place, and I needed a sensor that could stand up to that environment.

The sensor only comes with three feet of lead wire, so I soldered it to a 30-foot section of 22GA three-wire appliance cord. Then I ran the cord back to the GPIO pins on a Raspberry Pi in my garage. Using the simple Linux driver for the device, I could take a reading any time I wanted!

The Pi is a fantastic platform for sensor monitoring with Nagios. It’s not only a fully network-connected Linux box in its own right (so you can run about any code in any language you’d like), but it can also run Nagios Core (and I’ve heard some can get XI to run on it as well, but that’s an article for another time). Plus, it’s got 40 GPIO pins supporting a number of communication protocols. One of the USB ports can also be used to connect to and power an Arduino to run even more sensors.

Some people point out that the Raspberry Pi is not quite ready for the datacenter, and they are right. Still, there are IOT platforms out there that keep the Pi form factor, processor, and GPIO layout. The biggest knock against the Pi is its reliance on a sometimes flaky SD card, but again there are platforms out there that can boot from eMMC rather than the SD card, and some have connectors for an on-board M.2 SSD.


Next Thing You Know, You’re Writing a Plugin

But who wants to obsessively check anything? And really, I didn’t need to know the temperature of the pile … I needed to know when to turn the pile.
What I needed was a notification.
What I needed was a compost plugin.

Fortunately, writing a Nagios plugin is not as hard as you might imagine. While the Nagios Plugin Development Guidelines are not written as a how-to, the document is invaluable as to how a plugin needs to function.

I wrote my plugin in Python. It uses the Linux driver to check the temp of the pile and generates a warning alert when pile temperature drops below the first threshold, and then a critical alert when it drops below the second. When the pile goes critical, I know it is time to turn the pile to add more oxygen.

The great thing about using the Pi for monitoring is that we can run the Pi as a remote host and run our plugins via NRPE, or we can run it as a Nagios server. I opted to run it as a Nagios server.

The other awesomeness we get with plugins is performance data.

As a disclaimer I’ll tell you that I am not a developer, so if my code is a little wonky, well, it works as well as I need it to. And that’s maybe all a plugin really needs to do, for compost, anyway.

What unusual things are you monitoring? Let us know at