rails_monitor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/app/views/rails_monitor/status.html.haml +38 -0
- data/lib/rails_monitor/version.rb +3 -0
- data/lib/rails_monitor.rb +60 -0
- data/rails_monitor.gemspec +25 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kevin Radloff <radsaq@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# RailsMonitor
|
2
|
+
|
3
|
+
This gem allows a rails application developer to simply and easily create an
|
4
|
+
application status page with a set of app checks that can double as monitoring
|
5
|
+
endpoints for nagios or other systems.
|
6
|
+
|
7
|
+
This gem has been developed with the generous support of [LightCastle Technical
|
8
|
+
Consulting](http://www.lightcastletech.com/).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'rails_monitor'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install rails_monitor
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Include the monitoring mixin in your controller:
|
27
|
+
|
28
|
+
include RailsMonitor::Monitoring
|
29
|
+
|
30
|
+
Define one or more tabs of status checks:
|
31
|
+
|
32
|
+
status_tab :database, [:mysql_is_connected]
|
33
|
+
|
34
|
+
Define the accompanying endpoints:
|
35
|
+
|
36
|
+
boolean_status :mysql_is_connected do
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
If your application is using jquery and bootstrap, this is all you should need
|
41
|
+
to do.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
.container
|
2
|
+
.row
|
3
|
+
#status_container.settings.span12
|
4
|
+
.row
|
5
|
+
#status_list.span10.offset1.content
|
6
|
+
%h2 Site Status
|
7
|
+
|
8
|
+
%ul.nav.nav-tabs{'data-tabs' => 'tabs'}
|
9
|
+
- first = true
|
10
|
+
- @statuses.each_key do |category|
|
11
|
+
%li{:class => (first ? 'active' : nil)}
|
12
|
+
= link_to(category.to_s.humanize, {:anchor => category}, {'data-toggle' => 'tab'})
|
13
|
+
- first = false
|
14
|
+
|
15
|
+
.tab-content
|
16
|
+
- first = true
|
17
|
+
- @statuses.each do |category, names|
|
18
|
+
.tab-pane{:id => category, :class => (first ? 'active' : nil)}
|
19
|
+
- names.each do |name|
|
20
|
+
.status_wrapper
|
21
|
+
= name.to_s.humanize
|
22
|
+
.status{:id => "status_#{name}", 'data-name' => name}
|
23
|
+
%pre
|
24
|
+
- first = false
|
25
|
+
|
26
|
+
:javascript
|
27
|
+
var updateStatuses = function() {
|
28
|
+
jQuery.each($('.status'), function(ii, status) {
|
29
|
+
var name = $(status).data('name');
|
30
|
+
var elem = $(status).find('pre');
|
31
|
+
elem.html("Loading...");
|
32
|
+
jQuery.ajax(document.location.pathname + "/" + name, {timeout: 10000}).done(function(text) {
|
33
|
+
elem.html(text);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
setTimeout(updateStatuses, 10000);
|
37
|
+
};
|
38
|
+
updateStatuses();
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rails_monitor/version'
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module RailsMonitor
|
5
|
+
module Monitoring
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
prepend_view_path(File.join(File.dirname(__FILE__), '..', 'app', 'views'))
|
10
|
+
@@statuses ||= {}
|
11
|
+
cattr_reader :statuses
|
12
|
+
end
|
13
|
+
|
14
|
+
def index
|
15
|
+
@statuses = self.statuses
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
format.html do
|
19
|
+
render 'rails_monitor/status'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def status_tab(anchor, statuses_to_show = [])
|
26
|
+
self.statuses[anchor] = statuses_to_show
|
27
|
+
end
|
28
|
+
|
29
|
+
def boolean_status(name)
|
30
|
+
raise ArgumentError('No block given') unless block_given?
|
31
|
+
|
32
|
+
define_method(name) do
|
33
|
+
result = yield
|
34
|
+
|
35
|
+
if result
|
36
|
+
render :text => "OK: #{result}"
|
37
|
+
else
|
38
|
+
render :text => "ERROR: #{result}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def numeric_status(name, warn_threshold = nil, error_threshold = nil)
|
44
|
+
raise ArgumentError('No block given') unless block_given?
|
45
|
+
|
46
|
+
define_method(name) do
|
47
|
+
result = yield.to_i
|
48
|
+
|
49
|
+
if error_threshold && result >= error_threshold
|
50
|
+
render :text => "ERROR: #{result}"
|
51
|
+
elsif warn_threshold && result >= warn_threshold
|
52
|
+
render :text => "WARN: #{result}"
|
53
|
+
else
|
54
|
+
render :text => "OK: #{result}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_monitor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_monitor"
|
8
|
+
spec.version = RailsMonitor::VERSION
|
9
|
+
spec.authors = ["Kevin Radloff"]
|
10
|
+
spec.email = ["radsaq@gmail.com"]
|
11
|
+
spec.description = %q{Easily monitor your rails application}
|
12
|
+
spec.summary = %q{Easily monitor your rails application from a convenient web page, or define endpoints for 3rd party software like nagios.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'actionpack', '>= 3.1.0'
|
22
|
+
spec.add_dependency 'jquery-rails'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Radloff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jquery-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Easily monitor your rails application
|
79
|
+
email:
|
80
|
+
- radsaq@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- app/views/rails_monitor/status.html.haml
|
91
|
+
- lib/rails_monitor.rb
|
92
|
+
- lib/rails_monitor/version.rb
|
93
|
+
- rails_monitor.gemspec
|
94
|
+
homepage: ''
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.25
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Easily monitor your rails application from a convenient web page, or define
|
119
|
+
endpoints for 3rd party software like nagios.
|
120
|
+
test_files: []
|