rack-monitor 0.1.0 → 0.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/README.rdoc +8 -6
- data/lib/rack/monitor/monitor_app.rb +3 -3
- data/lib/rack/monitor/sensor.rb +1 -1
- data/lib/rack/monitor/sensors/request.rb +23 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -5,12 +5,12 @@ monitoring tools like Munin.
|
|
5
5
|
|
6
6
|
==Installation
|
7
7
|
|
8
|
-
|
8
|
+
sudo gem install rack-monitor
|
9
9
|
|
10
10
|
==Basic Usage
|
11
11
|
|
12
12
|
Rack::Monitor is implemented as a piece of Rack middleware and can be used with
|
13
|
-
any Rack-based application. If your application includes a rackup (
|
13
|
+
any Rack-based application. If your application includes a rackup (<tt>.ru</tt>) file
|
14
14
|
or uses Rack::Builder to construct the application pipeline, simply require
|
15
15
|
and use as follows:
|
16
16
|
|
@@ -22,23 +22,25 @@ and use as follows:
|
|
22
22
|
|
23
23
|
==Using with Rails
|
24
24
|
|
25
|
-
Add this to your
|
25
|
+
Add this to your <tt>config/environments/production.rb</tt>:
|
26
26
|
|
27
27
|
config.gem "rack-monitor", :lib => "rack/monitor"
|
28
28
|
|
29
29
|
require 'rack/monitor' #Rails bug?
|
30
|
-
config.middleware.use Rack::Monitor
|
30
|
+
config.middleware.use ::Rack::Monitor
|
31
31
|
|
32
|
-
You should now see
|
32
|
+
You should now see <tt>Rack::Monitor</tt> listed in the middleware pipeline:
|
33
33
|
|
34
34
|
RAILS_ENV=production rake middleware
|
35
35
|
|
36
|
+
Rack::Monitor doesn't work properly when started with mongrel_rails. Use thin instead.
|
37
|
+
|
36
38
|
==Monitoring with Munin
|
37
39
|
|
38
40
|
Copy plugin files from http://github.com/pka/rack-monitor/tree/master/munin/ to /etc/munin/plugins/
|
39
41
|
|
40
42
|
Setup a configuration in /etc/munin/plugin-conf.d/ like
|
41
|
-
http://github.com/pka/rack-monitor/tree/master/
|
43
|
+
http://github.com/pka/rack-monitor/tree/master/munin/plugin-conf.d/rack
|
42
44
|
|
43
45
|
/etc/init.d/munin-node restart
|
44
46
|
|
@@ -21,9 +21,9 @@ class MonitorApp
|
|
21
21
|
[200, {'Content-Type' => 'text/plain'}, [monitor_output]]
|
22
22
|
else
|
23
23
|
@sensors.each { |sensor| sensor.before(env) }
|
24
|
-
status, headers,
|
25
|
-
@sensors.each { |sensor| sensor.after(env) }
|
26
|
-
[status, headers,
|
24
|
+
status, headers, body = @app.call(env)
|
25
|
+
@sensors.each { |sensor| sensor.after(env, status, headers, body) }
|
26
|
+
[status, headers, body]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/rack/monitor/sensor.rb
CHANGED
@@ -1,16 +1,37 @@
|
|
1
1
|
module Rack::Monitor
|
2
2
|
|
3
3
|
class Request < Sensor
|
4
|
+
STATUS_CODES = [200, 403, 404]
|
4
5
|
def initialize
|
5
6
|
@count = 0
|
7
|
+
@status = {}
|
8
|
+
(STATUS_CODES+[1,2,3,4,5]).each { |code| @status[code] = 0 }
|
6
9
|
end
|
7
10
|
|
8
|
-
def after(env)
|
11
|
+
def after(env, status, headers, body)
|
9
12
|
@count += 1
|
13
|
+
@status[code_group(status)] += 1
|
10
14
|
end
|
11
15
|
|
12
16
|
def measurements
|
13
|
-
[['count', 'Total requests', @count]]
|
17
|
+
m = [['count', 'Total requests', @count]]
|
18
|
+
STATUS_CODES.each do |status|
|
19
|
+
m << ["status#{status}", "Responses with status #{status}", @status[status]]
|
20
|
+
end
|
21
|
+
[1,2,3,4,5].each do |status|
|
22
|
+
m << ["status#{status}", "Responses with other status #{status}xx", @status[status]]
|
23
|
+
end
|
24
|
+
m
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def code_group(code)
|
30
|
+
if STATUS_CODES.include?(code)
|
31
|
+
code
|
32
|
+
else
|
33
|
+
code / 100
|
34
|
+
end
|
14
35
|
end
|
15
36
|
end
|
16
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pirmin Kalberer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|