Project

nines

0.0
No commit activity in last 3 years
No release in over 3 years
Nines is a simple server monitoring tool written in Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.53
~> 2.4
~> 1.5.3
~> 2.0
 Project Readme

nines¶ ↑

Nines is a simple server monitoring tool written in Ruby, with versatile yet easy to understand notification preferences.

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.

Contacts, Checks & Notifications¶ ↑

Define different contacts to be notified:

contacts: {
  'admin-standard' => { email: 'admin@example.com' },
  'admin-urgent' => { email: 'admin@example.com', twitter: 'admin_oncall', sms: '19875551234', phone: '19875554321' }
}

Group checks according to check parameters and notification preferences:

check_groups: [
  { name: 'Web Sites - High Priority',
    description: 'Check often, notify immediately',
    parameters: { type: :http, port: 80, timeout_sec: 5, interval_sec: 30 },
    notify: [ { contact: 'admin-urgent', after: 2, every: 2, upto: 100 } ],
    checks: [ 'www.corporation.com', 'www.clientabc.com' ]
  },

  { name: 'Web Sites - Low Priority',
    description: 'Check infrequently, use urgent contact only after extended downtime',
    parameters: { type: :http, port: 80, timeout_sec: 15, interval_sec: 60 },
    notify: [
      { contact: 'admin-standard', after: 5, every: 5, upto: 10 },
      { contact: 'admin-urgent', after: 25, every: 10, upto: 10 }
    ],
    checks: [
      'blog.johndoe.name',
      { name: 'Blog Redirect', hostname: 'www.oldblogsite.com', up_statuses: [ 301 ] }
    ]
  },

  { name: 'Servers',
    description: 'Simple ping tests',
    parameters: { type: :ping, protocol: :icmp, interval_sec: 60 },
    notify: [
      { contact: 'admin-standard', after: 2, every: 2, upto: 10 },
      { contact: 'admin-urgent', after: 25, every: 10, upto: 10 }
    ],
    checks: [
      'web1.hostingco.com',
      { name: 'web1 admin IP', hostname: 'web1.hostingco.net' }
    ]
  }
]

Note: nines 1.0 supports email notifications only, but there are many ways to turn emails into other kinds of notifications (e.g. Boxcar).

Usage¶ ↑

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

Configuration¶ ↑

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

The simplest working config for a single web site (Ruby format):

Nines::App.config = {
  contacts: {
    'admin' => { email: 'admin@example.com' },
  },
  check_groups: [
    { name: 'My Web Site',
      parameters: { type: :http },
      notify: [ { contact: 'admin' } ],
      checks: [ 'www.asdf.com' ]
    }
  ]
}

Running nines in a shared hosting environment¶ ↑

If you have multiple servers, you can have them monitor each other, but what if you have only one? You don’t want to have your one server monitoring itself.

If you have a shared hosting account that allows shell access, you may be able to run nines there (check with your host’s policies on monitoring applications). Many hosts have an ancient version of ruby installed, but you can work around that with rvm. Here’s how (tested on Dreamhost <= referral link to support author):

% \curl -L https://get.rvm.io | bash -s stable --ruby  # installs rvm and stable version of ruby
% 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                                # test it in debug mode (remove -d once 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="aaron@biggerbird.com"
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 2>/dev/null

This will try to (re)start nines every 15 minutes. If it is already running, the command will just exit. (The “already running” is printed to STDERR, so redirect that to /dev/null to keep cron from emailing that message to you every 15 minutes.)

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 © 2013 Aaron Namba <aaron@biggerbird.com>

<img src=“https://travis-ci.org/anamba/nines.png” />