I recently got around to building myself a home server, something to use as a local backup/media server that could be left on all the time. Once I’d spent the appropriate amount of time on Google solving various problems I had, I managed to get a newly installed version of Ubuntu Server with 4 terrabytes of usable storage managed by the excellent ZFS file system.
Then I turned to monitoring, after all I don’t want to find out that one of my drives died 2 months ago when the second drive fails and I’ve lost data! I needed something that would email me when a drive failed or a ZFS pool was degraded. I also wanted to be able to see the CPU and memory usage from anywhere as well as get alerts when the server became unavailable.
To do this I started to use New Relic, a platform that is designed for monitoring web apps but that can also be used very effectively for monitoring home servers for free using their ‘lite’ plan. It gives you a nice web app that will show you lots of useful statistics, draw graphs (who doesn’t like a good graph) and most importantly, send alerts.
I’ve written and released a ZFS plugin for New Relic that allows you to monitor your ZFS pools, skip to step 3 if you already have New Relic set up, otherwise I’ll start from the beginning:
1. Create a New Relic account
Go to the Newrelic home page and click the ‘Create Free Account’ button, after supplying a few details you should be able to continue to Step 2. Here you will need to tell New Relic how big your company is, and what your role is.
As we are monitoring a home server I’d suggest just picking the smallest options for each and selecting any of the languages for ‘What would you like to monitor’. I’ve set my company name to be my name, it doesn’t seem to matter.
After clicking ‘Create my free account’ button you should be taken to your new account.
2. Install the server monitoring system
Next we need to install the New Relic agent that will collect data about our server. Ignore the information about deploying a web agent and click the Servers button on the left hand side. This will give you a brief introduction to server monitoring and allow you to get instructions for how to install the agent on some popular operating systems, click on the appropriate option and follow the instructions but make sure you note down your license key as you’ll need it for installing the ZFS plugin.
If everything goes well, you should start seeing data after a few minutes, if you haven’t got a ZFS setup to monitor, then you can skip to step 4, otherwise its time to install the plugin.
3. Install ZFS plugin
Installing the Newrelic ZFS plugin is very simple as it is packaged as a Ruby Gem, if your system doesn’t have Ruby already (the command we are going to use is ‘gem’) then there is a good guide for the most common systems on the Ruby website. Once Ruby has been installed run the command
gem install newrelic_zfs
Once this has completed you need to provide the plugin with some config, if you run the command
You will be asked if you want to create a new config file. Select ‘y’ and then type the location of where you want the file to live. Next you will be prompted for your New Relic License Key and a name for the server you have installed the plugin on.
After this a config file will be created and the plugin will start running, after a few minutes a tab should appear on your Newrelic account labelled ‘ZFS’:
To finish the installation you probably want to daemonize the process, this obviously depends on the system you’re using but I’ve used this template on Github in the past. The command needed is ‘newrelic_zfs full/path/to/config.yml’ and it needs to be run as a user with permission to run ‘zpool list’ (root on my system)
4. See results and set up alerts
The ZFS plugin has default alert levels, you can change them by clicking on the settings button for the server you want to change. The Unhealthy pools level is set to 0.1 and 0.2 so that as soon as any pool is unhealthy, an alert will be triggered.
For general server alerts you need to set up a server policy. New Relic have their own documentation on how to do this so I won’t reinvent the wheel but just point you in the correct direction