monittr 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,45 @@
1
1
  # Monittr : A Web Interface for Monit Statistics #
2
2
 
3
- _Monittr_ provides a _Ruby_ interface for displaying [_Monit_](http://mmonit.com/) statistics in [_Sinatra_](http://www.sinatrarb.com/) based web applications.
3
+ _Monittr_ provides a _Ruby_ interface for the [_Monit_](http://mmonit.com/monit/) systems management system.
4
4
 
5
- It loads information from the [web server embedded in _Monit_](http://mmonit.com/monit/documentation/monit.html#monit_httpd) and makes it accessible as Ruby objects.
5
+ Its main goal is to display statistics from multiple _Monit_ instances in an attractive web interface.
6
6
 
7
- It also displays the information in HTML with the provided helpers. You can use the default template, or provide your own. The default template is located in `lib/monittr/sinatra/template.erb`.
7
+ _Monittr_ loads XML from the [web server embedded in _Monit_](http://mmonit.com/monit/documentation/monit.html#monit_httpd) and makes it accessible as Ruby objects.
8
+
9
+ It also provides helpers for [_Sinatra_](http://www.sinatrarb.com/) applications, to display the information as HTML. You can insert the _Monit_ information into any page, or create a dedicated page.
10
+
11
+ You can use the default template, or create your own. The default template is located in `lib/monittr/sinatra/template.erb`.
12
+
13
+ The default template is pictured below.
8
14
 
9
15
  ![Screenshot: Monittr, a web interface for Monit statistics](https://github.com/karmi/monittr/raw/master/screenshot.png)
10
16
 
11
17
 
12
18
  ## Usage ##
13
19
 
14
- First, clone or download the sources from [_Github_](https://github.com/karmi/monittr/zipball/master).
20
+ First, clone or [download](https://github.com/karmi/monittr/zipball/master)
21
+ the sources from [_Github_](https://github.com/karmi/monittr/), to get the latest version:
15
22
 
16
- You can try the interface in a IRB console:
23
+ $ git clone http://github.com/karmi/monittr.git
24
+ $ cd monittr
25
+
26
+ You can try the _Ruby_ interface in a IRB console:
17
27
 
18
28
  $ irb -Ilib -rubygems -rmonittr
19
29
 
20
- You have to pass one or more full URLs to a running Monit web server XML output, eg. `http://admin:monit@example.com:2812/`.
30
+ You have to pass one or more full URLs to a local or remote Monit web server output:
21
31
 
22
- In case you don't have a running Monit handy, fake its output:
32
+ cluster = Monittr::Cluster.new ['http://localhost:2812/']
23
33
 
24
- require 'fakeweb'
25
- FakeWeb.register_uri(:get, 'http://localhost:2812/', :body => File.read('test/fixtures/status.xml') ); nil
34
+ In case you don't have a running _Monit_ at hand, use the provided _FakeWeb_ setup:
26
35
 
27
- Now, retrieve information from the cluster:
36
+ require 'fakeweb'
37
+ FakeWeb.register_uri(:get, 'http://localhost:2812/_status?format=xml', :body => File.read('test/fixtures/status.xml') ); nil
28
38
 
29
39
  cluster = Monittr::Cluster.new ['http://localhost:2812/']
40
+
41
+ Now, you can display the information from the cluster:
42
+
30
43
  cluster.servers.size
31
44
 
32
45
  server = cluster.servers.first
@@ -42,17 +55,19 @@ Now, retrieve information from the cluster:
42
55
 
43
56
  ...
44
57
 
45
- You can also check out the HTML output by running the example application:
58
+ You can also check out the HTML display by running the example application:
46
59
 
47
60
  $ ruby examples/application.rb
48
61
  $ open http://localhost:4567/
49
62
 
50
63
  You should see the information about two faked Monit instances in your browser.
51
64
 
52
- Provide the URLs to _Monit_ instances by setting the appropriate option:
65
+ Provide the URLs to live _Monit_ instances by setting the appropriate option in `application.rb`:
53
66
 
54
67
  set :monit_urls, %w[ http://production.example.com:2812 http://staging.example.com:2812 ]
55
68
 
69
+ You may also need to comment out the _FakeWeb_ section, if you're passing `localhost` URLs.
70
+
56
71
 
57
72
  ## Customization ##
58
73
 
@@ -62,7 +77,7 @@ It's easy to customize the HTML output by setting the appropriate options in you
62
77
  set :template, Proc.new { File.join(root, 'template.erb') }
63
78
  set :stylesheet, '/path/to/my/stylesheet'
64
79
 
65
- Please see the example application for more.
80
+ Please see the example application for prepared examples.
66
81
 
67
82
 
68
83
  ## Installation ##
@@ -78,9 +93,11 @@ Stable versions of the gem can be installed from _Rubygems_:
78
93
  $ gem install monittr
79
94
 
80
95
 
81
- ## Other Information ##
96
+ ## Other ##
97
+
98
+ The code is useful for the intended purpose as it is, but if you've got any feedback, suggestions or patches, please send me an e-mail or use _Github_ Issues/Pull Requests.
82
99
 
83
- See the [_monit_](https://github.com/k33l0r/monit) gem for another Ruby interface to _Monit_.
100
+ Check out the [_monit_](https://github.com/k33l0r/monit) gem for another Ruby interface to _Monit_.
84
101
 
85
102
  -----
86
103
 
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new(:test) do |test|
8
+ test.libs << 'lib' << 'test'
9
+ test.pattern = 'test/**/*_test.rb'
10
+ test.verbose = true
11
+ end
@@ -7,17 +7,29 @@ require 'fakeweb'
7
7
 
8
8
  require 'monittr/sinatra/monittr'
9
9
 
10
- FakeWeb.register_uri(:get, 'http://localhost:2812/_status?format=xml', :body => File.read( File.expand_path('../../test/fixtures/status.xml', __FILE__)))
10
+ # --- Comment these lines to enable loading data from http://localhost:2812 ---
11
+ FakeWeb.register_uri(:get, 'http://localhost:2812/_status?format=xml',
12
+ :body => File.read( File.expand_path('../../test/fixtures/status.xml', __FILE__)))
13
+ # -----------------------------------------------------------------------------
11
14
 
15
+ # --- Set URLs to your Monit instances here -----------------------------------
12
16
  set :monit_urls, %w[ http://localhost:2812 http://localhost:2812 ]
17
+ # -----------------------------------------------------------------------------
13
18
 
19
+ # --- Use your own template ---------------------------------------------------
14
20
  # set :template, Proc.new { File.join(root, 'template.erb') }
21
+ # -----------------------------------------------------------------------------
22
+
23
+ # --- Use your own stylesheet for the `stylesheet` helper ---------------------
15
24
  # set :stylesheet, '/path/to/my/stylesheet'
25
+ # -----------------------------------------------------------------------------
26
+
16
27
 
17
28
  get "/" do
18
29
  erb :index
19
30
  end
20
31
 
32
+
21
33
  __END__
22
34
 
23
35
  @@ layout
@@ -28,7 +40,8 @@ __END__
28
40
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
29
41
  <style>
30
42
  body { color: #222; font-family: sans-serif; margin: 2em; }
31
- #example { border: 4px solid #ccc; padding: 1em; }
43
+ p { margin: 0 0 0.5em 0; }
44
+ #example { border: 4px solid #ccc; padding: 1em; margin: 1em 0 1em 0; }
32
45
  </style>
33
46
  </head>
34
47
  <body>
@@ -1,20 +1,30 @@
1
- <h1>A Customized template for <em>Monittr</em></h1>
1
+ <style>
2
+ body { color: #222; font-size: 85%; }
3
+ a { color: #222; }
4
+ h1 { font-size: 18px; }
5
+ h2 { font-size: 16px; margin: 1em 0 .25em 0; }
6
+ h3 { font-size: 14px; margin: .25em 0 .25em 0; }
7
+ ul { margin: 0 0 0 1.2em; padding: 0; list-style-type: square; }
8
+ </style>
2
9
 
3
- <p>You can customize the template as you wish,
4
- just set the path to it with something like this in your application:</p>
5
-
6
- <pre>set :template, Proc.new { File.join(root, 'template.erb') }</pre>
10
+ <h1>A Customized Template for <em>Monittr</em></h1>
7
11
 
8
12
  <hr>
9
13
 
10
- <% cluster.servers.each do |server| %>
11
- <h2>Server: <em><%= server.system.name %></em> // status: <%= server.system.status %></h2>
14
+ <% server = cluster.servers.first %>
12
15
 
13
- <h3>Processes</h3>
14
- <ul>
15
- <% server.processes.each do |process| %>
16
- <li><%= process.name %></li>
17
- <% end %>
18
- </ul>
16
+ <h2>
17
+ Server: <em><a href="<%= server.url %>"><%= server.system.name %></a></em>
18
+ // status: <%= server.system.status == 0 ? 'running' : 'not running' %> and
19
+ <%= server.system.monitored == 1 ? 'monitored' : '<b>not</b> monitored' %>
20
+ </h2>
19
21
 
20
- <% end %>
22
+ <ul>
23
+ <% server.processes.each do |process| %>
24
+ <li>
25
+ <%= process.name %>
26
+ <em><%= process.status == 0 ? 'running' : 'stopped' %> and <%= process.monitored == 1 ? 'monitored' : '<b>not</b> monitored' %></em>
27
+ <small>(CPU: <%= process.cpu || 'N/A' %>%, MEM: <%= process.memory || 'N/A' %>%)</small>
28
+ </li>
29
+ <% end %>
30
+ </ul>
@@ -6,7 +6,6 @@
6
6
 
7
7
  #monittr .rounded
8
8
  { -moz-border-radius: 0.5em;
9
- -webkit-border-radius: 0.5em;
10
9
  border-radius: 0.5em }
11
10
 
12
11
  #monittr a
@@ -29,7 +28,6 @@
29
28
  display: block;
30
29
  float: left;
31
30
  -moz-border-radius: 6px;
32
- -webkit-border-radius: 6px;
33
31
  border-radius: 6px; }
34
32
  #monittr .dot.running
35
33
  { background-color: green; }
@@ -42,13 +40,14 @@
42
40
  { color: #222;
43
41
  background-color: #F8F8F8;
44
42
  margin: 0.2em 0 0 0;
45
- border: 1px solid #ccc; }
43
+ border: 1px solid #ccc;
44
+ border-top: none; }
46
45
 
47
46
  #monittr .server h2
48
47
  { font-size: 14px;
49
48
  font-weight: normal;
50
49
  background-color: #ccc;
51
- padding: 0.5em 0.5em 0.4em 0.5em;
50
+ padding: 0.6em 0.5em 0.4em 1em;
52
51
  margin: 0; }
53
52
  #monittr .server.running h2
54
53
  { background-color: #66E98A; }
@@ -57,14 +56,14 @@
57
56
  background-color: #CC033E; }
58
57
  #monittr .server.failure h2 *
59
58
  { color: #fff !important; }
59
+ #monittr .server h2 a
60
+ { margin-left: 0.25em; }
60
61
 
61
62
  #monittr .server.expanded h2
62
63
  { -moz-border-radius-bottomleft: 0;
63
64
  -moz-border-radius-bottomright: 0;
64
- -webkit-border-radius-bottomleft: 0;
65
- -webkit-border-radius-bottomright: 0
66
- border-radius-bottomleft: 0;
67
- border-radius-bottomright: 0; }
65
+ border-bottom-left-radius: 0;
66
+ border-bottom-right-radius: 0; }
68
67
 
69
68
  #monittr .server h2 small
70
69
  { font-size: 75%;
@@ -124,7 +123,6 @@
124
123
  font-weight: normal;
125
124
  padding: 0.25em 0.5em 0.15em 0.5em;
126
125
  -moz-border-radius: 0.5em;
127
- -webkit-border-radius: 0.5em;
128
126
  border-radius: 0.5em; }
129
127
 
130
128
  #monittr .server .segment strong .label.running
@@ -132,4 +130,4 @@
132
130
  #monittr .server .segment strong .label.warning
133
131
  { background-color: orange; }
134
132
  #monittr .server .segment strong .label.failure
135
- { background-color: red; }
133
+ { background-color: red; }
@@ -9,8 +9,8 @@
9
9
  <div class="server rounded">
10
10
  <h2 class="rounded">
11
11
  <strong>
12
- <span class="dot status <%= server.system.status == 0 ? 'running' : 'failure' %>">&middot;</span>
13
- <span class="dot monitored <%= server.system.monitored == 1 ? 'running' : 'failure' %>">&middot;</span>
12
+ <span title="status" class="dot status <%= server.system.status == 0 ? 'running' : 'failure' %>">&middot;</span>
13
+ <span title="monitored" class="dot monitored <%= server.system.monitored == 1 ? 'running' : 'failure' %>">&middot;</span>
14
14
  <a href="<%= server.url %>"><%= server.system.name %></a>
15
15
  <%= "<em>#{server.system.message}</em>" if server.system.message %>
16
16
  </strong>
@@ -79,17 +79,25 @@
79
79
  $(function() {
80
80
  $('#monittr .server .content').hide();
81
81
 
82
- $('#monittr .server h2').click(function() {
83
- $(this).parent().toggleClass('expanded').find('.content').toggle('fast', function() { });
82
+ $('#monittr .server').bind('expand', function() {
83
+ $(this).addClass('expanded').find('.content').show('fast', function() { });
84
84
  });
85
+ $('#monittr .server').bind('collapse', function() {
86
+ $(this).removeClass('expanded').find('.content').hide('fast', function() { });
87
+ });
88
+
89
+ $('#monittr .server h2').toggle(
90
+ function() { $(this).parent().trigger('expand') },
91
+ function() { $(this).parent().trigger('collapse') }
92
+ );
85
93
 
86
94
  $('#toggle').toggle(
87
95
  function() {
88
- $('#monittr .server .content').show('fast');
96
+ $('#monittr .server').trigger('expand');
89
97
  $(this).html('- Collapse all');
90
98
  },
91
99
  function() {
92
- $('#monittr .server .content').hide('fast');
100
+ $('#monittr .server').trigger('collapse');
93
101
  $(this).html('+ Expand all');
94
102
  }
95
103
  );
@@ -1,3 +1,3 @@
1
1
  module Monittr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,7 @@
7
7
  <uptime>937661</uptime>
8
8
  <poll>10</poll>
9
9
  <startdelay>0</startdelay>
10
- <localhostname>myapplication.cz</localhostname>
10
+ <localhostname>application.com</localhostname>
11
11
  <controlfile>/usr/local/etc/monitrc</controlfile>
12
12
  <httpd>
13
13
  <address/>
@@ -459,56 +459,6 @@
459
459
  <percenttotal>0.0</percenttotal>
460
460
  </cpu>
461
461
  </service>
462
- <service type="3">
463
- <collected_sec>1290526733</collected_sec>
464
- <collected_usec>939824</collected_usec>
465
- <name>scheduler_workers</name>
466
- <status>0</status>
467
- <status_hint>0</status_hint>
468
- <monitor>1</monitor>
469
- <monitormode>0</monitormode>
470
- <pendingaction>0</pendingaction>
471
- <groups/>
472
- <pid>12870</pid>
473
- <ppid>12869</ppid>
474
- <uptime>656652</uptime>
475
- <children>1</children>
476
- <memory>
477
- <percent>0.6</percent>
478
- <percenttotal>1.3</percenttotal>
479
- <kilobyte>56596</kilobyte>
480
- <kilobytetotal>116260</kilobytetotal>
481
- </memory>
482
- <cpu>
483
- <percent>0.0</percent>
484
- <percenttotal>0.0</percenttotal>
485
- </cpu>
486
- </service>
487
- <service type="3">
488
- <collected_sec>1290526733</collected_sec>
489
- <collected_usec>939890</collected_usec>
490
- <name>scheduler</name>
491
- <status>0</status>
492
- <status_hint>0</status_hint>
493
- <monitor>1</monitor>
494
- <monitormode>0</monitormode>
495
- <pendingaction>0</pendingaction>
496
- <groups/>
497
- <pid>12681</pid>
498
- <ppid>1</ppid>
499
- <uptime>656765</uptime>
500
- <children>0</children>
501
- <memory>
502
- <percent>0.7</percent>
503
- <percenttotal>0.7</percenttotal>
504
- <kilobyte>66200</kilobyte>
505
- <kilobytetotal>66200</kilobytetotal>
506
- </memory>
507
- <cpu>
508
- <percent>0.2</percent>
509
- <percenttotal>0.2</percenttotal>
510
- </cpu>
511
- </service>
512
462
  <service type="3">
513
463
  <collected_sec>1290526733</collected_sec>
514
464
  <collected_usec>939892</collected_usec>
@@ -523,7 +473,7 @@
523
473
  <service type="5">
524
474
  <collected_sec>1290526733</collected_sec>
525
475
  <collected_usec>939894</collected_usec>
526
- <name>myapplication.cz</name>
476
+ <name>application.com</name>
527
477
  <status>0</status>
528
478
  <status_hint>0</status_hint>
529
479
  <monitor>1</monitor>
@@ -65,7 +65,7 @@ module Monittr
65
65
  assert_not_nil @server.system
66
66
  assert_equal 0, @server.system.status
67
67
  assert_equal 1, @server.system.monitored
68
- assert_equal 'myapplication.cz', @server.system.name
68
+ assert_equal 'application.com', @server.system.name
69
69
  assert_equal 5.28, @server.system.load
70
70
  assert_equal 0, @server.system.status
71
71
  assert_equal 937661, @server.system.uptime
@@ -84,7 +84,7 @@ module Monittr
84
84
 
85
85
  should "return processes info" do
86
86
  assert_not_nil @server.processes
87
- assert_equal 15, @server.processes.size
87
+ assert_equal 13, @server.processes.size
88
88
 
89
89
  thin = @server.processes.first
90
90
  assert_not_nil thin
@@ -23,7 +23,7 @@ class SinatraHelperTest < Test::Unit::TestCase
23
23
  get '/'
24
24
 
25
25
  assert last_response.ok?
26
- assert last_response.body.include?('myapplication.cz'), "Response body should contain: myapplication.cz"
26
+ assert last_response.body.include?('application.com'), "Response body should contain: application.com"
27
27
  assert last_response.body.include?('thin_1'), "Response body should contain: thin_1"
28
28
  end
29
29
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Karel Minarik
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-25 00:00:00 +01:00
17
+ date: 2010-11-28 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -103,7 +103,7 @@ dependencies:
103
103
  version: "0"
104
104
  type: :development
105
105
  version_requirements: *id007
106
- description: " Monittr provides a Ruby interface for displaying Monit statistics\n in Sinatra based web applications.\n\n It loads information from the web server embedded in Monit and\n makes it accessible as Ruby objects.\n\n It also displays the information in HTML with the provided helpers.\n"
106
+ description: " Monittr provides a Ruby interface for loading and displaying statistics\n from multiple Monit instances and helpers for Sinatra web applications.\n"
107
107
  email: karmi@karmi.cz
108
108
  executables: []
109
109
 
@@ -159,6 +159,6 @@ rubyforge_project:
159
159
  rubygems_version: 1.3.6
160
160
  signing_key:
161
161
  specification_version: 3
162
- summary: Web interface for Monit statistics
162
+ summary: A Ruby and web interface for Monit statistics
163
163
  test_files: []
164
164