nines

Nines is a simple server monitoring tool written in Ruby. It reads in hand-coded YAML config files (see config.yml.sample). Rename to config.yml and edit as needed before first run.

When run, it forks into the background and runs in a continuous loop. If there are bugs in the code (possible) it may die, so keep it running with monit, init, cron, whatever.

It’s no substitute for paid services like Pingdom, but it’s great for keeping tabs on less critical services.

Usage

% gem install nines
% nines -f <config file> start

The config file can be in YAML or ruby format. Refer to the included examples: nines.yml.sample | nines.rb.sample

What if you have only one server, and you want to monitor it? You do need to have a server to run nines on, and you don’t want to have your one server monitoring itself. If you have a shared hosting account that allows shell access, you can run nines there. Many hosts offer an ancient version of ruby, but you can work around that with rvm. Here’s how (tested on Dreamhost:

% \curl -L https://get.rvm.io | bash -s stable --ruby  # installs rvm and stable version of ruby (currently 1.9.3p327)
% echo 'gem: --no-ri --no-rdoc' > ~/gemrc              # gems install more quickly sans documentation
% gem install nines                                    # grab the latest version of the nines gem
% cd ; mkdir nines && cd nines                         # put nines stuff in its own dir
% vi nines.yml                                         # create a config file (start with a sample config)
% nines -d -f nines.yml                                # then test it in debug mode (remove -d once your config is working)

Add nines to your crontab to keep it running through errors and server reboots. When using cron+rvm, remember to grab the GEM_HOME and GEM_PATH environment variables from your shell and make sure the rvm version of ruby is in your path.

% echo $GEM_HOME
/home/[username]/.rvm/gems/ruby-1.9.3-p327
$ echo $GEM_PATH
/home/[username]/.rvm/gems/ruby-1.9.3-p327:/home/[username]/.rvm/gems/ruby-1.9.3-p327@global
% which ruby
/home/[username]/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

Example crontab (note the two different bin dirs for rvm):

MAILTO="[email protected]"
PATH=/home/[username]/.rvm/rubies/ruby-1.9.3-p327/bin:/home/[username]/.rvm/gems/ruby-1.9.3-p327/bin:/usr/bin:/bin
GEM_HOME=/home/[username]/.rvm/gems/ruby-1.9.3-p327
GEM_PATH=/home/[username]/.rvm/gems/ruby-1.9.3-p327:/home/[username]/.rvm/gems/ruby-1.9.3-p327@global

*/15 * * * * nines -d -f /home/[username]/nines/nines.rb

This will try to (re)start nines every 15 minutes. (If it is running, the command will just exit.)

Dependencies

Developed and tested with MRI ruby 1.9.3. Regularly used on CentOS 5, Amazon Linux and OS X 10.8, but ought to work on any POSIX-compliant OS.

Dependencies:

  • trollop (commandline options)

  • net-ping (http/ping testing)

  • dnsruby (dns resolution)

  • mail (email)

License & Copyright

Distributed under MIT license. Copyright © 2012 Aaron Namba <[email protected]>