rails-pulse 0.4.3
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/README.textile +106 -0
- data/init.rb +1 -0
- data/lib/pulse.rb +3 -0
- data/lib/pulse_controller.rb +19 -0
- data/lib/pulse_helper.rb +2 -0
- data/lib/routes.rb +9 -0
- metadata +63 -0
data/README.textile
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
h1. Pulse
|
2
|
+
|
3
|
+
Pulse adds an action to your rails project that can be used for external health checking. The most common use is by a http proxy such as "haproxy":http://haproxy.1wt.eu/ or a monitoring tool such as "god":http://god.rubyforge.org.
|
4
|
+
|
5
|
+
h3. Authors
|
6
|
+
|
7
|
+
* "Paul Gross":http://www.prgs.net
|
8
|
+
* "Jesse Newland":http://jnewland.com
|
9
|
+
|
10
|
+
h2. Requirements
|
11
|
+
|
12
|
+
* Rails
|
13
|
+
* MySQL, Postgres, or Oracle. sqlite not supported, sorry.
|
14
|
+
|
15
|
+
h2. Installation
|
16
|
+
|
17
|
+
In your @config/environment.rb@:
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
<code>
|
21
|
+
config.gem 'rails-pulse', :source => "http://gemcutter.org/", :lib => "pulse"
|
22
|
+
</code>
|
23
|
+
</pre>
|
24
|
+
|
25
|
+
Install the gem:
|
26
|
+
|
27
|
+
<pre>
|
28
|
+
<code>
|
29
|
+
cd RAILS_ROOT
|
30
|
+
rake gems:install
|
31
|
+
</code>
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
Finally, add a route to config/routes.rb:
|
35
|
+
|
36
|
+
<pre>
|
37
|
+
<code>
|
38
|
+
map.pulse 'pulse'
|
39
|
+
</code>
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
This configures pulse to work at the 'pulse' URL. If you would rather use a different URL:
|
43
|
+
|
44
|
+
<pre>
|
45
|
+
<code>
|
46
|
+
map.pulse 'some/other/url'
|
47
|
+
</code>
|
48
|
+
</pre>
|
49
|
+
|
50
|
+
h2. haproxy configuration
|
51
|
+
|
52
|
+
haproxy can be configured to use the /pulse url for its health checking. Just add:
|
53
|
+
|
54
|
+
<pre>
|
55
|
+
<code>
|
56
|
+
option httpchk GET /pulse
|
57
|
+
</code>
|
58
|
+
</pre>
|
59
|
+
|
60
|
+
<pre>
|
61
|
+
<code>
|
62
|
+
listen rails :9000
|
63
|
+
server rails-1 localhost:8000 maxconn 1 check inter 20000 fall 1
|
64
|
+
server rails-2 localhost:8001 maxconn 1 check inter 20000 fall 1
|
65
|
+
...
|
66
|
+
</code>
|
67
|
+
</pre>
|
68
|
+
|
69
|
+
h2. god configuration
|
70
|
+
|
71
|
+
You are using god to watch your mongrels, right?
|
72
|
+
|
73
|
+
In your mongrel watch, add the following restart condition:
|
74
|
+
|
75
|
+
<pre>
|
76
|
+
<code>
|
77
|
+
w.restart_if do |restart|
|
78
|
+
...
|
79
|
+
restart.condition(:http_response_code) do |c|
|
80
|
+
c.code_is_not = 200
|
81
|
+
c.host = 'localhost'
|
82
|
+
c.path = '/pulse'
|
83
|
+
c.port = 8000
|
84
|
+
c.timeout = 5.seconds
|
85
|
+
c.interval = 20.seconds
|
86
|
+
end
|
87
|
+
end
|
88
|
+
</code>
|
89
|
+
</pre>
|
90
|
+
|
91
|
+
Also make sure to give your mongrels a nice grace period.
|
92
|
+
|
93
|
+
<pre>
|
94
|
+
<code>
|
95
|
+
...
|
96
|
+
w.start_grace = 90.seconds
|
97
|
+
w.restart_grace = 90.seconds
|
98
|
+
...
|
99
|
+
</code>
|
100
|
+
</pre>
|
101
|
+
|
102
|
+
For a complete god configuration example, check out my "god_examples project":http://github.com/jnewland/god_examples and the included "sample rails god config":http://github.com/jnewland/god_examples/tree/master/rails/config/god/app.god.
|
103
|
+
|
104
|
+
h2. License
|
105
|
+
|
106
|
+
Released under "Ruby's license":http://www.ruby-lang.org/en/LICENSE.txt
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/pulse"
|
data/lib/pulse.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class PulseController < ActionController::Base
|
2
|
+
session :off unless Rails::VERSION::STRING >= "2.3"
|
3
|
+
|
4
|
+
#The pulse action. Runs <tt>select 1</tt> on the DB. If a sane result is
|
5
|
+
#returned, 'OK' is displayed and a 200 response code is returned. If not,
|
6
|
+
#'ERROR' is returned along with a 500 response code.
|
7
|
+
def pulse
|
8
|
+
if (ActiveRecord::Base.connection.execute("select 1 from dual").num_rows rescue 0) == 1
|
9
|
+
render :text => "<html><body>OK #{Time.now.utc.to_s(:db)}</body></html>"
|
10
|
+
else
|
11
|
+
render :text => '<html><body>ERROR</body></html>', :status => :internal_server_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#cancel out loggin for the PulseController by defining logger as <tt>nil</tt>
|
16
|
+
def logger
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
data/lib/pulse_helper.rb
ADDED
data/lib/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-pulse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Gross
|
8
|
+
- Jesse Newland
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-12-01 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: |-
|
18
|
+
Adds a pulse URL that pings the DB to a Rails app.
|
19
|
+
This is an improved version of the `pulse` gem.
|
20
|
+
email: jnewland@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- init.rb
|
29
|
+
- lib/pulse.rb
|
30
|
+
- lib/pulse_controller.rb
|
31
|
+
- lib/pulse_helper.rb
|
32
|
+
- lib/routes.rb
|
33
|
+
- README.textile
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/jnewland/pulse
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Adds a pulse URL that pings the DB to a Rails app.
|
62
|
+
test_files: []
|
63
|
+
|