rack-metrics 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Appraisals +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/lib/generators/rack/metrics/install/install_generator.rb +11 -0
- data/lib/rack/metrics.rb +162 -0
- data/lib/rack/metrics/config.rb +11 -0
- data/lib/rack/metrics/current.rb +13 -0
- data/lib/rack/metrics/instrumenter.rb +17 -0
- data/lib/rack/metrics/metrics.rb +50 -0
- data/lib/rack/metrics/middleware.rb +15 -0
- data/lib/rack/metrics/railtie.rb +9 -0
- data/lib/rack/metrics/version.rb +5 -0
- data/rack-metrics.gemspec +26 -0
- data/test/dummy/my_app.rb +69 -0
- data/test/support/classes/foo.rb +5 -0
- data/test/test_helper.rb +23 -0
- data/test/unit/metrics_test.rb +56 -0
- metadata +142 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 229ea3f24fb44bcfd2a753013f02d262f2d1b88c
|
|
4
|
+
data.tar.gz: 0f842673829178e085c9d90bc5e35c29a3546e1d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f65fc043491a22f916c527c15623b091d754ddedaab9658e6d5be72affbb6d6d6a5ae371297c400325b76b7e7f43d868a9a0305ee4c739364d634b59146456e1
|
|
7
|
+
data.tar.gz: 65839013596a8cfbb70d274df4db94321640597b9862fc6a3db6e6891de17e6487f8df8e74a134da96d65578bc867e13d81e9eadf0aef754fb5a956970c379e1
|
data/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
.DS_Store
|
|
19
|
+
test/dummy/log
|
|
20
|
+
log
|
|
21
|
+
gemfiles/*.lock
|
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rack-metrics
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.0.0-p353
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Greg Molnar
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Rack::Metrics
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/EvolutionSoft/rack-metrics)
|
|
4
|
+
|
|
5
|
+
TODO: Write a gem description
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'rack-metrics', github: 'EvolutionSoft/rack-metrics'
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
If you have a Rails application use the `rails g rack:metrics:install` command to generate the initializer.
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
1. Fork it
|
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
27
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module Metrics
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
desc "This generator creates an initializer file at config/initializers"
|
|
5
|
+
def create_initializer
|
|
6
|
+
create_file "config/initializers/rack-metrics.rb", "Rack::Metrics.config.api_key = 'api_key_goes_here'"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/rack/metrics.rb
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
require "rack/metrics/instrumenter"
|
|
2
|
+
require "rack/metrics/version"
|
|
3
|
+
require "rack/metrics/middleware"
|
|
4
|
+
require "rack/metrics/config"
|
|
5
|
+
require "rack/metrics/metrics"
|
|
6
|
+
require "rack/metrics/current"
|
|
7
|
+
require "rack/metrics/railtie" if defined? Rails
|
|
8
|
+
|
|
9
|
+
module Rack
|
|
10
|
+
module Metrics
|
|
11
|
+
def self.parse_stack(stack)
|
|
12
|
+
parsed = []
|
|
13
|
+
stack.each do |line|
|
|
14
|
+
line.gsub!("#{Rails.root}/", '')
|
|
15
|
+
if /^((?:app|config|lib|test).+?):(\d+)(?::in `(.*)')?/ =~ line
|
|
16
|
+
parsed<< line
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
parsed
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.subscribe
|
|
23
|
+
env = Rails.env || ENV['rack_env']
|
|
24
|
+
return unless Rack::Metrics.config.environments.include?(env.to_sym)
|
|
25
|
+
ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |*args|
|
|
26
|
+
Metrics.current = Event.new *args
|
|
27
|
+
Metrics.current.stack = Stack.new
|
|
28
|
+
Metrics.current.template = Event.new *args
|
|
29
|
+
|
|
30
|
+
ActiveSupport::Notifications.subscribe "render_template.action_view" do |name, time, finished, transaction_id, payload|
|
|
31
|
+
Metrics.current.template.name = name
|
|
32
|
+
Metrics.current.template.time = time
|
|
33
|
+
Metrics.current.template.end = finished
|
|
34
|
+
Metrics.current.template.transaction_id = transaction_id
|
|
35
|
+
Metrics.current.template.payload = payload
|
|
36
|
+
Metrics.current.template.payload[:identifier] = Metrics.current.template.payload[:identifier].gsub("#{Rails.root}/", '') unless Metrics.current.template.payload[:identifier].nil?
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
ActiveSupport::Notifications.subscribe "render_template.action_view" do |name, time, finished, transaction_id, payload|
|
|
41
|
+
Metrics.current.template.name = name
|
|
42
|
+
Metrics.current.template.time = time
|
|
43
|
+
Metrics.current.template.end = finished
|
|
44
|
+
Metrics.current.template.transaction_id = transaction_id
|
|
45
|
+
Metrics.current.template.payload = payload
|
|
46
|
+
Metrics.current.template.payload[:identifier] = Metrics.current.template.payload[:identifier].gsub("#{Rails.root}/", '') unless Metrics.current.template.payload[:identifier].nil?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
ActiveSupport::Notifications.subscribe "start_render_partial.action_view" do |*args|
|
|
50
|
+
# TODO: make it work with nested render partials
|
|
51
|
+
render_partial = Event.new *args
|
|
52
|
+
Metrics.current.stack<< render_partial
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
ActiveSupport::Notifications.subscribe "render_partial.action_view" do |*args|
|
|
56
|
+
render_partial = Metrics.current.stack.pop
|
|
57
|
+
render_partial.init *args
|
|
58
|
+
render_partial.payload[:identifier] = render_partial.payload[:identifier].gsub("#{Rails.root}/", '') unless render_partial.payload[:identifier].nil?
|
|
59
|
+
if Metrics.current.stack.empty?
|
|
60
|
+
Metrics.current.template.partials<< render_partial
|
|
61
|
+
else
|
|
62
|
+
Metrics.current.stack.peek.partials<< render_partial
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, time, finished, transaction_id, payload|
|
|
67
|
+
Metrics.current.name = name
|
|
68
|
+
Metrics.current.time = time
|
|
69
|
+
Metrics.current.end = finished
|
|
70
|
+
Metrics.current.transaction_id = transaction_id
|
|
71
|
+
Metrics.current.payload = payload
|
|
72
|
+
memory = `ps -o rss -p #{Process::pid}`.chomp.split("\n").last.strip.to_i / 1024
|
|
73
|
+
Metrics.current.payload['memory'] = memory.to_i
|
|
74
|
+
begin
|
|
75
|
+
data = Metrics.current.to_json
|
|
76
|
+
thread = Thread.new do
|
|
77
|
+
Metrics.push_data(data)
|
|
78
|
+
end
|
|
79
|
+
rescue Exception => e
|
|
80
|
+
Metrics.log("Rack-Metrics exception raised: #{e.inspect}")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
ActiveSupport::Notifications.subscribe "sql.active_record" do |*args|
|
|
85
|
+
sql = Event.new *args
|
|
86
|
+
if Metrics.current.is_a?(Rack::Metrics::Event)
|
|
87
|
+
unless sql.payload[:name] == 'SCHEMA'
|
|
88
|
+
sql.payload['stacktrace'] = Metrics.parse_stack(caller(2)).join("\r\n")
|
|
89
|
+
if Metrics.current.stack.empty?
|
|
90
|
+
Metrics.current.template.queries<< sql
|
|
91
|
+
else
|
|
92
|
+
Metrics.current.stack.peek.queries<< sql
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
Rack::Metrics::Instrumenter.instrument_method(ActionView::PartialRenderer, :render, "start_render_partial.action_view")
|
|
102
|
+
|
|
103
|
+
module Rack
|
|
104
|
+
module Metrics
|
|
105
|
+
class Event < ActiveSupport::Notifications::Event
|
|
106
|
+
attr_accessor :template, :queries, :partials, :name, :time, :end, :transaction_id, :payload, :stack
|
|
107
|
+
|
|
108
|
+
def initialize(name, start, ending, transaction_id, payload)
|
|
109
|
+
@queries = []
|
|
110
|
+
@partials = []
|
|
111
|
+
super(name, start, ending, transaction_id, payload)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def init(name, start, ending, transaction_id, payload)
|
|
115
|
+
@name = name
|
|
116
|
+
@payload = payload.dup
|
|
117
|
+
@time = start
|
|
118
|
+
@transaction_id = transaction_id
|
|
119
|
+
@end = ending
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def as_json(options={})
|
|
123
|
+
attrs = super(options)
|
|
124
|
+
attrs['duration'] = self.duration.round(2)
|
|
125
|
+
attrs.delete_if {|k, v| v.nil?}
|
|
126
|
+
attrs.delete_if {|k, v| v.respond_to?(:empty?) and v.empty? }
|
|
127
|
+
attrs
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class Stack
|
|
132
|
+
|
|
133
|
+
def initialize
|
|
134
|
+
@storage = []
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def push(e)
|
|
138
|
+
@storage.push e
|
|
139
|
+
end
|
|
140
|
+
alias_method :<<, :push
|
|
141
|
+
|
|
142
|
+
def pop
|
|
143
|
+
@storage.pop
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def peek
|
|
147
|
+
@storage.last
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def first
|
|
151
|
+
@storage.first
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def empty?
|
|
155
|
+
@storage.empty?
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module Metrics
|
|
3
|
+
class Instrumenter
|
|
4
|
+
def self.instrument_method(klass, method, name)
|
|
5
|
+
method_name = method.to_s.gsub(/[\?\!]/, "")
|
|
6
|
+
with_rack_metrics = ("#{method_name}_with_rack_metrics").to_sym
|
|
7
|
+
without_rack_metrics = ("#{method_name}_without_rack_metrics").to_sym
|
|
8
|
+
klass.send :alias_method, without_rack_metrics, method
|
|
9
|
+
klass.send :define_method, with_rack_metrics do |*args, &orig|
|
|
10
|
+
ActiveSupport::Notifications.instrument(name)
|
|
11
|
+
self.send without_rack_metrics, *args, &orig
|
|
12
|
+
end
|
|
13
|
+
klass.send :alias_method, method, with_rack_metrics
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
module Rack
|
|
4
|
+
module Metrics
|
|
5
|
+
class << self
|
|
6
|
+
attr_writer :config
|
|
7
|
+
attr_accessor :start_processing
|
|
8
|
+
|
|
9
|
+
def config
|
|
10
|
+
@config ||= Rack::Metrics::Config.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def current
|
|
14
|
+
Thread.current[:rack_metrics]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def current=(c)
|
|
18
|
+
Thread.current[:rack_metrics] = c
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def push_data(data)
|
|
22
|
+
@endpoint = 'https://rack-metrics.com/api/v1'
|
|
23
|
+
log("=> Pushing metrics data")
|
|
24
|
+
begin
|
|
25
|
+
uri = URI(@endpoint)
|
|
26
|
+
res = Net::HTTP.post_form(uri, 'api_key' => Rack::Metrics.config.api_key, 'api_version' => '1.1.0', 'data' => data)
|
|
27
|
+
rescue => e
|
|
28
|
+
log "=> Error while pushing metrics data: #{e.message}"
|
|
29
|
+
end
|
|
30
|
+
Metrics.current = nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def log(message)
|
|
34
|
+
begin
|
|
35
|
+
Rails.logger.info message
|
|
36
|
+
rescue
|
|
37
|
+
puts message
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def current
|
|
43
|
+
Metrics.current
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def current=(c)
|
|
47
|
+
Metrics.current = c
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'rack/metrics/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "rack-metrics"
|
|
8
|
+
spec.version = Rack::Metrics::VERSION
|
|
9
|
+
spec.authors = ["Greg Molnar"]
|
|
10
|
+
spec.email = ["molnargerg@gmail.com"]
|
|
11
|
+
spec.description = %q{rack-metrics is a performance monitoring tool.}
|
|
12
|
+
spec.summary = %q{A performance monitoring tool.}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency 'minitest', '>= 3'
|
|
23
|
+
spec.add_development_dependency 'sqlite3'
|
|
24
|
+
spec.add_development_dependency 'appraisal'
|
|
25
|
+
spec.add_development_dependency "rake"
|
|
26
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require "rails"
|
|
2
|
+
require 'rails/all'
|
|
3
|
+
require 'rack/metrics'
|
|
4
|
+
require 'action_view/testing/resolvers'
|
|
5
|
+
module MyApp
|
|
6
|
+
class Application < Rails::Application
|
|
7
|
+
config.root = File.expand_path("../../..", __FILE__)
|
|
8
|
+
config.cache_classes = true
|
|
9
|
+
|
|
10
|
+
config.eager_load = false
|
|
11
|
+
config.serve_static_assets = true
|
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
|
13
|
+
|
|
14
|
+
config.consider_all_requests_local = true
|
|
15
|
+
config.action_controller.perform_caching = false
|
|
16
|
+
|
|
17
|
+
config.action_dispatch.show_exceptions = false
|
|
18
|
+
|
|
19
|
+
config.action_controller.allow_forgery_protection = false
|
|
20
|
+
|
|
21
|
+
config.active_support.deprecation = :stderr
|
|
22
|
+
|
|
23
|
+
config.middleware.delete "Rack::Lock"
|
|
24
|
+
config.middleware.delete "ActionDispatch::Flash"
|
|
25
|
+
config.middleware.delete "ActionDispatch::BestStandardsSupport"
|
|
26
|
+
config.eager_load = false
|
|
27
|
+
config.secret_key_base = '49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk'
|
|
28
|
+
routes.append do
|
|
29
|
+
get "/:action" => "site#:action"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
Rack::Metrics.config.environments = [:internal_test]
|
|
34
|
+
class SiteController < ActionController::Base
|
|
35
|
+
include Rails.application.routes.url_helpers
|
|
36
|
+
layout 'application'
|
|
37
|
+
self.view_paths = [ActionView::FixtureResolver.new(
|
|
38
|
+
"site/simple.html.erb"=> 'Hello from simple.html.erb',
|
|
39
|
+
"site/with_query.html.erb"=> 'Hello from with_query.html.erb',
|
|
40
|
+
"site/with_partial_render.html.erb"=> 'Hello from with_partial_render.html.erb <%= render "comment" %>',
|
|
41
|
+
"site/with_partial_render_with_query.html.erb"=> 'Hello from with_partial_render.html.erb <%= render @comments %>',
|
|
42
|
+
"site/_comment.html.erb" => "Partial",
|
|
43
|
+
"site/_comment_with_query.html.erb" => "Partial <%= Comment.count %>",
|
|
44
|
+
"comments/_comment.html.erb" => "Comment partial",
|
|
45
|
+
"layouts/application.html.erb" => '<%= yield %>',
|
|
46
|
+
)]
|
|
47
|
+
|
|
48
|
+
def simple
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def with_query
|
|
52
|
+
post = Post.all.count
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def with_partial_render
|
|
56
|
+
post = Post.all.count
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def with_partial_render_with_query
|
|
60
|
+
post = Post.all.count
|
|
61
|
+
@comments = Comment.all
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def with_template_query
|
|
65
|
+
post = Post.all.count
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
MyApp::Application.initialize!
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "internal_test"
|
|
2
|
+
ENV['DATABASE_URL'] = 'sqlite3://localhost/:memory:'
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
require 'minitest/spec'
|
|
6
|
+
require "dummy/my_app"
|
|
7
|
+
require 'rails/test_help'
|
|
8
|
+
require 'rack/metrics'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Schema.define do
|
|
13
|
+
create_table :posts do |t|
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
create_table :comments do |t|
|
|
17
|
+
t.integer :post_id
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Post < ActiveRecord::Base; end
|
|
22
|
+
class Comment < ActiveRecord::Base; end
|
|
23
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'pp'
|
|
3
|
+
class MetricsTest < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
ActiveSupport::Notifications.instrument('start_processing.action_controller'){}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "it subscribes to start_processing.action_controller" do
|
|
9
|
+
assert_kind_of Rack::Metrics::Event, Rack::Metrics.current
|
|
10
|
+
assert_kind_of Rack::Metrics::Event, Rack::Metrics.current.template
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "it subscribes to sql.active_record" do
|
|
14
|
+
ActiveSupport::Notifications.instrument('sql.active_record'){}
|
|
15
|
+
refute_empty Rack::Metrics.current.template.queries
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test "it subscribes to render_template.action_view" do
|
|
19
|
+
ActiveSupport::Notifications.instrument('render_template.action_view'){}
|
|
20
|
+
refute_nil Rack::Metrics.current.template
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "it subscribes to render_partial.action_view" do
|
|
24
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
25
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view'){}
|
|
26
|
+
refute_empty Rack::Metrics.current.template.partials
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "it nests render_partial.action_view" do
|
|
30
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
31
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view') do
|
|
32
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
33
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view') do
|
|
34
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
35
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view'){}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
refute_empty Rack::Metrics.current.template.partials
|
|
39
|
+
assert_equal 1, Rack::Metrics.current.template.partials.count
|
|
40
|
+
refute_empty Rack::Metrics.current.template.partials[0].partials
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test "it adds query to nested render_partial.action_view" do
|
|
44
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
45
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view') do
|
|
46
|
+
ActiveSupport::Notifications.instrument('start_render_partial.action_view'){}
|
|
47
|
+
ActiveSupport::Notifications.instrument('sql.active_record'){}
|
|
48
|
+
ActiveSupport::Notifications.instrument('render_partial.action_view') do
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
refute_empty Rack::Metrics.current.template.partials
|
|
52
|
+
assert_equal 1, Rack::Metrics.current.template.partials.count
|
|
53
|
+
assert_equal 0, Rack::Metrics.current.template.queries.count
|
|
54
|
+
assert_equal 1, Rack::Metrics.current.template.partials[0].partials[0].queries.count
|
|
55
|
+
end
|
|
56
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rack-metrics
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Greg Molnar
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: minitest
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: sqlite3
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: appraisal
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: rack-metrics is a performance monitoring tool.
|
|
84
|
+
email:
|
|
85
|
+
- molnargerg@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- .gitignore
|
|
91
|
+
- .ruby-gemset
|
|
92
|
+
- .ruby-version
|
|
93
|
+
- .travis.yml
|
|
94
|
+
- Appraisals
|
|
95
|
+
- Gemfile
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- gemfiles/rails_4.gemfile
|
|
100
|
+
- lib/generators/rack/metrics/install/install_generator.rb
|
|
101
|
+
- lib/rack/metrics.rb
|
|
102
|
+
- lib/rack/metrics/config.rb
|
|
103
|
+
- lib/rack/metrics/current.rb
|
|
104
|
+
- lib/rack/metrics/instrumenter.rb
|
|
105
|
+
- lib/rack/metrics/metrics.rb
|
|
106
|
+
- lib/rack/metrics/middleware.rb
|
|
107
|
+
- lib/rack/metrics/railtie.rb
|
|
108
|
+
- lib/rack/metrics/version.rb
|
|
109
|
+
- rack-metrics.gemspec
|
|
110
|
+
- test/dummy/my_app.rb
|
|
111
|
+
- test/support/classes/foo.rb
|
|
112
|
+
- test/test_helper.rb
|
|
113
|
+
- test/unit/metrics_test.rb
|
|
114
|
+
homepage: ''
|
|
115
|
+
licenses:
|
|
116
|
+
- MIT
|
|
117
|
+
metadata: {}
|
|
118
|
+
post_install_message:
|
|
119
|
+
rdoc_options: []
|
|
120
|
+
require_paths:
|
|
121
|
+
- lib
|
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - '>='
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - '>='
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
requirements: []
|
|
133
|
+
rubyforge_project:
|
|
134
|
+
rubygems_version: 2.1.11
|
|
135
|
+
signing_key:
|
|
136
|
+
specification_version: 4
|
|
137
|
+
summary: A performance monitoring tool.
|
|
138
|
+
test_files:
|
|
139
|
+
- test/dummy/my_app.rb
|
|
140
|
+
- test/support/classes/foo.rb
|
|
141
|
+
- test/test_helper.rb
|
|
142
|
+
- test/unit/metrics_test.rb
|