scout_rails 0.0.2 → 0.0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown
CHANGED
data/lib/scout_rails/agent.rb
CHANGED
@@ -22,10 +22,6 @@ module ScoutRails
|
|
22
22
|
attr_accessor :options # options passed to the agent when +#start+ is called.
|
23
23
|
attr_accessor :metric_lookup # Hash used to lookup metric ids based on their name and scope
|
24
24
|
|
25
|
-
# Hash of class (values are Sets of method names) that should be instrumented by examining
|
26
|
-
# the ActiveRecord call stack.
|
27
|
-
attr_accessor :dynamic_instruments
|
28
|
-
|
29
25
|
# All access to the agent is thru this class method to ensure multiple Agent instances are not initialized per-Ruby process.
|
30
26
|
def self.instance(options = {})
|
31
27
|
@@instance ||= self.new(options)
|
@@ -40,7 +36,6 @@ module ScoutRails
|
|
40
36
|
@store = ScoutRails::Store.new
|
41
37
|
@layaway = ScoutRails::Layaway.new
|
42
38
|
@config = ScoutRails::Config.new(options[:config_path])
|
43
|
-
@dynamic_instruments = Hash.new
|
44
39
|
@metric_lookup = Hash.new
|
45
40
|
@process_cpu=ScoutRails::Instruments::Process::ProcessCpu.new(1) # TODO: the argument is the number of processors
|
46
41
|
@process_memory=ScoutRails::Instruments::Process::ProcessMemory.new
|
@@ -134,22 +129,6 @@ module ScoutRails
|
|
134
129
|
60
|
135
130
|
end
|
136
131
|
|
137
|
-
# Every time the worker thread completes, it calls this method
|
138
|
-
# to add instruments to selected methods in the AR call stack.
|
139
|
-
def add_dynamic_instruments
|
140
|
-
dynamic_instruments.each do |class_name,to_instrument|
|
141
|
-
klass = class_name.constantize
|
142
|
-
klass.class_eval do
|
143
|
-
if !klass.respond_to?(:instrument_method)
|
144
|
-
include ::ScoutRails::Tracer
|
145
|
-
end
|
146
|
-
to_instrument.each do |m|
|
147
|
-
self.instrument_method(m)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
132
|
# Creates the worker thread. The worker thread is a loop that runs continuously. It sleeps for +Agent#period+ and when it wakes,
|
154
133
|
# processes data, either saving it to disk or reporting to Scout.
|
155
134
|
def start_worker_thread(connection_options = {})
|
@@ -166,7 +145,6 @@ module ScoutRails
|
|
166
145
|
now = Time.now
|
167
146
|
end
|
168
147
|
process_metrics
|
169
|
-
add_dynamic_instruments
|
170
148
|
while next_time <= now
|
171
149
|
next_time += period
|
172
150
|
end
|
@@ -20,29 +20,9 @@ module ScoutRails::Instruments
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
# Searches for the first AR model in the call stack. If found, adds it to a Hash of
|
24
|
-
# classes and methods to later instrument. Used to provide a better breakdown.
|
25
|
-
def scout_instrument_caller(called)
|
26
|
-
model_call = called.find { |call| call =~ /\/app\/models\/(.+)\.rb:\d+:in `(.+)'/ }
|
27
|
-
if model_call and !model_call.include?("without_scout_instrument")
|
28
|
-
set=ScoutRails::Agent.instance.dynamic_instruments[$1.camelcase] || Set.new
|
29
|
-
ScoutRails::Agent.instance.dynamic_instruments[$1.camelcase] = (set << $2)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Only instrument the caller if dynamic_instruments isn't disabled. By default, it is enabled.
|
34
|
-
def scout_dynamic?
|
35
|
-
dynamic=ScoutRails::Agent.instance.config.settings['dynamic_instruments']
|
36
|
-
dynamic.nil? or dynamic
|
37
|
-
end
|
38
|
-
|
39
23
|
def scout_ar_metric_name(sql,name)
|
40
24
|
if name && (parts = name.split " ") && parts.size == 2
|
41
25
|
model = parts.first
|
42
|
-
# samples 10% of calls
|
43
|
-
if scout_dynamic? and rand*10 < 1
|
44
|
-
scout_instrument_caller(caller(10)[0..9]) # for performance, limits the number of call stack items to examine
|
45
|
-
end
|
46
26
|
operation = parts.last.downcase
|
47
27
|
metric_name = case operation
|
48
28
|
when 'load' then 'find'
|
@@ -74,7 +54,6 @@ def add_instruments
|
|
74
54
|
ActiveRecord::Base.class_eval do
|
75
55
|
include ::ScoutRails::Tracer
|
76
56
|
end
|
77
|
-
ScoutRails::Agent.instance.logger.debug "Dynamic instrumention is #{ActiveRecord::Base.connection.scout_dynamic? ? 'enabled' : 'disabled'}"
|
78
57
|
end
|
79
58
|
end
|
80
59
|
|
data/lib/scout_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Derek Haynes
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-16 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.
|
@@ -60,9 +60,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
|
-
- - ! '
|
63
|
+
- - ! '>'
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
65
|
+
version: 1.3.1
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project: scout_rails
|
68
68
|
rubygems_version: 1.8.10
|