rack-probe 0.0.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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.markdown +53 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rack-probe.rb +3 -0
- data/lib/rack/probe.rb +55 -0
- data/rack-probe.gemspec +60 -0
- data/spec/rack/probe_spec.rb +136 -0
- data/spec/spec_helper.rb +14 -0
- metadata +96 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 ecin
|
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.markdown
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Rack::Probe : dtrace probes for your webapp
|
2
|
+
===========================================
|
3
|
+
|
4
|
+
status
|
5
|
+
------
|
6
|
+
|
7
|
+
Rack::Probe (along with Dtracy) is part of the Ruby on Rail's Google Summer of Code '09 Quartet, with development updates and entertainment available at `http://ecin.tumblr.com` Welcome! Sit down, grab a sugary drink, and enjoy the smell of freshly baked code right out of the oven.
|
8
|
+
|
9
|
+
requirements
|
10
|
+
------------
|
11
|
+
|
12
|
+
An operating system with support for Dtrace (http://www.sun.com/bigadmin/content/dtrace/) is a must. Mac OS X, Solaris/OpenSolaris and FreeBSD are all acceptable choices, though no testing has been done on FreeBSD.
|
13
|
+
|
14
|
+
gem dependencies
|
15
|
+
------------
|
16
|
+
|
17
|
+
* rack
|
18
|
+
* ruby-dtrace
|
19
|
+
|
20
|
+
installing
|
21
|
+
----------
|
22
|
+
|
23
|
+
`gem sources -a http://gems.github.com`
|
24
|
+
|
25
|
+
`gem install ecin-rack-probe`
|
26
|
+
|
27
|
+
setup
|
28
|
+
-----
|
29
|
+
|
30
|
+
Rails Middleware:
|
31
|
+
|
32
|
+
_Inside your config/environment.rb_
|
33
|
+
|
34
|
+
`config.gem "ecin-rack-probe", :lib => "rack/probe"`
|
35
|
+
|
36
|
+
`config.middleware.use "Rack::Probe"`
|
37
|
+
|
38
|
+
Rack Middleware:
|
39
|
+
|
40
|
+
_Inside your rackup file_
|
41
|
+
|
42
|
+
`require 'rack/probe'`
|
43
|
+
`use Rack::Probe`
|
44
|
+
|
45
|
+
use
|
46
|
+
---
|
47
|
+
|
48
|
+
From a terminal, run `dtrace -n rack*::: -l` to get a list of all the available probes. The number you'll see after 'rack' in the provider field is the PID of the process that's making the probes available.
|
49
|
+
|
50
|
+
copyright
|
51
|
+
---------
|
52
|
+
|
53
|
+
Copyright (c) 2009 ecin. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-probe"
|
8
|
+
gem.summary = %Q{Rack::Probe adds Dtrace probes to your Rack apps.}
|
9
|
+
gem.description = %Q{Rack::Probe provides a set of probes for Rack that fire with each request.}
|
10
|
+
gem.email = "ecin@copypastel.com"
|
11
|
+
gem.homepage = "http://github.com/ecin/rack-probe"
|
12
|
+
gem.authors = ["ecin"]
|
13
|
+
gem.add_dependency "ruby-dtrace", ">= 0.2.8"
|
14
|
+
gem.add_dependency "rack", ">= 1.0.0"
|
15
|
+
gem.add_development_dependency "rspec"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION')
|
41
|
+
version = File.read('VERSION')
|
42
|
+
else
|
43
|
+
version = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rack-probe #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
data/lib/rack-probe.rb
ADDED
data/lib/rack/probe.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class Symbol
|
2
|
+
unless instance_methods.include? :to_proc
|
3
|
+
def to_proc
|
4
|
+
Proc.new { |obj, *args| obj.send(self, *args) }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Rack
|
10
|
+
class Probe
|
11
|
+
|
12
|
+
gem 'ruby-dtrace', '>= 0.2.7'
|
13
|
+
require 'dtrace/provider'
|
14
|
+
|
15
|
+
def initialize( app, opts = {} )
|
16
|
+
# Unless our probes are already defined...
|
17
|
+
unless Dtrace::Probe::Rack.instance_of? Dtrace::Provider::Klass
|
18
|
+
Dtrace::Provider.create :rack do |p|
|
19
|
+
p.probe :get # GET request
|
20
|
+
p.probe :post # POST request
|
21
|
+
p.probe :put # PUT request
|
22
|
+
p.probe :delete # DELETE request
|
23
|
+
p.probe :ip, :string # IP of the requester
|
24
|
+
p.probe :path, :string # Path visited
|
25
|
+
p.probe :referer, :string # Referer
|
26
|
+
p.probe :xhr # AJAX request
|
27
|
+
|
28
|
+
p.probe :request_start # Start of a request
|
29
|
+
p.probe :request_finish # End of a request
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Provider shortcut
|
34
|
+
@R = Dtrace::Probe::Rack
|
35
|
+
@app = app
|
36
|
+
end
|
37
|
+
|
38
|
+
def call( env )
|
39
|
+
@R.request_start(&:fire)
|
40
|
+
request = Rack::Request.new env
|
41
|
+
@R.get(&:fire) if request.get?
|
42
|
+
@R.post(&:fire) if request.post?
|
43
|
+
@R.put(&:fire) if request.put?
|
44
|
+
@R.delete(&:fire) if request.delete?
|
45
|
+
@R.xhr(&:fire) if request.xhr?
|
46
|
+
@R.path { |p| p.fire(request.path) }
|
47
|
+
@R.ip { |p| p.fire(request.ip) }
|
48
|
+
@R.referer { |p| p.fire(request.referer) }
|
49
|
+
response = @app.call(env)
|
50
|
+
@R.request_finish(&:fire)
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/rack-probe.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack-probe}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["ecin"]
|
12
|
+
s.date = %q{2009-08-21}
|
13
|
+
s.description = %q{Rack::Probe provides a set of probes for Rack that fire with each request.}
|
14
|
+
s.email = %q{ecin@copypastel.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rack-probe.rb",
|
27
|
+
"lib/rack/probe.rb",
|
28
|
+
"rack-probe.gemspec",
|
29
|
+
"spec/rack/probe_spec.rb",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/ecin/rack-probe}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
|
+
s.summary = %q{Rack::Probe adds Dtrace probes to your Rack apps.}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/rack/probe_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
48
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
52
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
57
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../spec_helper.rb')
|
2
|
+
|
3
|
+
require 'spec/interop/test'
|
4
|
+
require 'dtrace'
|
5
|
+
|
6
|
+
describe Rack::Probe do
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def app
|
10
|
+
a = lambda { [200, {'Content-Type' => 'text/html'},''] }
|
11
|
+
Rack::Probe.new(a)
|
12
|
+
end
|
13
|
+
|
14
|
+
def compile_script(script)
|
15
|
+
@compiler.compile(script).execute
|
16
|
+
@compiler.go
|
17
|
+
DtraceConsumer.new(@compiler)
|
18
|
+
end
|
19
|
+
|
20
|
+
class DtraceConsumer
|
21
|
+
def finished?
|
22
|
+
@done
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
@q = Proc.new {'hello'}
|
28
|
+
@compiler = Dtrace.new
|
29
|
+
@compiler.setopt('bufsize', '8m')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should fire a probe with a request\'s ip' do
|
33
|
+
Rack::Probe.new @q
|
34
|
+
consumer = compile_script ":::ip {trace(copyinstr((int) arg0));}"
|
35
|
+
get '/'
|
36
|
+
consumer.consume_once do |d|
|
37
|
+
record = d.data.first
|
38
|
+
record.value.should match(/.*\..*\..*\..*/)
|
39
|
+
consumer.finish
|
40
|
+
end
|
41
|
+
consumer.finished?.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should fire a probe with a request\'s path' do
|
45
|
+
consumer = compile_script ":::path {trace(copyinstr((int) arg0));}"
|
46
|
+
get '/'
|
47
|
+
consumer.consume_once do |d|
|
48
|
+
record = d.data.first
|
49
|
+
record.value.should eql('/')
|
50
|
+
consumer.finish
|
51
|
+
end
|
52
|
+
consumer.finished?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should fire a probe with a request\'s referer' do
|
56
|
+
consumer = compile_script ":::referer {trace(copyinstr((int) arg0));}"
|
57
|
+
get '/'
|
58
|
+
consumer.consume_once do |d|
|
59
|
+
record = d.data.first
|
60
|
+
record.value.should eql('/')
|
61
|
+
consumer.finish
|
62
|
+
end
|
63
|
+
consumer.finished?.should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should fire a probe when a request is a GET' do
|
67
|
+
consumer = compile_script ":::get {}"
|
68
|
+
get '/'
|
69
|
+
consumer.consume_once do |d|
|
70
|
+
d.probe.name.should eql('get')
|
71
|
+
consumer.finish
|
72
|
+
end
|
73
|
+
consumer.finished?.should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should fire a probe when a request is a POST' do
|
77
|
+
consumer = compile_script ":::post {}"
|
78
|
+
post '/'
|
79
|
+
consumer.consume_once do |d|
|
80
|
+
d.probe.name.should eql('post')
|
81
|
+
consumer.finish
|
82
|
+
end
|
83
|
+
consumer.finished?.should be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should fire a probe when a request is a PUTS' do
|
87
|
+
consumer = compile_script ":::put {}"
|
88
|
+
put '/'
|
89
|
+
consumer.consume_once do |d|
|
90
|
+
d.probe.name.should eql('put')
|
91
|
+
consumer.finish
|
92
|
+
end
|
93
|
+
consumer.finished?.should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should fire a probe when a request is a DELETE' do
|
97
|
+
consumer = compile_script ":::delete {}"
|
98
|
+
delete '/'
|
99
|
+
consumer.consume_once do |d|
|
100
|
+
d.probe.name.should eql('delete')
|
101
|
+
consumer.finish
|
102
|
+
end
|
103
|
+
consumer.finished?.should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should fire a probe when a request is a XHR' do
|
107
|
+
consumer = compile_script ":::xhr {}"
|
108
|
+
get '/', {}, { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" }
|
109
|
+
consumer.consume_once do |d|
|
110
|
+
d.probe.name.should eql('xhr')
|
111
|
+
consumer.finish
|
112
|
+
end
|
113
|
+
consumer.finished?.should be_true
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should fire a probe when a request is started' do
|
117
|
+
consumer = compile_script ":::request_start {}"
|
118
|
+
get '/'
|
119
|
+
consumer.consume_once do |d|
|
120
|
+
d.probe.name.should eql('request_start')
|
121
|
+
consumer.finish
|
122
|
+
end
|
123
|
+
consumer.finished?.should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should fire a probe when a request finishes' do
|
127
|
+
consumer = compile_script ":::request_finish {}"
|
128
|
+
get '/'
|
129
|
+
consumer.consume_once do |d|
|
130
|
+
d.probe.name.should eql('request_finish')
|
131
|
+
consumer.finish
|
132
|
+
end
|
133
|
+
consumer.finished?.should be_true
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack/probe'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/autorun'
|
8
|
+
|
9
|
+
# Be sure to run tests with sudo/as root, as it makes use of Dtrace
|
10
|
+
# consumers.
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-probe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ecin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-21 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby-dtrace
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.8
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: Rack::Probe provides a set of probes for Rack that fire with each request.
|
46
|
+
email: ecin@copypastel.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.markdown
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.markdown
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/rack-probe.rb
|
62
|
+
- lib/rack/probe.rb
|
63
|
+
- rack-probe.gemspec
|
64
|
+
- spec/rack/probe_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/ecin/rack-probe
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Rack::Probe adds Dtrace probes to your Rack apps.
|
94
|
+
test_files:
|
95
|
+
- spec/rack/probe_spec.rb
|
96
|
+
- spec/spec_helper.rb
|