easymon 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of easymon might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +231 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/easymon/application.js +15 -0
- data/app/assets/javascripts/easymon/checks.js +2 -0
- data/app/assets/stylesheets/easymon/application.css +13 -0
- data/app/assets/stylesheets/easymon/checks.css +4 -0
- data/app/controllers/easymon/application_controller.rb +4 -0
- data/app/controllers/easymon/checks_controller.rb +55 -0
- data/app/helpers/easymon/application_helper.rb +4 -0
- data/app/helpers/easymon/checks_helper.rb +4 -0
- data/app/views/layouts/easymon/application.html.erb +14 -0
- data/config/routes.rb +6 -0
- data/lib/easymon.rb +64 -0
- data/lib/easymon/checklist.rb +57 -0
- data/lib/easymon/checks/active_record_check.rb +26 -0
- data/lib/easymon/checks/http_check.rb +29 -0
- data/lib/easymon/checks/memcached_check.rb +27 -0
- data/lib/easymon/checks/redis_check.rb +31 -0
- data/lib/easymon/checks/semaphore_check.rb +26 -0
- data/lib/easymon/checks/split_active_record_check.rb +55 -0
- data/lib/easymon/checks/traffic_enabled_check.rb +13 -0
- data/lib/easymon/engine.rb +8 -0
- data/lib/easymon/repository.rb +46 -0
- data/lib/easymon/result.rb +32 -0
- data/lib/easymon/testing.rb +15 -0
- data/lib/easymon/version.rb +3 -0
- data/lib/tasks/easymon_tasks.rake +4 -0
- data/test/controllers/easymon/checks_controller_test.rb +61 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/easymon.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/easymon.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/easymon_controller.rb +7 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/easymon_helper.rb +2 -0
- data/test/dummy/app/views/easymon/index.html.erb +2 -0
- data/test/dummy/app/views/easymon/show.html.erb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +34 -0
- data/test/dummy/config/elasticsearch.yml +2 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +39 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +41 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/easymon.rb +6 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/memcached.yml +6 -0
- data/test/dummy/config/redis.yml +11 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/helpers/easymon/checks_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +33 -0
- data/test/unit/checklist_test.rb +71 -0
- data/test/unit/checks/active_record_check_test.rb +33 -0
- data/test/unit/checks/http_check_test.rb +36 -0
- data/test/unit/checks/memcached_check_test.rb +39 -0
- data/test/unit/checks/redis_check_test.rb +35 -0
- data/test/unit/checks/semaphore_check_test.rb +20 -0
- data/test/unit/checks/split_active_record_check_test.rb +70 -0
- data/test/unit/checks/traffic_enabled_check_test.rb +21 -0
- data/test/unit/repository_test.rb +58 -0
- metadata +273 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 70386bd8a4b34143d2913095deb4d60ef7f28f0c
|
4
|
+
data.tar.gz: a36cad6c25360f27cb0d7f10ca81eccaeecb1899
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7995dc4767abbf2dc5a4e124dcbf2be22b6bfc3957654352622b9faffc5e1af4446c7f4b3a3ef112a3115b9c1a7270eb71ba5df586d94c7065b9da2bbe4021b
|
7
|
+
data.tar.gz: 35afc40c57ff4304f0e8217e49b0b49ee5752e1762658ff95e147b7fab260a4905bb7331572e07cce1e78d2c2bfa20a1b0b21fd21cd33c26a7bcae7f1481c8a8
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 37signals
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
# Easymon
|
2
|
+
|
3
|
+
Easymon helps you monitor your application's availability. It provides a simple
|
4
|
+
way to test the availability of resources your application needs, like the
|
5
|
+
application database, a memcached connection, or a redis instance. These test
|
6
|
+
results can be used by a load balancer to determine the general health and
|
7
|
+
viability of the node your application is running on.
|
8
|
+
|
9
|
+
It's packaged up as a rails engine for 3.1 and greater, and a plugin for 2.3 -
|
10
|
+
3.0.
|
11
|
+
|
12
|
+
## History
|
13
|
+
|
14
|
+
This gem extracts and modularizes the logic we had in our monitoring controllers
|
15
|
+
and were copying back and forth between applications.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add to Gemfile and bundle!:
|
20
|
+
|
21
|
+
````ruby
|
22
|
+
gem 'easymon'
|
23
|
+
````
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
To get started, you'll need to add an initializer for this to do anything.
|
27
|
+
In `config/initializers/easymon.rb`:
|
28
|
+
|
29
|
+
````ruby
|
30
|
+
Easymon::Repository.add("application-database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
|
31
|
+
````
|
32
|
+
|
33
|
+
This will register a check called `application-database` for use.
|
34
|
+
|
35
|
+
Next, we need to add the routes to your application. Depending on the rails
|
36
|
+
version, this is done one of two ways:
|
37
|
+
|
38
|
+
### Rails 2.3.x & 3.0
|
39
|
+
Add `Easymon.routes(map)` to your `config/routes.rb`. This will put the Easymon
|
40
|
+
routes under `/up`. If you want Easymon mounted somewhere other than `/up`, use
|
41
|
+
`Easymon.routes(map, "/monitoring")`. That would put the Easymon paths under
|
42
|
+
`/monitoring`. For Rails 3.0, the default routes file does not provide `map`,
|
43
|
+
so use `Easymon.routes(self)` instead.
|
44
|
+
|
45
|
+
### Rails 3.1+
|
46
|
+
Rails 3.1+ gives us mountable engines, so use the standard syntax, adding
|
47
|
+
`mount Easymon::Engine => "/up"` to your `config/routes.rb`.
|
48
|
+
|
49
|
+
|
50
|
+
Now, you can run your entire checklist by visiting `/up`, or wherever you have
|
51
|
+
mounted the application. If you want to just test the single check, go to
|
52
|
+
`/up/application-database`, and only the check named `application-database` will
|
53
|
+
be run.
|
54
|
+
|
55
|
+
### Critical Checks
|
56
|
+
If you have several services that are critical to your app, and others that
|
57
|
+
are not, you can segregate those for health check purposes if you wish.
|
58
|
+
Assuming your database and redis are critical, but memcached is not, again in
|
59
|
+
`config/initializers/easymon.rb`:
|
60
|
+
|
61
|
+
````ruby
|
62
|
+
Easymon::Repository.add(
|
63
|
+
"application-database",
|
64
|
+
Easymon::ActiveRecordCheck.new(ActiveRecord::Base),
|
65
|
+
:critical
|
66
|
+
)
|
67
|
+
Easymon::Repository.add(
|
68
|
+
"redis",
|
69
|
+
Easymon::RedisCheck.new(
|
70
|
+
YAML.load_file(
|
71
|
+
Rails.root.join("config/redis.yml")
|
72
|
+
)[Rails.env].symbolize_keys
|
73
|
+
),
|
74
|
+
:critical
|
75
|
+
)
|
76
|
+
Easymon::Repository.add(
|
77
|
+
"memcached",
|
78
|
+
Easymon::MemcachedCheck.new(Rails.cache)
|
79
|
+
)
|
80
|
+
````
|
81
|
+
|
82
|
+
In addition to the main route `/up`, this will register four checks,
|
83
|
+
individually available at:
|
84
|
+
|
85
|
+
* `/up/application-database`
|
86
|
+
* `/up/redis`
|
87
|
+
* `/up/memcached`
|
88
|
+
* `/up/critical` - Runs both the application-database and redis checks.
|
89
|
+
|
90
|
+
## Included Checks
|
91
|
+
|
92
|
+
* ActiveRecord
|
93
|
+
* Redis
|
94
|
+
* Memcached
|
95
|
+
* Semaphore
|
96
|
+
* Traffic Enabled
|
97
|
+
* Split ActiveRecord
|
98
|
+
* Http
|
99
|
+
|
100
|
+
### ActiveRecord
|
101
|
+
`Easymon::ActiveRecordCheck` is a basic check that uses ActiveRecord to check
|
102
|
+
the availability of your main database. It's usually invoked as such:
|
103
|
+
|
104
|
+
````ruby
|
105
|
+
Easymon::ActiveRecordCheck.new(ActiveRecord::Base)
|
106
|
+
````
|
107
|
+
|
108
|
+
Internally, it compares `1 == klass.connection.select_value("SELECT 1=1").to_i`
|
109
|
+
where klass is whatever class you passed to the check. Usually this will be
|
110
|
+
ActiveRecord::Base, but feel free to go crazy.
|
111
|
+
|
112
|
+
### Redis
|
113
|
+
`Easymon::RedisCheck` will check the availability of a Redis server, given an
|
114
|
+
appropriate config hash. Typically, we'll read the config off disk, but as long
|
115
|
+
as you get a valid config hash, this will work:
|
116
|
+
|
117
|
+
````ruby
|
118
|
+
Easymon::RedisCheck.new(
|
119
|
+
YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys
|
120
|
+
)
|
121
|
+
````
|
122
|
+
|
123
|
+
This is the most visually complex test to instantiate, but it's only because
|
124
|
+
we're loading the config from disk and getting the config block that matches
|
125
|
+
the Rails.env in one line. As long as you pass a hash that can be used by
|
126
|
+
Redis.new.
|
127
|
+
|
128
|
+
### Memcached
|
129
|
+
`Easymon::MemcachedCheck` is a basic check that will write and then read a key
|
130
|
+
from the cache. It expects a cache instance to check, so it could be as easy
|
131
|
+
as:
|
132
|
+
|
133
|
+
````ruby
|
134
|
+
Easymon::MemcachedCheck.new(Rails.cache)
|
135
|
+
````
|
136
|
+
|
137
|
+
### Semaphore
|
138
|
+
`Easymon::Semaphore` checks for the presence of a file on disk relative to the
|
139
|
+
Rails.root of the current application.
|
140
|
+
|
141
|
+
````ruby
|
142
|
+
check = Easymon::SemaphoreCheck.new("config/redis.yml")
|
143
|
+
````
|
144
|
+
|
145
|
+
This is mainly a check that gets subclassed by the next check.
|
146
|
+
|
147
|
+
###Traffic Enabled
|
148
|
+
`Easymon::TrafficEnabledCheck` is fairly specific, but when we want a server to
|
149
|
+
accept traffic, we can place a file in the Rails.root, and the load balancers
|
150
|
+
can use the result of this check to help decide whether or not to send traffic
|
151
|
+
to the node.
|
152
|
+
|
153
|
+
````ruby
|
154
|
+
Easymon::TrafficEnabledCheck.new("enable-traffic")
|
155
|
+
````
|
156
|
+
|
157
|
+
###Split ActiveRecord
|
158
|
+
`Easymon::SplitActiveRecordCheck` is the most complicated check, as it's not
|
159
|
+
something you can use out of the gate. Here we pass a block so we get a fresh
|
160
|
+
instance of `ActiveRecord::Base` or whatever other class we might be using to
|
161
|
+
make a secondary database connection.
|
162
|
+
|
163
|
+
For example, given the following other class:
|
164
|
+
|
165
|
+
````ruby
|
166
|
+
module Easymon
|
167
|
+
class Base < ActiveRecord::Base
|
168
|
+
def establish_connection(spec = nil)
|
169
|
+
if spec
|
170
|
+
super
|
171
|
+
elsif config = Easymon.database_configuration
|
172
|
+
super config
|
173
|
+
end
|
174
|
+
end
|
175
|
+
def database_configuration
|
176
|
+
env = "#{Rails.env}_slave"
|
177
|
+
config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
````
|
182
|
+
|
183
|
+
We would check both it and `ActiveRecord::Base` like so:
|
184
|
+
|
185
|
+
````ruby
|
186
|
+
check = Easymon::SplitActiveRecordCheck.new {
|
187
|
+
[ActiveRecord::Base.connection, Easymon::Base.connection]
|
188
|
+
}
|
189
|
+
Easymon::Repository.add("split-database", check)
|
190
|
+
````
|
191
|
+
|
192
|
+
### Http
|
193
|
+
`Easymon::HttpCheck` will check the return status of a HEAD request to a URL.
|
194
|
+
Great for checking service endpoint availability! The following will make a
|
195
|
+
request to port 9200 on localhost, which is where you might have Elasticsearch
|
196
|
+
running:
|
197
|
+
|
198
|
+
````ruby
|
199
|
+
Easymon::HttpCheck.new("http://localhost:9200")
|
200
|
+
````
|
201
|
+
|
202
|
+
Typically, we'll read an elasticsearch config off disk, and use the URL like so:
|
203
|
+
|
204
|
+
````ruby
|
205
|
+
config = YAML.load_file(Rails.root.join("config/elasticsearch.yml"))[Rails.env].symbolize_keys
|
206
|
+
Easymon::HttpCheck.new(config[:url])
|
207
|
+
````
|
208
|
+
|
209
|
+
## How to contribute
|
210
|
+
|
211
|
+
Here's the most direct way to get your work merged into the project:
|
212
|
+
|
213
|
+
1. Fork the project
|
214
|
+
2. Clone down your fork
|
215
|
+
3. Create a feature branch
|
216
|
+
4. Add your feature + tests
|
217
|
+
5. Document new features in the README
|
218
|
+
6. Make sure everything still passes by running the tests
|
219
|
+
7. If necessary, rebase your commits into logical chunks, without errors
|
220
|
+
8. Push the branch up
|
221
|
+
9. Send a pull request for your branch
|
222
|
+
|
223
|
+
If you're going to make a major change ask first to maje sure it's in line with
|
224
|
+
the project goals.
|
225
|
+
|
226
|
+
## Authors
|
227
|
+
|
228
|
+
* [Nathan Anderson](mailto:andnat@gmail.com)
|
229
|
+
|
230
|
+
## License
|
231
|
+
See [LICENSE](LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Easymon'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_dependency "easymon/application_controller"
|
2
|
+
|
3
|
+
module Easymon
|
4
|
+
class ChecksController < ApplicationController
|
5
|
+
rescue_from Easymon::NoSuchCheck do |e|
|
6
|
+
respond_to do |format|
|
7
|
+
format.any(:text, :html) { render :text => e.message, :status => :not_found }
|
8
|
+
format.json { render :json => e.message, :status => :not_found }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
checklist = Easymon::Repository.all
|
14
|
+
checklist.check
|
15
|
+
|
16
|
+
message = "No Checks Defined"
|
17
|
+
|
18
|
+
response_status = checklist.response_status
|
19
|
+
message = checklist.to_s unless checklist.empty?
|
20
|
+
|
21
|
+
unless checklist.empty?
|
22
|
+
# override response_status if we have a "critical" checklist
|
23
|
+
if checklist.include?("critical")
|
24
|
+
critical_checklist = checklist.fetch("critical")
|
25
|
+
response_status = critical_checklist.response_status
|
26
|
+
message = add_prefix(critical_checklist.success?, message)
|
27
|
+
else
|
28
|
+
message = add_prefix(checklist.success?, message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
format.any(:text, :html) { render :text => message, :status => response_status }
|
34
|
+
format.json { render :json => checklist, :status => response_status }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def show
|
39
|
+
check = Easymon::Repository.fetch(params[:check])
|
40
|
+
result = Easymon::Result.new(check.check)
|
41
|
+
|
42
|
+
message = "#{params[:check]}: #{result.message}"
|
43
|
+
|
44
|
+
respond_to do |format|
|
45
|
+
format.any(:text, :html) { render :text => result.message, :status => result.response_status }
|
46
|
+
format.json { render :json => message, :status => result.response_status }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def add_prefix(result, message)
|
52
|
+
result ? "OK #{message}" : "DOWN #{message}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Easymon</title>
|
5
|
+
<%= stylesheet_link_tag "easymon/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "easymon/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/easymon.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new("3.0")
|
2
|
+
require "easymon/engine"
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
require "easymon/checklist"
|
7
|
+
require "easymon/repository"
|
8
|
+
require "easymon/result"
|
9
|
+
|
10
|
+
require "easymon/checks/active_record_check"
|
11
|
+
require "easymon/checks/split_active_record_check"
|
12
|
+
require "easymon/checks/redis_check"
|
13
|
+
require "easymon/checks/memcached_check"
|
14
|
+
require "easymon/checks/semaphore_check"
|
15
|
+
require "easymon/checks/traffic_enabled_check"
|
16
|
+
require "easymon/checks/http_check"
|
17
|
+
require "easymon/testing"
|
18
|
+
|
19
|
+
module Easymon
|
20
|
+
NoSuchCheck = Class.new(StandardError)
|
21
|
+
|
22
|
+
def self.rails_version
|
23
|
+
Gem::Version.new(Rails.version)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.rails2?
|
27
|
+
Easymon.rails_version.between?(Gem::Version.new("2.3"), Gem::Version.new("3.0"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.rails30?
|
31
|
+
Easymon.rails_version.between?(Gem::Version.new("3.0"), Gem::Version.new("3.1"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.mountable_engine?
|
35
|
+
Easymon.rails_version > Gem::Version.new("3.1")
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.routes(mapper, path = "/up")
|
39
|
+
if Easymon.rails2?
|
40
|
+
# Rails 2.3.x (anything less than 3, really)
|
41
|
+
$:.unshift File.expand_path(File.join(
|
42
|
+
File.dirname(__FILE__),
|
43
|
+
"..","app","controllers"))
|
44
|
+
require 'easymon/checks_controller'
|
45
|
+
|
46
|
+
mapper.instance_eval do
|
47
|
+
connect "#{path}", :controller => "easymon/checks", :action => "index"
|
48
|
+
connect "#{path}/:check", :controller => "easymon/checks", :action => "show"
|
49
|
+
end
|
50
|
+
elsif Easymon.rails30?
|
51
|
+
# Greater than 3.0, but less than 3.1
|
52
|
+
mapper.instance_eval do
|
53
|
+
get "#{path}" => 'easymon/checks#index'
|
54
|
+
get "#{path}/:check" => 'easymon/checks#show'
|
55
|
+
end
|
56
|
+
elsif Easymon.mountable_engine?
|
57
|
+
# Rails 3.1+
|
58
|
+
mapper.instance_eval do
|
59
|
+
get "/", :to => "checks#index"
|
60
|
+
get "/:check", :to => "checks#show"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|