Giter Site home page Giter Site logo

karmi / monittr Goto Github PK

View Code? Open in Web Editor NEW
238.0 9.0 33.0 398 KB

Ruby and web interface for Monit statistics

Home Page: http://ephemera.karmi.cz/post/1714578431/monittr-ruby-and-web-interface-for-multiple-monits

License: MIT License

Ruby 95.44% Shell 4.56%

monittr's Introduction

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

monittr's People

Contributors

hron84 avatar karmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monittr's Issues

SocketError getaddrinfo: Name or service not known

I configured my monittr sinatra application with my current monit instances. When I run the application I get this error instead of the machine name:

'SocketError getaddrinfo: Name or service not known'

I checked with curl and monit urls and credentials were ok.

how about add child processes information

one sample service info as follows, how about add the //children //mermory/percenttotal //cpu/percenttotal info?

thanks

    <service type="3">
            <collected_sec>1292484038</collected_sec>
            <collected_usec>76458</collected_usec>
            <name>php-fpm</name>
            <status>0</status>
            <status_hint>0</status_hint>
            <monitor>1</monitor>
            <monitormode>0</monitormode>
            <pendingaction>0</pendingaction>
            <group></group>
            <pid>14509</pid>
            <ppid>1</ppid>
            <uptime>769741</uptime>
            <children>35</children>
            <memory>
                    <percent>0.0</percent>
                    <percenttotal>10.4</percenttotal>
                    <kilobyte>1984</kilobyte>
                    <kilobytetotal>423472</kilobytetotal>
            </memory>
            <cpu>
                    <percent>0.0</percent>
                    <percenttotal>3.5</percenttotal>
            </cpu>
            <port>
                    <hostname>127.0.0.1</hostname>
                    <portnumber>9000</portnumber>
                    <request></request>
                    <protocol>DEFAULT</protocol>
                    <type>TCP</type>
                    <responsetime>0.000</responsetime>
            </port>
    </service>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.