scout_rails 1.0.8 → 1.0.9

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/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ ./**/.DS_Store
1
2
  *.gem
2
3
  .bundle
3
4
  Gemfile.lock
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.9
2
+
3
+ * Rainbows! app server support.
4
+ * Removed undocumented Sinatra support.
5
+ * Limiting metric hash size to 1000 to prevent a metric explosion.
6
+
1
7
  # 1.0.8
2
8
 
3
9
  * Processing metrics when a process starts + exits to prevent losing in-memory metrics on process exit.
@@ -10,6 +10,7 @@ module ScoutRails
10
10
  metrics = layaway.deposit_and_deliver
11
11
  if metrics.any?
12
12
  add_metric_ids(metrics)
13
+ logger.warn "Some data may be lost - metric size is at limit" if metrics.size == ScoutRails::Store::MAX_SIZE
13
14
  # for debugging, count the total number of requests
14
15
  controller_count = 0
15
16
  metrics.each do |meta,stats|
@@ -67,6 +67,7 @@ module ScoutRails
67
67
  logger.debug "Not starting worker thread"
68
68
  install_passenger_events if environment.app_server == :passenger
69
69
  install_unicorn_worker_loop if environment.app_server == :unicorn
70
+ install_rainbows_worker_loop if environment.app_server == :rainbows
70
71
  return
71
72
  end
72
73
  start_background_worker
@@ -143,6 +144,17 @@ module ScoutRails
143
144
  end
144
145
  end
145
146
 
147
+ def install_rainbows_worker_loop
148
+ logger.debug "Installing Rainbows worker loop."
149
+ Rainbows::HttpServer.class_eval do
150
+ old = instance_method(:worker_loop)
151
+ define_method(:worker_loop) do |worker|
152
+ ScoutRails::Agent.instance.start_background_worker
153
+ old.bind(self).call(worker)
154
+ end
155
+ end
156
+ end
157
+
146
158
  # Creates the worker thread. The worker thread is a loop that runs continuously. It sleeps for +Agent#period+ and when it wakes,
147
159
  # processes data, either saving it to disk or reporting to Scout.
148
160
  def start_background_worker
@@ -184,8 +196,6 @@ module ScoutRails
184
196
  require File.expand_path(File.join(File.dirname(__FILE__),'instruments/rails/action_controller_instruments.rb'))
185
197
  when :rails3
186
198
  require File.expand_path(File.join(File.dirname(__FILE__),'instruments/rails3/action_controller_instruments.rb'))
187
- when :sinatra
188
- require File.expand_path(File.join(File.dirname(__FILE__),'instruments/sinatra_instruments.rb'))
189
199
  end
190
200
  require File.expand_path(File.join(File.dirname(__FILE__),'instruments/active_record_instruments.rb'))
191
201
  require File.expand_path(File.join(File.dirname(__FILE__),'instruments/net_http.rb'))
@@ -55,6 +55,7 @@ module ScoutRails
55
55
  @app_server ||= if thin? then :thin
56
56
  elsif passenger? then :passenger
57
57
  elsif webrick? then :webrick
58
+ elsif rainbows? then :rainbows
58
59
  elsif unicorn? then :unicorn
59
60
  else nil
60
61
  end
@@ -80,6 +81,12 @@ module ScoutRails
80
81
  def webrick?
81
82
  defined?(::WEBrick) && defined?(::WEBrick::VERSION)
82
83
  end
84
+
85
+ def rainbows?
86
+ if defined?(::Rainbows) && defined?(::Rainbows::HttpServer)
87
+ ObjectSpace.each_object(::Rainbows::HttpServer) { |x| return true }
88
+ end
89
+ end
83
90
 
84
91
  def unicorn?
85
92
  if defined?(::Unicorn) && defined?(::Unicorn::HttpServer)
@@ -91,7 +98,7 @@ module ScoutRails
91
98
  # If forking, don't start worker thread in the master process. Since it's started as a Thread, it won't survive
92
99
  # the fork.
93
100
  def forking?
94
- passenger? or unicorn?
101
+ passenger? or unicorn? or rainbows?
95
102
  end
96
103
 
97
104
  ### ruby checks
@@ -1,6 +1,10 @@
1
1
  # The store encapsolutes the logic that (1) saves instrumented data by Metric name to memory and (2) maintains a stack (just an Array)
2
2
  # of instrumented methods that are being called. It's accessed via +ScoutRails::Agent.instance.store+.
3
3
  class ScoutRails::Store
4
+
5
+ # Limits the size of the metric hash to prevent a metric explosion.
6
+ MAX_SIZE = 1000
7
+
4
8
  attr_accessor :metric_hash
5
9
  attr_accessor :transaction_hash
6
10
  attr_accessor :stack
@@ -142,7 +146,7 @@ class ScoutRails::Store
142
146
  old_data.each do |old_meta,old_stats|
143
147
  if stats = metric_hash[old_meta]
144
148
  metric_hash[old_meta] = stats.combine!(old_stats)
145
- else
149
+ elsif metric_hash.size < MAX_SIZE
146
150
  metric_hash[old_meta] = old_stats
147
151
  end
148
152
  end
@@ -1,3 +1,3 @@
1
1
  module ScoutRails
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-03 00:00:00.000000000 Z
13
+ date: 2012-12-11 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Monitors a Ruby on Rails application and reports detailed metrics on
16
16
  performance to Scout, a hosted monitoring service.
@@ -20,7 +20,6 @@ executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
- - .DS_Store
24
23
  - .gitignore
25
24
  - CHANGELOG.markdown
26
25
  - Gemfile
@@ -41,7 +40,6 @@ files:
41
40
  - lib/scout_rails/instruments/process/process_memory.rb
42
41
  - lib/scout_rails/instruments/rails/action_controller_instruments.rb
43
42
  - lib/scout_rails/instruments/rails3/action_controller_instruments.rb
44
- - lib/scout_rails/instruments/sinatra_instruments.rb
45
43
  - lib/scout_rails/layaway.rb
46
44
  - lib/scout_rails/layaway_file.rb
47
45
  - lib/scout_rails/metric_meta.rb
data/.DS_Store DELETED
Binary file
@@ -1,41 +0,0 @@
1
- module ScoutRails::Instruments
2
- module SinatraInstruments
3
- def dispatch_with_scout_instruments!
4
- scout_controller_action = "Controller/Sinatra/#{scout_sinatra_controller_name(@request)}"
5
- self.class.trace(scout_controller_action, :uri => @request.path_info) do
6
- dispatch_without_scout_instruments!
7
- end
8
- end
9
-
10
- # Iterates through the app's routes, returning the matched route that the request should be
11
- # grouped under for the metric name.
12
- #
13
- # If not found, "unknown" is returned. This prevents a metric explosion.
14
- #
15
- # Nice to have: substitute the param pattern (([^/?#]+)) w/the named key (the +key+ param of the block).
16
- def scout_sinatra_controller_name(request)
17
- name = 'unknown'
18
- verb = request.request_method if request && request.respond_to?(:request_method)
19
- Array(self.class.routes[verb]).each do |pattern, keys, conditions, block|
20
- if pattern = process_route(pattern, keys, conditions) { pattern.source }
21
- name = pattern
22
- end
23
- end
24
- name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1')
25
- if verb
26
- name = [verb,name].join(' ')
27
- end
28
- name
29
- end
30
- end # SinatraInstruments
31
- end # ScoutRails::Instruments
32
-
33
- if defined?(::Sinatra) && defined?(::Sinatra::Base) && Sinatra::Base.private_method_defined?(:dispatch!)
34
- ScoutRails::Agent.instance.logger.debug "Instrumenting Sinatra"
35
- ::Sinatra::Base.class_eval do
36
- include ScoutRails::Tracer
37
- include ::ScoutRails::Instruments::SinatraInstruments
38
- alias dispatch_without_scout_instruments! dispatch!
39
- alias dispatch! dispatch_with_scout_instruments!
40
- end
41
- end