Project

monittr

0.1
No commit activity in last 3 years
No release in over 3 years
Monittr provides a Ruby interface for loading and displaying statistics from multiple Monit instances and helpers for Sinatra web applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Monittr

Monittr provides a Ruby interface for the Monit systems management system. Its main goal is to aggregate statistics from multiple Monit instances and display them in an attractive web interface.

Monittr loads XML from the web server embedded in Monit and makes it accessible as Ruby objects. It also provides helpers for Sinatra applications, to display the information as HTML. You can insert the statistics into any page, or create a dedicated one. You can use the default template, or create your own. The default template is located in lib/monittr/sinatra/template.erb and pictured below.

Screenshot: Monittr, a web interface for Monit statistics

Usage

First, clone or download the sources from Github, to get the latest version:

$ git clone http://github.com/karmi/monittr.git
$ cd monittr

You can try the Ruby interface in a IRB console:

$ irb -Ilib -rubygems -rmonittr

You have to pass one or more URLs to a local or remote Monit HTTP server:

cluster = Monittr::Cluster.new ['http://localhost:2812/']

In case you don't have a running Monit server at hand, use the provided FakeWeb setup:

require 'fakeweb'
FakeWeb.register_uri(:get, 'http://localhost:2812/_status?format=xml', :body => File.read('test/fixtures/status.xml') ); nil

cluster = Monittr::Cluster.new ['http://localhost:2812/']

Now, you can display the information from the cluster:

cluster.servers.size

server = cluster.servers.first
server.system.status
server.system.load

server.filesystems.first.name
server.filesystems.first.percent

server.processes.first.name
server.processes.first.cpu
server.processes.first.memory

...

You can also check out the HTML display by running the example application:

$ ruby examples/application.rb
$ open http://localhost:4567/

You should see the information about two faked Monit instances in your browser. (You may need to comment out the FakeWeb section, if you're passing localhost URLs.)

To use the gem in a Sinatra application, you have to require the gem, the Sinatra helper and provide the URLs to Monit instances:

require 'monittr'
require 'monittr/sinatra/monittr'
set :monit_urls,  %w[ http://production.example.com:2812 http://staging.example.com:2812 ]

In a “modular” Sinatra application, you have to register the module explicitely as well:

register Sinatra::MonittrHTML

Then, just call the helper in your template:

<%= monittr.html %>

You may use the example application as the starting point.

Customization

It's easy to customize the HTML output by setting the appropriate options in your Sinatra application.

set :template,   Proc.new { File.join(root, 'template.erb') }
set :stylesheet, '/path/to/my/stylesheet'

Installation

The best way to install the gem is from the source:

$ git clone http://github.com/karmi/monittr.git
$ cd monittr
$ rake install

Stable versions of the gem can be installed from Rubygems:

$ gem install monittr

Other

Any feedback, suggestions or patches are welcome via e-mail or Github Issues/Pull Requests.

Check out the monit gem for another Ruby interface to Monit.


Karel Minarik