rack-monitor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +57 -0
- data/lib/rack/monitor.rb +10 -0
- data/lib/rack/monitor/monitor_app.rb +45 -0
- data/lib/rack/monitor/sensor.rb +24 -0
- data/lib/rack/monitor/sensors/memory.rb +18 -0
- data/lib/rack/monitor/sensors/request.rb +17 -0
- data/lib/rack/monitor/sensors/version.rb +14 -0
- data/test/helper.rb +9 -0
- data/test/test_rack-monitor.rb +7 -0
- metadata +64 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Pirmin Kalberer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
=Rack::Monitor
|
2
|
+
|
3
|
+
Rack::Monitor is Rack middleware collecting run-time information for
|
4
|
+
monitoring tools like Munin.
|
5
|
+
|
6
|
+
==Installation
|
7
|
+
|
8
|
+
$ sudo gem install rack-monitor
|
9
|
+
|
10
|
+
==Basic Usage
|
11
|
+
|
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 (`.ru`) file
|
14
|
+
or uses Rack::Builder to construct the application pipeline, simply require
|
15
|
+
and use as follows:
|
16
|
+
|
17
|
+
require 'rack/monitor'
|
18
|
+
|
19
|
+
use Rack::Monitor if ENV['RACK_ENV'] == 'production'
|
20
|
+
|
21
|
+
run app
|
22
|
+
|
23
|
+
==Using with Rails
|
24
|
+
|
25
|
+
Add this to your `config/environments/production.rb`:
|
26
|
+
|
27
|
+
config.gem "rack-monitor", :lib => "rack/monitor"
|
28
|
+
|
29
|
+
require 'rack/monitor' #Rails bug?
|
30
|
+
config.middleware.use Rack::Monitor
|
31
|
+
|
32
|
+
You should now see `Rack::Monitor` listed in the middleware pipeline:
|
33
|
+
|
34
|
+
RAILS_ENV=production rake middleware
|
35
|
+
|
36
|
+
==Monitoring with Munin
|
37
|
+
|
38
|
+
Copy plugin files from http://github.com/pka/rack-monitor/tree/master/munin/ to /etc/munin/plugins/
|
39
|
+
|
40
|
+
Setup a configuration in /etc/munin/plugin-conf.d/ like
|
41
|
+
http://github.com/pka/rack-monitor/tree/master/muninplugin-conf.d/rack
|
42
|
+
|
43
|
+
/etc/init.d/munin-node restart
|
44
|
+
|
45
|
+
==Links
|
46
|
+
|
47
|
+
GitHub:: http://github.com/pka/rack-monitor
|
48
|
+
|
49
|
+
|
50
|
+
Thanks to:
|
51
|
+
|
52
|
+
* rack-bug
|
53
|
+
* Rails footnotes
|
54
|
+
|
55
|
+
== Copyright
|
56
|
+
|
57
|
+
Copyright (c) 2010 Pirmin Kalberer. See LICENSE for details.
|
data/lib/rack/monitor.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rack/monitor/sensor'
|
2
|
+
|
3
|
+
# Load all sensors
|
4
|
+
#
|
5
|
+
Dir[File.join(File.dirname(__FILE__), 'sensors', '*.rb')].each do |sensor|
|
6
|
+
require sensor
|
7
|
+
end
|
8
|
+
|
9
|
+
module Rack::Monitor
|
10
|
+
|
11
|
+
class MonitorApp
|
12
|
+
def initialize(app, options={})
|
13
|
+
@app = app
|
14
|
+
@options = {:url=>'/rack_status'}.merge(options)
|
15
|
+
sensor_class_names = Rack::Monitor.constants.reject { |s| %q(Sensor MonitorApp).include?(s) }
|
16
|
+
@sensors = sensor_class_names.collect { |s| Rack::Monitor.const_get(s).new }
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env, options={})
|
20
|
+
if env["PATH_INFO"] == @options[:url]
|
21
|
+
[200, {'Content-Type' => 'text/plain'}, [monitor_output]]
|
22
|
+
else
|
23
|
+
@sensors.each { |sensor| sensor.before(env) }
|
24
|
+
status, headers, response = @app.call(env)
|
25
|
+
@sensors.each { |sensor| sensor.after(env) }
|
26
|
+
[status, headers, response]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def monitor_output
|
33
|
+
output = ''
|
34
|
+
@sensors.each do |sensor|
|
35
|
+
class_name = sensor.class.name.gsub(/^.*::/, '')
|
36
|
+
sensor.collect
|
37
|
+
sensor.measurements.each do |var, desc, value|
|
38
|
+
output << "[#{class_name}:#{var}] #{desc}: #{value}\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
output
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack::Monitor
|
4
|
+
|
5
|
+
class Sensor
|
6
|
+
#Called before request
|
7
|
+
def before(env)
|
8
|
+
end
|
9
|
+
|
10
|
+
#Called after request
|
11
|
+
def after(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
#Called before delivering measurements
|
15
|
+
def collect
|
16
|
+
end
|
17
|
+
|
18
|
+
#Return measured values arrays [variable, description, value]
|
19
|
+
def measurements
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rack::Monitor
|
2
|
+
|
3
|
+
class Version < Sensor
|
4
|
+
def measurements
|
5
|
+
m = [['rack_info', 'Rack version', Rack.release]]
|
6
|
+
if defined?(Rails) && defined?(Rails::Info)
|
7
|
+
m << ['rails_info', 'Rails version', Rails.version]
|
8
|
+
end
|
9
|
+
m
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pirmin Kalberer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-03 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Run-time date collector
|
17
|
+
email: pka@sourcepole.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- lib/rack/monitor.rb
|
27
|
+
- lib/rack/monitor/monitor_app.rb
|
28
|
+
- lib/rack/monitor/sensor.rb
|
29
|
+
- lib/rack/monitor/sensors/memory.rb
|
30
|
+
- lib/rack/monitor/sensors/request.rb
|
31
|
+
- lib/rack/monitor/sensors/version.rb
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/pka/rack-monitor
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
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: Rack::Monitor middleware
|
62
|
+
test_files:
|
63
|
+
- test/helper.rb
|
64
|
+
- test/test_rack-monitor.rb
|