health_check 1.1.2 → 1.2.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 +5 -0
- data/.travis.yml +52 -41
- data/CHANGELOG +4 -0
- data/README.rdoc +81 -18
- data/config/routes.rb +4 -2
- data/health_check.gemspec +1 -1
- data/lib/health_check.rb +28 -0
- data/lib/health_check/add_23_routes.rb +12 -7
- data/lib/health_check/health_check_controller.rb +16 -42
- data/lib/health_check/utils.rb +51 -27
- data/lib/health_check/version.rb +1 -1
- data/test/init_variables +60 -0
- data/{rails2_3.gemfile → test/rails_2.3.gemfile} +8 -1
- data/{rails3_0.gemfile → test/rails_3.0.gemfile} +0 -1
- data/{rails3_1.gemfile → test/rails_3.1.gemfile} +0 -1
- data/{rails3_2.gemfile → test/rails_3.2.gemfile} +0 -1
- data/{rails_edge.gemfile → test/rails_4.0-beta.gemfile} +4 -5
- data/test/setup_railsapp +258 -0
- data/test/test_with_railsapp +100 -177
- data/test/testurl +39 -12
- metadata +25 -18
- data/rails1_2.gemfile +0 -12
data/.gitignore
CHANGED
@@ -17,6 +17,9 @@ test/tmp
|
|
17
17
|
test/version_tmp
|
18
18
|
tmp
|
19
19
|
|
20
|
+
## RUBYMINE
|
21
|
+
.idea/
|
22
|
+
|
20
23
|
## MAC OS
|
21
24
|
.DS_Store
|
22
25
|
|
@@ -35,7 +38,9 @@ tmtags
|
|
35
38
|
|
36
39
|
## PROJECT::SPECIFIC
|
37
40
|
bin/
|
41
|
+
test/bin/
|
38
42
|
railsapps/
|
43
|
+
test/*.gemfile.lock
|
39
44
|
,*
|
40
45
|
|
41
46
|
# Local ruby version config
|
data/.travis.yml
CHANGED
@@ -3,60 +3,71 @@ notifications:
|
|
3
3
|
email:
|
4
4
|
on_success: change
|
5
5
|
on_failure: always
|
6
|
-
|
7
|
-
- 1.8.7
|
8
|
-
- 1.9.3
|
9
|
-
- rbx-18mode
|
10
|
-
- rbx-19mode
|
11
|
-
- jruby-18mode
|
12
|
-
- jruby-19mode
|
13
|
-
#- jruby-head
|
14
|
-
#- ruby-head
|
15
|
-
- ree
|
6
|
+
|
16
7
|
before_install:
|
17
|
-
- gem update --system
|
8
|
+
- gem update --system $RUBYGEMS_VERSION
|
18
9
|
- gem --version
|
19
10
|
- gem install bundler
|
20
11
|
- bundle --version
|
21
12
|
- mkdir -p tmp/bundle
|
22
13
|
|
23
|
-
gemfile:
|
24
|
-
- rails2_3.gemfile
|
25
|
-
- rails3_0.gemfile
|
26
|
-
- rails3_1.gemfile
|
27
|
-
- rails3_2.gemfile
|
28
|
-
#- rails_edge.gemfile
|
29
|
-
|
30
14
|
bundler_args: "--binstubs"
|
31
15
|
|
32
16
|
script: ./test/test_with_railsapp
|
33
17
|
|
18
|
+
rvm:
|
19
|
+
- 1.8.7
|
20
|
+
- 1.9.2
|
21
|
+
- 1.9.3
|
22
|
+
- 2.0.0
|
23
|
+
- jruby-19mode
|
24
|
+
- rbx-19mode
|
25
|
+
- ree
|
26
|
+
|
27
|
+
gemfile:
|
28
|
+
- test/rails_3.2.gemfile
|
29
|
+
|
30
|
+
env:
|
31
|
+
- RUBYGEMS_VERSION=
|
32
|
+
|
34
33
|
matrix:
|
35
34
|
exclude:
|
36
|
-
- rvm:
|
37
|
-
gemfile:
|
38
|
-
|
39
|
-
|
40
|
-
- rvm: jruby-18mode
|
41
|
-
gemfile: rails2_3.gemfile
|
35
|
+
- rvm: 1.8.7
|
36
|
+
gemfile: test/rails_3.2.gemfile
|
37
|
+
env: RUBYGEMS_VERSION=
|
38
|
+
|
42
39
|
- rvm: jruby-19mode
|
43
|
-
gemfile:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
- rvm: 1.
|
49
|
-
gemfile:
|
40
|
+
gemfile: test/rails_3.2.gemfile
|
41
|
+
env: RUBYGEMS_VERSION=
|
42
|
+
|
43
|
+
include:
|
44
|
+
# rails 2.3 march 16 2009 - ruby 1.8.7
|
45
|
+
- rvm: 1.8.7
|
46
|
+
gemfile: test/rails_2.3.gemfile
|
47
|
+
env: RUBYGEMS_VERSION=1.8.25
|
50
48
|
|
49
|
+
# rails 3.0 aug 29 2010 - ruby 1.8.7
|
51
50
|
- rvm: 1.8.7
|
52
|
-
gemfile:
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
gemfile: test/rails_3.0.gemfile
|
52
|
+
env: RUBYGEMS_VERSION=
|
53
|
+
|
54
|
+
# rails 3.1 aug 31, 2011 - ruby 1.8.7 or 1.9.2
|
55
|
+
- rvm: 1.8.7
|
56
|
+
gemfile: test/rails_3.1.gemfile
|
57
|
+
env: RUBYGEMS_VERSION=
|
58
|
+
|
59
|
+
- rvm: 1.9.2
|
60
|
+
gemfile: test/rails_3.1.gemfile
|
61
|
+
env: RUBYGEMS_VERSION=
|
62
|
+
|
63
|
+
# rails 4.0 - in development as of 5 mar 2013 - ruby 2.0
|
64
|
+
- rvm: 2.0.0
|
65
|
+
gemfile: test/rails_4.0-beta.gemfile
|
66
|
+
env: RUBYGEMS_VERSION=
|
67
|
+
|
68
|
+
- rvm: jruby-19mode
|
69
|
+
gemfile: test/rails_3.2.gemfile
|
70
|
+
env: RUBYGEMS_VERSION=1.8.25
|
71
|
+
|
59
72
|
allow_failures:
|
60
|
-
- gemfile:
|
61
|
-
- rvm: jruby-head
|
62
|
-
- rvm: ruby-head
|
73
|
+
- gemfile: test/rails_4.0-beta.gemfile
|
data/CHANGELOG
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= Change Log =
|
2
2
|
|
3
|
+
* 1.2.0 - The gem can now be configured, including timeouts, status codes and text returned on success
|
4
|
+
- Customn checks can be added via initializer like config.add_custom_check { CustomCheckClass.a_custom_check }
|
5
|
+
- You can now request the response to be json or xml (via url or Content-accepted header)
|
6
|
+
- reduced tests to the versions of ruby recomended for the different versions of rails
|
3
7
|
* 1.1.2 - Change to bundler support for building gems, as jeweler gem was broken by v2.0.0 of rubygems
|
4
8
|
* 1.1.0 - Include cache check (Thanks to https://github.com/mgomes1 ) and some changes to test setup to workaround and diagnose test failures under rvm
|
5
9
|
* 1.0.2 - Included travis config and gemfiles used in travis tests in gem and changes to test setup so that gem test
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= health_check gem
|
2
2
|
|
3
3
|
Simple health check of Rails app for use with Pingdom, NewRelic, EngineYard or uptime.openacs.org etc.
|
4
4
|
|
@@ -36,6 +36,8 @@ The email gateway is not checked unless the smtp settings have been changed.
|
|
36
36
|
Specify full or include email in the list of checks to varify the smtp settings
|
37
37
|
(eg use 127.0.0.1 instead of localhost).
|
38
38
|
|
39
|
+
Note: rails 4.0 also checks migrations and throws a ActiveRecord::PendingMigrationError (http error 500)
|
40
|
+
|
39
41
|
== Installation
|
40
42
|
|
41
43
|
=== As a Gem from rubygems (Rails 3.0 and above)
|
@@ -69,6 +71,39 @@ Run the following commands from the root of your rails application
|
|
69
71
|
cd vendor/plugins
|
70
72
|
git clone git://github.com/ianheggie/health_check.git
|
71
73
|
|
74
|
+
== Configuration
|
75
|
+
|
76
|
+
To change the configuration of health_check, create a file `config/initializers/health_check.rb` and add a configuration block like:
|
77
|
+
|
78
|
+
HealthCheck.setup do |config|
|
79
|
+
|
80
|
+
# Text output upon success
|
81
|
+
config.success = 'success'
|
82
|
+
|
83
|
+
# Timeout in seconds used when checking smtp server
|
84
|
+
self.smtp_timeout = 30.0
|
85
|
+
|
86
|
+
# http status code used when plain text error message is output
|
87
|
+
# Set to 200 if you want your want to distinguish between partial (text does not include success) and
|
88
|
+
# total failure of rails application (http status of 500 etc)
|
89
|
+
|
90
|
+
self.http_status_for_error_text = 500
|
91
|
+
|
92
|
+
# http status code used when an error object is output (json or xml)
|
93
|
+
# Set to 200 if you want your want to distinguish between partial (healthy property == false) and
|
94
|
+
# total failure of rails application (http status of 500 etc)
|
95
|
+
|
96
|
+
self.http_status_for_error_object = 500
|
97
|
+
|
98
|
+
# Add one or more custom checks that return a blank string if ok, or an error message if there is an error
|
99
|
+
config.add_custom_check do
|
100
|
+
CustomHealthCheck.perform_check # any code that returns blank on success and non blank string upon failure
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
You may call add_custom_check multiple times with different tests. These tests will be included in the default list ("standard").
|
106
|
+
|
72
107
|
== Uptime Monitoring
|
73
108
|
|
74
109
|
Use a website monitoring service to check the url regularly for the word "success" (without the quotes) rather than just a 200 http status so
|
@@ -84,6 +119,41 @@ See
|
|
84
119
|
* Engine Yard's guide - https://support.cloud.engineyard.com/entries/20996821-monitor-application-uptime (although the guide is based on fitter_happier plugin it will also work with this gem)
|
85
120
|
* Any other montoring service that can be set to check for the word success in the test returned from a url
|
86
121
|
|
122
|
+
=== Requesting Json and XML responses
|
123
|
+
|
124
|
+
Health_check will respond with an encoded hash object if json or xml is requested.
|
125
|
+
Either set the HTTP Accept header or append .json or .xml to the url.
|
126
|
+
|
127
|
+
The hash contains two keys:
|
128
|
+
* healthy - true if requested checks pass (boolean)
|
129
|
+
* message - text message ("success" or error message)
|
130
|
+
|
131
|
+
The following commands
|
132
|
+
|
133
|
+
curl -v localhost:3000/health_check.json
|
134
|
+
curl -v localhost:3000/health_check/email.json
|
135
|
+
curl -v -H "Accept: application/json" localhost:3000/health_check
|
136
|
+
|
137
|
+
Will return a result with Content-Type: application/json and body like:
|
138
|
+
|
139
|
+
{"healthy":true,"message":"success"}
|
140
|
+
|
141
|
+
These following commands
|
142
|
+
|
143
|
+
curl -v localhost:3000/health_check.xml
|
144
|
+
curl -v localhost:3000/health_check/migration_cache.xml
|
145
|
+
curl -v -H "Accept: text/xml" localhost:3000/health_check/cache
|
146
|
+
|
147
|
+
Will return a result with Content-Type: application/xml and body like:
|
148
|
+
|
149
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
150
|
+
<hash>
|
151
|
+
<healthy type="boolean">true</healthy>
|
152
|
+
<message>success</message>
|
153
|
+
</hash>
|
154
|
+
|
155
|
+
See https://github.com/ianheggie/health_check/wiki/Ajax-Example for an Ajax example
|
156
|
+
|
87
157
|
== Note on Patches/Pull Requests
|
88
158
|
|
89
159
|
<em>Feedback welcome! Especially with suggested replacement code and corresponding tests</em>
|
@@ -105,11 +175,11 @@ See
|
|
105
175
|
|
106
176
|
== Testing
|
107
177
|
|
108
|
-
=== Automated
|
178
|
+
=== Automated testing
|
109
179
|
|
110
180
|
See Travis CI testing result: {<img src="https://travis-ci.org/ianheggie/health_check.png">}[https://travis-ci.org/ianheggie/health_check]
|
111
181
|
|
112
|
-
Code Climate also monitors this project: {<img src="https://codeclimate.com/github/ianheggie/health_check.png" />}[https://codeclimate.com/github/ianheggie/health_check]
|
182
|
+
Code Climate also monitors this project for code quality: {<img src="https://codeclimate.com/github/ianheggie/health_check.png" />}[https://codeclimate.com/github/ianheggie/health_check]
|
113
183
|
|
114
184
|
=== Manual testing
|
115
185
|
|
@@ -119,7 +189,7 @@ This will require TCP port 3456 to be free.
|
|
119
189
|
|
120
190
|
Using rbenv or rvm, install and set the version of ruby you wish to test against.
|
121
191
|
You will need to install the bundler gem if using rbenv.
|
122
|
-
See the <tt>.travis.yml</tt> file for
|
192
|
+
See the <tt>.travis.yml</tt> file for the list of ruby versions that we test against.
|
123
193
|
|
124
194
|
* rbenv command: <tt>rbenv shell 1.8.7-p371</tt>
|
125
195
|
* rvm command: <tt>rvm use 1.9.3</tt>
|
@@ -130,26 +200,19 @@ Create a temp directory for throw away testing, and clone the health_check gem i
|
|
130
200
|
cd ~/tmp
|
131
201
|
git clone https://github.com/ianheggie/health_check.git
|
132
202
|
|
133
|
-
|
203
|
+
Cd to the checked out health_check directory and then run the test as follows:
|
134
204
|
|
135
205
|
cd ~/tmp/health_check
|
136
206
|
|
137
|
-
|
138
|
-
|
139
|
-
export BUNDLE_GEMFILE=$PWD/rails2_3.gemfile
|
140
|
-
export BUNDLE_GEMFILE=$PWD/rails3_0.gemfile
|
141
|
-
export BUNDLE_GEMFILE=$PWD/rails3_1.gemfile
|
142
|
-
export BUNDLE_GEMFILE=$PWD/rails3_2.gemfile
|
143
|
-
unset BUNDLE_GEMFILE # for installed version of rails
|
144
|
-
|
145
|
-
Then install the required gems, and update rbenv shims (if using rbenv)
|
207
|
+
test/test_with_railsapp
|
146
208
|
|
147
|
-
|
148
|
-
|
209
|
+
The script will first call `test/setup_railsapp` to setup a rails app with health_check installed and then
|
210
|
+
run up the rails server and perform veraious tests.
|
149
211
|
|
150
|
-
|
212
|
+
The script `test/setup_railsapp` will prompt you for which gemfile under test you wish to use to install the appropriate rails version, and then
|
213
|
+
setup tmp/railsapp accordingly.
|
151
214
|
|
152
|
-
|
215
|
+
The command `rake test` will also launch these tests, except it cannot install the bundler and rake gems if they are missing first (unlike test/test_with_railsapp)
|
153
216
|
|
154
217
|
== Copyright
|
155
218
|
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
if defined?(HealthCheck::Engine)
|
2
2
|
Rails.application.routes.draw do
|
3
|
-
|
4
|
-
|
3
|
+
get 'health_check', :to => 'health_check/health_check#index'
|
4
|
+
get 'health_check.:format', :to => 'health_check/health_check#index'
|
5
|
+
get 'health_check/:checks', :to => 'health_check/health_check#index'
|
6
|
+
get 'health_check/:checks.:format', :to => 'health_check/health_check#index'
|
5
7
|
end
|
6
8
|
end
|
data/health_check.gemspec
CHANGED
@@ -24,5 +24,5 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_development_dependency(%q<rake>, [">= 0.8.3"])
|
25
25
|
gem.add_development_dependency(%q<shoulda>, ["~> 2.11.0"])
|
26
26
|
gem.add_development_dependency(%q<sqlite3>, ["~> 1.3.7"])
|
27
|
-
gem.add_development_dependency(%q<bundler>, ["~> 1.2
|
27
|
+
gem.add_development_dependency(%q<bundler>, ["~> 1.2"])
|
28
28
|
end
|
data/lib/health_check.rb
CHANGED
@@ -8,6 +8,34 @@ module HealthCheck
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
# Text output upon success
|
12
|
+
mattr_accessor :success
|
13
|
+
self.success = "success"
|
14
|
+
|
15
|
+
# Timeout in seconds used when checking smtp server
|
16
|
+
mattr_accessor :smtp_timeout
|
17
|
+
self.smtp_timeout = 30.0
|
18
|
+
|
19
|
+
# http status code used when plain text error message is output
|
20
|
+
mattr_accessor :http_status_for_error_text
|
21
|
+
self.http_status_for_error_text = 500
|
22
|
+
|
23
|
+
# http status code used when an error object is output (json or xml)
|
24
|
+
mattr_accessor :http_status_for_error_object
|
25
|
+
self.http_status_for_error_object = 500
|
26
|
+
|
27
|
+
# Array of custom check blocks
|
28
|
+
mattr_accessor :custom_checks
|
29
|
+
self.custom_checks = [ ]
|
30
|
+
|
31
|
+
def self.add_custom_check(&block)
|
32
|
+
custom_checks << block
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.setup
|
36
|
+
yield self
|
37
|
+
end
|
38
|
+
|
11
39
|
end
|
12
40
|
|
13
41
|
require "health_check/version"
|
@@ -6,14 +6,19 @@ module ActionController
|
|
6
6
|
module Routing #:nodoc:
|
7
7
|
class RouteSet #:nodoc:
|
8
8
|
alias_method :draw_without_health_check_routes, :draw
|
9
|
+
|
9
10
|
def draw
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
draw_without_health_check_routes do |map|
|
12
|
+
map.connect 'health_check',
|
13
|
+
:controller => 'health_check/health_check', :action => 'index'
|
14
|
+
map.connect 'health_check.:format',
|
15
|
+
:controller => 'health_check/health_check', :action => 'index'
|
16
|
+
map.connect 'health_check/:checks',
|
17
|
+
:controller => 'health_check/health_check', :action => 'index'
|
18
|
+
map.connect 'health_check/:checks.:format',
|
19
|
+
:controller => 'health_check/health_check', :action => 'index'
|
20
|
+
yield map
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -9,26 +9,29 @@ module HealthCheck
|
|
9
9
|
layout nil
|
10
10
|
|
11
11
|
def index
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def check
|
16
|
-
do_check(params[:checks])
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def do_check(checks)
|
12
|
+
checks = params[:checks] || 'standard'
|
22
13
|
begin
|
23
|
-
errors = process_checks(checks)
|
14
|
+
errors = HealthCheck::Utils.process_checks(checks)
|
24
15
|
rescue Exception => e
|
25
16
|
errors = e.message
|
26
17
|
end
|
27
18
|
if errors.blank?
|
28
|
-
|
19
|
+
obj = { :healthy => true, :message => HealthCheck.success }
|
20
|
+
respond_to do |format|
|
21
|
+
format.html { render :text => HealthCheck.success, :content_type => 'text/plain' }
|
22
|
+
format.json { render :xml => obj.to_json }
|
23
|
+
format.xml { render :xml => obj.to_xml }
|
24
|
+
format.any { render :text => HealthCheck.success, :content_type => 'text/plain' }
|
25
|
+
end
|
29
26
|
else
|
30
27
|
msg = "health_check failed: #{errors}"
|
31
|
-
|
28
|
+
obj = { :healthy => false, :message => msg }
|
29
|
+
respond_to do |format|
|
30
|
+
format.html { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
|
31
|
+
format.json { render :xml => obj.to_json, :status => HealthCheck.http_status_for_error_object}
|
32
|
+
format.xml { render :xml => obj.to_xml, :status => HealthCheck.http_status_for_error_object }
|
33
|
+
format.any { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
|
34
|
+
end
|
32
35
|
# Log a single line as some uptime checkers only record that it failed, not the text returned
|
33
36
|
if logger
|
34
37
|
silence_level, logger.level = logger.level, @old_logger_level
|
@@ -38,35 +41,6 @@ module HealthCheck
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
def process_checks(checks)
|
42
|
-
errors = ''
|
43
|
-
checks.split('_').each do |check|
|
44
|
-
case check
|
45
|
-
when 'and', 'site'
|
46
|
-
# do nothing
|
47
|
-
when "database"
|
48
|
-
HealthCheck::Utils.get_database_version
|
49
|
-
when "email"
|
50
|
-
errors << HealthCheck::Utils.check_email
|
51
|
-
when "migrations", "migration"
|
52
|
-
database_version = HealthCheck::Utils.get_database_version
|
53
|
-
migration_version = HealthCheck::Utils.get_migration_version
|
54
|
-
if database_version.to_i != migration_version.to_i
|
55
|
-
errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). "
|
56
|
-
end
|
57
|
-
when 'cache'
|
58
|
-
errors << HealthCheck::Utils.check_cache
|
59
|
-
when "standard"
|
60
|
-
errors << process_checks("database_migrations")
|
61
|
-
errors << process_checks("email") unless HealthCheck::Utils.default_action_mailer_configuration?
|
62
|
-
when "all", "full"
|
63
|
-
errors << process_checks("database_migrations_email_cache")
|
64
|
-
else
|
65
|
-
return "invalid argument to health_test. "
|
66
|
-
end
|
67
|
-
end
|
68
|
-
return errors
|
69
|
-
end
|
70
44
|
|
71
45
|
protected
|
72
46
|
|