Skip to content

Commit bf733da

Browse files
author
Leonid Beder
committed
Added initial version.
0 parents  commit bf733da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2371
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
coverage
6+
InstalledFiles
7+
lib/bundler/man
8+
pkg
9+
rdoc
10+
spec/reports
11+
test/tmp
12+
test/version_tmp
13+
tmp
14+
15+
# YARD artifacts
16+
.yardoc
17+
_yardoc
18+
doc/
19+
dump.rdb

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--colour
2+
--format progress
3+
--drb

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rvm:
2+
- 1.9.3
3+
- 2.0.0

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rdoc'
4+
5+
# Specify your gem's dependencies in rediska.gemspec
6+
gemspec

Gemfile.lock

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
PATH
2+
remote: .
3+
specs:
4+
health-monitor-rails (0.0.1)
5+
rails (>= 3.2)
6+
7+
GEM
8+
remote: http://rubygems.org/
9+
specs:
10+
actionmailer (4.0.2)
11+
actionpack (= 4.0.2)
12+
mail (~> 2.5.4)
13+
actionpack (4.0.2)
14+
activesupport (= 4.0.2)
15+
builder (~> 3.1.0)
16+
erubis (~> 2.7.0)
17+
rack (~> 1.5.2)
18+
rack-test (~> 0.6.2)
19+
activemodel (4.0.2)
20+
activesupport (= 4.0.2)
21+
builder (~> 3.1.0)
22+
activerecord (4.0.2)
23+
activemodel (= 4.0.2)
24+
activerecord-deprecated_finders (~> 1.0.2)
25+
activesupport (= 4.0.2)
26+
arel (~> 4.0.0)
27+
activerecord-deprecated_finders (1.0.3)
28+
activesupport (4.0.2)
29+
i18n (~> 0.6, >= 0.6.4)
30+
minitest (~> 4.2)
31+
multi_json (~> 1.3)
32+
thread_safe (~> 0.1)
33+
tzinfo (~> 0.3.37)
34+
arel (4.0.2)
35+
atomic (1.1.14)
36+
builder (3.1.4)
37+
celluloid (0.15.2)
38+
timers (~> 1.1.0)
39+
coderay (1.1.0)
40+
connection_pool (1.2.0)
41+
coveralls (0.7.0)
42+
multi_json (~> 1.3)
43+
rest-client
44+
simplecov (>= 0.7)
45+
term-ansicolor
46+
thor
47+
database_cleaner (1.2.0)
48+
diff-lcs (1.2.5)
49+
docile (1.1.3)
50+
erubis (2.7.0)
51+
hike (1.2.3)
52+
i18n (0.6.9)
53+
json (1.8.1)
54+
mail (2.5.4)
55+
mime-types (~> 1.16)
56+
treetop (~> 1.4.8)
57+
method_source (0.8.2)
58+
mime-types (1.25.1)
59+
minitest (4.7.5)
60+
multi_json (1.8.4)
61+
polyglot (0.3.3)
62+
pry (0.9.12.6)
63+
coderay (~> 1.0)
64+
method_source (~> 0.8)
65+
slop (~> 3.4)
66+
rack (1.5.2)
67+
rack-test (0.6.2)
68+
rack (>= 1.0)
69+
rails (4.0.2)
70+
actionmailer (= 4.0.2)
71+
actionpack (= 4.0.2)
72+
activerecord (= 4.0.2)
73+
activesupport (= 4.0.2)
74+
bundler (>= 1.3.0, < 2.0)
75+
railties (= 4.0.2)
76+
sprockets-rails (~> 2.0.0)
77+
railties (4.0.2)
78+
actionpack (= 4.0.2)
79+
activesupport (= 4.0.2)
80+
rake (>= 0.8.7)
81+
thor (>= 0.18.1, < 2.0)
82+
rake (10.1.1)
83+
rdoc (4.1.1)
84+
json (~> 1.4)
85+
redis (3.0.7)
86+
redis-namespace (1.4.1)
87+
redis (~> 3.0.4)
88+
rediska (0.0.7)
89+
redis (~> 3.0.0)
90+
rest-client (1.6.7)
91+
mime-types (>= 1.16)
92+
rspec-core (2.14.7)
93+
rspec-expectations (2.14.5)
94+
diff-lcs (>= 1.1.3, < 2.0)
95+
rspec-mocks (2.14.5)
96+
rspec-rails (2.14.1)
97+
actionpack (>= 3.0)
98+
activemodel (>= 3.0)
99+
activesupport (>= 3.0)
100+
railties (>= 3.0)
101+
rspec-core (~> 2.14.0)
102+
rspec-expectations (~> 2.14.0)
103+
rspec-mocks (~> 2.14.0)
104+
sidekiq (2.17.4)
105+
celluloid (>= 0.15.2)
106+
connection_pool (>= 1.0.0)
107+
json
108+
redis (>= 3.0.6)
109+
redis-namespace (>= 1.3.1)
110+
simplecov (0.8.2)
111+
docile (~> 1.1.0)
112+
multi_json
113+
simplecov-html (~> 0.8.0)
114+
simplecov-html (0.8.0)
115+
slop (3.4.7)
116+
spork (0.9.2)
117+
sprockets (2.10.1)
118+
hike (~> 1.2)
119+
multi_json (~> 1.0)
120+
rack (~> 1.0)
121+
tilt (~> 1.1, != 1.3.0)
122+
sprockets-rails (2.0.1)
123+
actionpack (>= 3.0)
124+
activesupport (>= 3.0)
125+
sprockets (~> 2.8)
126+
sqlite3 (1.3.8)
127+
term-ansicolor (1.3.0)
128+
tins (~> 1.0)
129+
thor (0.18.1)
130+
thread_safe (0.1.3)
131+
atomic
132+
tilt (1.4.1)
133+
timers (1.1.0)
134+
tins (1.0.0)
135+
treetop (1.4.15)
136+
polyglot
137+
polyglot (>= 0.3.1)
138+
tzinfo (0.3.38)
139+
140+
PLATFORMS
141+
ruby
142+
143+
DEPENDENCIES
144+
coveralls
145+
database_cleaner
146+
health-monitor-rails!
147+
pry
148+
rake
149+
rdoc
150+
rediska
151+
rspec-rails
152+
sidekiq
153+
spork
154+
sqlite3

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Leonid Beder
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.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# health-monitor-rails
2+
3+
[![Gem Version](https://badge.fury.io/rb/health-monitor-rails.png)](http://badge.fury.io/rb/health-monitor-rails)
4+
[![Build Status](https://travis-ci.org/lbeder/health-monitor-rails.png)](https://travis-ci.org/lbeder/health-monitor-rails)
5+
[![Dependency Status](https://gemnasium.com/lbeder/health-monitor-rails.png)](https://gemnasium.com/lbeder/health-monitor-rails)
6+
[![Coverage Status](https://coveralls.io/repos/lbeder/health-monitor-rails/badge.png)](https://coveralls.io/r/lbeder/health-monitor-rails)

Rakefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
8+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
9+
load 'rails/tasks/engine.rake'
10+
11+
Bundler::GemHelper.install_tasks
12+
13+
require 'rspec/core/rake_task'
14+
15+
Rake::TestTask.new(:test) do |t|
16+
t.libs << 'lib'
17+
t.libs << 'test'
18+
t.pattern = 'test/**/*_test.rb'
19+
t.verbose = false
20+
end
21+
22+
task default: :test

app/controllers/health_controller.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class HealthController < ActionController::Base
2+
layout nil
3+
4+
# GET /health/check
5+
def check
6+
HealthMonitor.check!
7+
8+
render text: "Healh check has passed: #{Time.now.to_s(:db)}\n"
9+
rescue Exception => e
10+
render text: "Healh check has failed: #{Time.now.to_s(:db)}, error: #{e.message}\n",
11+
:status => :service_unavailable
12+
end
13+
14+
private
15+
def process_with_silence(*args)
16+
logger.quietly do
17+
process_without_silence(*args)
18+
end
19+
end
20+
21+
alias_method_chain :process, :silence
22+
end

bin/rails

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
# This command will automatically be run when you run "rails" with Rails 3/4 gems installed from the
3+
# root of your application.
4+
5+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
6+
ENGINE_PATH = File.expand_path('../../lib/health_monitor/engine', __FILE__)
7+
8+
require 'rails/all'
9+
require 'rails/engine/commands'

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
HealthMonitor::Engine.routes.draw do
2+
get :check
3+
end

health-monitor-rails.gemspec

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$:.push File.expand_path('../lib', __FILE__)
2+
require 'health_monitor/version'
3+
4+
Gem::Specification.new do |s|
5+
s.name = 'health-monitor-rails'
6+
s.version = HealthMonitor::VERSION
7+
s.platform = Gem::Platform::RUBY
8+
s.authors = ['Leonid Beder']
9+
s.email = ['[email protected]']
10+
s.license = 'MIT'
11+
s.homepage = 'https://github.com/lbeder/health-monitor-rails'
12+
s.summary = 'xxx'
13+
s.description = 'xxx.'
14+
15+
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
16+
s.test_files = Dir['test/**/*']
17+
18+
s.add_dependency 'rails', '>= 3.2'
19+
s.add_development_dependency 'sqlite3'
20+
s.add_development_dependency 'rspec-rails'
21+
s.add_development_dependency 'database_cleaner'
22+
s.add_development_dependency 'spork'
23+
s.add_development_dependency 'pry'
24+
s.add_development_dependency 'coveralls'
25+
s.add_development_dependency 'rake'
26+
s.add_development_dependency 'rediska'
27+
s.add_development_dependency 'sidekiq'
28+
end

lib/health-monitor-rails.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'health_monitor/version'
2+
require 'health_monitor/engine'
3+
require 'health_monitor/configuration'
4+
require 'health_monitor/monitor'

lib/health_monitor/configuration.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module HealthMonitor
2+
class Configuration
3+
attr_accessor :providers, :error_callback
4+
5+
def initialize
6+
@providers = [:database]
7+
end
8+
end
9+
end

lib/health_monitor/engine.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module HealthMonitor
2+
class Engine < ::Rails::Engine
3+
isolate_namespace HealthMonitor
4+
end
5+
end

lib/health_monitor/monitor.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'health_monitor/configuration'
2+
3+
module HealthMonitor
4+
extend self
5+
6+
attr_accessor :configuration
7+
8+
def configure
9+
self.configuration ||= Configuration.new
10+
11+
yield configuration if block_given?
12+
end
13+
14+
def check!
15+
configuration.providers.each do |provider|
16+
require "health_monitor/providers/#{provider}"
17+
18+
monitor = "HealthMonitor::Providers::#{provider.capitalize}".constantize.new
19+
monitor.check!
20+
end
21+
rescue Exception => e
22+
configuration.error_callback.call(e) if configuration.error_callback
23+
raise
24+
end
25+
end
26+
27+
HealthMonitor.configure

lib/health_monitor/providers/cache.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module HealthMonitor
2+
module Providers
3+
class Cache
4+
def check!
5+
time = Time.now.to_s
6+
7+
Rails.cache.write(:health, time)
8+
fetched = Rails.cache.read(:health)
9+
10+
raise "different values (now: #{time}, fetched: #{fetched}" if fetched != time
11+
end
12+
end
13+
end
14+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module HealthMonitor
2+
module Providers
3+
class DBException < StandardError; end
4+
5+
class Database
6+
def check!
7+
# Check connection to the DB:
8+
query = "SELECT max(version, '0') FROM schema_migrations"
9+
ActiveRecord::Base.connection.select_value(query).to_i
10+
rescue => e
11+
raise DBException.new(e.message)
12+
end
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)