newrelic_rpm 2.11.0.beta → 2.11.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/lib/new_relic/agent.rb +67 -43
- data/lib/new_relic/agent/agent.rb +34 -25
- data/lib/new_relic/agent/error_collector.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +1 -1
- data/lib/new_relic/local_environment.rb +2 -1
- data/lib/new_relic/version.rb +1 -1
- data/newrelic_rpm.gemspec +2 -2
- metadata +3 -3
data/lib/new_relic/agent.rb
CHANGED
@@ -31,8 +31,8 @@
|
|
31
31
|
#
|
32
32
|
# == Configuring the Agent
|
33
33
|
#
|
34
|
-
# All agent configuration is done in the <tt>newrelic.yml</tt> file.
|
35
|
-
# file is by default read from the +config+ directory of the
|
34
|
+
# All agent configuration is done in the <tt>newrelic.yml</tt> file.
|
35
|
+
# This file is by default read from the +config+ directory of the
|
36
36
|
# application root and is subsequently searched for in the application
|
37
37
|
# root directory, and then in a <tt>~/.newrelic</tt> directory
|
38
38
|
#
|
@@ -171,16 +171,17 @@ module NewRelic
|
|
171
171
|
# Call this to manually start the Agent in situations where the Agent does
|
172
172
|
# not auto-start.
|
173
173
|
#
|
174
|
-
# When the app environment loads, so does the Agent. However, the
|
175
|
-
# only connect to RPM if a web front-end is found. If
|
176
|
-
# ruby processes that don't use
|
177
|
-
#
|
174
|
+
# When the app environment loads, so does the Agent. However, the
|
175
|
+
# Agent will only connect to RPM if a web front-end is found. If
|
176
|
+
# you want to selectively monitor ruby processes that don't use
|
177
|
+
# web plugins, then call this method in your code and the Agent
|
178
|
+
# will fire up and start reporting to RPM.
|
178
179
|
#
|
179
|
-
# Options are passed in as overrides for values in the
|
180
|
-
# as app_name. In addition, the option +log+
|
181
|
-
# will be used instead of the standard
|
182
|
-
# the newrelic.yml section to use
|
183
|
-
# with an :env argument.
|
180
|
+
# Options are passed in as overrides for values in the
|
181
|
+
# newrelic.yml, such as app_name. In addition, the option +log+
|
182
|
+
# will take a logger that will be used instead of the standard
|
183
|
+
# file logger. The setting for the newrelic.yml section to use
|
184
|
+
# (ie, RAILS_ENV) can be overridden with an :env argument.
|
184
185
|
#
|
185
186
|
def manual_start(options={})
|
186
187
|
raise unless Hash === options
|
@@ -188,32 +189,52 @@ module NewRelic
|
|
188
189
|
end
|
189
190
|
|
190
191
|
# Register this method as a callback for processes that fork
|
191
|
-
# jobs.
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
|
196
|
-
|
192
|
+
# jobs.
|
193
|
+
#
|
194
|
+
# Pass <tt>:force_reconnect => true</tt> to force the agent to
|
195
|
+
# reconnect to the server and start a worker loop for sending
|
196
|
+
# data.
|
197
|
+
#
|
198
|
+
# If the master/parent connects to the agent prior to forking the
|
199
|
+
# agent in the forked process will use that agent_run. Otherwise
|
200
|
+
# the forked process will establish a new connection with the
|
201
|
+
# server.
|
202
|
+
#
|
203
|
+
# Use this especially when you fork the process to run background
|
204
|
+
# jobs or other work. If you are doing this with a web dispatcher
|
205
|
+
# that forks worker processes then you will need to force the
|
206
|
+
# agent to reconnect, which it won't do by default. Passenger and
|
207
|
+
# Unicorn are already handled, nothing special needed for them.
|
208
|
+
def after_fork(options={})
|
209
|
+
agent.after_fork(options)
|
197
210
|
end
|
211
|
+
|
212
|
+
# Clear out any unsent metric data.
|
213
|
+
def reset_stats
|
214
|
+
agent.reset_stats
|
215
|
+
end
|
216
|
+
|
198
217
|
# Shutdown the agent. Call this before exiting. Sends any queued data
|
199
218
|
# and kills the background thread.
|
200
219
|
def shutdown
|
201
220
|
agent.shutdown
|
202
221
|
end
|
203
222
|
|
204
|
-
# Add instrumentation files to the agent. The argument should be
|
205
|
-
# matching ruby scripts which will be executed at the time
|
206
|
-
# is loaded. Since instrumentation is not loaded
|
207
|
-
# running it's better to use this method to
|
208
|
-
# just loading the files directly,
|
223
|
+
# Add instrumentation files to the agent. The argument should be
|
224
|
+
# a glob matching ruby scripts which will be executed at the time
|
225
|
+
# instrumentation is loaded. Since instrumentation is not loaded
|
226
|
+
# when the agent is not running it's better to use this method to
|
227
|
+
# register instrumentation than just loading the files directly,
|
228
|
+
# although that probably also works.
|
209
229
|
def add_instrumentation file_pattern
|
210
230
|
NewRelic::Control.instance.add_instrumentation file_pattern
|
211
231
|
end
|
212
232
|
|
213
|
-
# This method sets the block sent to this method as a sql
|
214
|
-
# The block will be called with a single String SQL
|
215
|
-
# The method must return the obfuscated
|
216
|
-
# If chaining of obfuscators is required, use type =
|
233
|
+
# This method sets the block sent to this method as a sql
|
234
|
+
# obfuscator. The block will be called with a single String SQL
|
235
|
+
# statement to obfuscate. The method must return the obfuscated
|
236
|
+
# String SQL. If chaining of obfuscators is required, use type =
|
237
|
+
# :before or :after
|
217
238
|
#
|
218
239
|
# type = :before, :replace, :after
|
219
240
|
#
|
@@ -257,9 +278,9 @@ module NewRelic
|
|
257
278
|
end
|
258
279
|
end
|
259
280
|
|
260
|
-
# Cancel the collection of the current transaction in progress, if
|
261
|
-
# Only affects the transaction started on this thread once
|
262
|
-
# and before it has completed.
|
281
|
+
# Cancel the collection of the current transaction in progress, if
|
282
|
+
# any. Only affects the transaction started on this thread once
|
283
|
+
# it has started and before it has completed.
|
263
284
|
def abort_transaction!
|
264
285
|
# The class may not be loaded if the agent is disabled
|
265
286
|
if defined? NewRelic::Agent::Instrumentation::MetricFrame
|
@@ -267,10 +288,11 @@ module NewRelic
|
|
267
288
|
end
|
268
289
|
end
|
269
290
|
|
270
|
-
# Yield to the block without collecting any metrics or traces in
|
271
|
-
# subsequent calls. If executed recursively, will keep
|
272
|
-
# entry point and turn on tracing again after
|
273
|
-
# This uses the thread local
|
291
|
+
# Yield to the block without collecting any metrics or traces in
|
292
|
+
# any of the subsequent calls. If executed recursively, will keep
|
293
|
+
# track of the first entry point and turn on tracing again after
|
294
|
+
# leaving that block. This uses the thread local
|
295
|
+
# +newrelic_untrace+
|
274
296
|
def disable_all_tracing
|
275
297
|
agent.push_trace_execution_flag(false)
|
276
298
|
yield
|
@@ -283,9 +305,10 @@ module NewRelic
|
|
283
305
|
Thread.current[:newrelic_untraced].nil? || Thread.current[:newrelic_untraced].last != false
|
284
306
|
end
|
285
307
|
|
286
|
-
# Set a filter to be applied to errors that RPM will track.
|
287
|
-
#
|
288
|
-
# the original exception) or nil to ignore this
|
308
|
+
# Set a filter to be applied to errors that RPM will track. The
|
309
|
+
# block should evalute to the exception to track (which could be
|
310
|
+
# different from the original exception) or nil to ignore this
|
311
|
+
# exception.
|
289
312
|
#
|
290
313
|
# The block is yielded to with the exception to filter.
|
291
314
|
#
|
@@ -295,8 +318,8 @@ module NewRelic
|
|
295
318
|
agent.error_collector.ignore_error_filter(&block)
|
296
319
|
end
|
297
320
|
|
298
|
-
# Record the given error in RPM. It will be passed through the
|
299
|
-
# if there is one.
|
321
|
+
# Record the given error in RPM. It will be passed through the
|
322
|
+
# #ignore_error_filter if there is one.
|
300
323
|
#
|
301
324
|
# * <tt>exception</tt> is the exception which will be recorded
|
302
325
|
# Options:
|
@@ -322,13 +345,14 @@ module NewRelic
|
|
322
345
|
# and is now deprecated.
|
323
346
|
alias add_request_parameters add_custom_parameters #:nodoc:
|
324
347
|
|
325
|
-
# Yield to a block that is run with a database metric name
|
326
|
-
# the Database instrumentation will use this
|
327
|
-
# otherwise know about a model.
|
348
|
+
# Yield to a block that is run with a database metric name
|
349
|
+
# context. This means the Database instrumentation will use this
|
350
|
+
# for the metric name if it does not otherwise know about a model.
|
351
|
+
# This is re-entrant.
|
328
352
|
#
|
329
353
|
# * <tt>model</tt> is the DB model class
|
330
|
-
# * <tt>method</tt> is the name of the finder method or other
|
331
|
-
#
|
354
|
+
# * <tt>method</tt> is the name of the finder method or other
|
355
|
+
# method to identify the operation with.
|
332
356
|
def with_database_metric_name(model, method, &block)
|
333
357
|
if frame = NewRelic::Agent::Instrumentation::MetricFrame.current
|
334
358
|
frame.with_database_metric_name(model, method, &block)
|
@@ -19,6 +19,14 @@ module NewRelic
|
|
19
19
|
# the NewRelic hosted site.
|
20
20
|
|
21
21
|
PROTOCOL_VERSION = 8
|
22
|
+
# 14105: v8 (tag 2.10.3)
|
23
|
+
# (no v7)
|
24
|
+
# 10379: v6 (not tagged)
|
25
|
+
# 4078: v5 (tag 2.5.4)
|
26
|
+
# 2292: v4 (tag 2.3.6)
|
27
|
+
# 1754: v3 (tag 2.3.0)
|
28
|
+
# 534: v2 (shows up in 2.1.0, our first tag)
|
29
|
+
|
22
30
|
|
23
31
|
attr_reader :obfuscator
|
24
32
|
attr_reader :stats_engine
|
@@ -38,15 +46,15 @@ module NewRelic
|
|
38
46
|
end
|
39
47
|
|
40
48
|
# This method should be called in a forked process after a fork.
|
41
|
-
# It assumes the parent process
|
42
|
-
#
|
43
|
-
# the worker thread and sampler threads.
|
49
|
+
# It assumes the parent process initialized the agent, but does
|
50
|
+
# not assume the agent started.
|
44
51
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
52
|
+
# * It clears any metrics carried over from the parent process
|
53
|
+
# * Restarts the sampler thread if necessary
|
54
|
+
# * Initiates a new agent run and worker loop unless that was done
|
55
|
+
# in the parent process and +:force_reconnect+ is not true
|
48
56
|
#
|
49
|
-
def after_fork
|
57
|
+
def after_fork(options={})
|
50
58
|
|
51
59
|
# @connected gets false after we fail to connect or have an error
|
52
60
|
# connecting. @connected has nil if we haven't finished trying to connect.
|
@@ -62,7 +70,7 @@ module NewRelic
|
|
62
70
|
|
63
71
|
# Clear out stats that are left over from parent process
|
64
72
|
reset_stats
|
65
|
-
start_worker_thread
|
73
|
+
start_worker_thread(options[:force_reconnect])
|
66
74
|
@stats_engine.start_sampler_thread
|
67
75
|
end
|
68
76
|
|
@@ -215,6 +223,17 @@ module NewRelic
|
|
215
223
|
control.log! "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #$$"
|
216
224
|
control.log! "Agent Log found in #{NewRelic::Control.instance.log_file}" if NewRelic::Control.instance.log_file
|
217
225
|
end
|
226
|
+
|
227
|
+
# Clear out the metric data, errors, and transaction traces. Reset the histogram data.
|
228
|
+
def reset_stats
|
229
|
+
@stats_engine.reset_stats
|
230
|
+
@unsent_errors = []
|
231
|
+
@traces = nil
|
232
|
+
@unsent_timeslice_data = {}
|
233
|
+
@last_harvest_time = Time.now
|
234
|
+
@launch_time = Time.now
|
235
|
+
@histogram = NewRelic::Histogram.new(NewRelic::Control.instance.apdex_t / 10)
|
236
|
+
end
|
218
237
|
|
219
238
|
private
|
220
239
|
def collector
|
@@ -222,8 +241,7 @@ module NewRelic
|
|
222
241
|
end
|
223
242
|
|
224
243
|
# Try to launch the worker thread and connect to the server
|
225
|
-
def start_worker_thread
|
226
|
-
@worker_loop = WorkerLoop.new
|
244
|
+
def start_worker_thread(force_reconnect=false)
|
227
245
|
log.debug "Creating RPM worker thread."
|
228
246
|
@worker_thread = Thread.new do
|
229
247
|
begin
|
@@ -231,23 +249,25 @@ module NewRelic
|
|
231
249
|
# We try to connect. If this returns false that means
|
232
250
|
# the server rejected us for a licensing reason and we should
|
233
251
|
# just exit the thread. If it returns nil
|
234
|
-
# that means it didn't try to connect because we're in the master
|
235
|
-
connect if
|
252
|
+
# that means it didn't try to connect because we're in the master.
|
253
|
+
connect if !@connected or force_reconnect
|
236
254
|
if @connected
|
237
255
|
# disable transaction sampling if disabled by the server and we're not in dev mode
|
238
256
|
if !control.developer_mode? && !@should_send_samples
|
239
257
|
@transaction_sampler.disable
|
240
258
|
end
|
241
|
-
|
259
|
+
log.info "Reporting performance data every #{@report_period} seconds."
|
242
260
|
log.debug "Running worker loop"
|
243
261
|
# note if the agent attempts to report more frequently than allowed by the server
|
244
262
|
# the server will start dropping data.
|
263
|
+
@worker_loop = WorkerLoop.new
|
245
264
|
@worker_loop.run(@report_period) do
|
246
265
|
harvest_and_send_timeslice_data
|
247
266
|
harvest_and_send_slowest_sample if @should_send_samples
|
248
267
|
harvest_and_send_errors if error_collector.enabled
|
249
268
|
end
|
250
|
-
|
269
|
+
else
|
270
|
+
log.debug "No connection. Worker thread finished."
|
251
271
|
end
|
252
272
|
end
|
253
273
|
rescue NewRelic::Agent::ForceRestartException => e
|
@@ -309,8 +329,6 @@ module NewRelic
|
|
309
329
|
# connection is made, or the server rejects us.
|
310
330
|
|
311
331
|
def connect(keep_retrying = true)
|
312
|
-
# Don't reconnect if we've already got a connection.
|
313
|
-
return if @connected
|
314
332
|
|
315
333
|
# wait a few seconds for the web server to boot, necessary in development
|
316
334
|
connect_retry_period = keep_retrying ? 10 : 0
|
@@ -403,15 +421,6 @@ module NewRelic
|
|
403
421
|
def determine_home_directory
|
404
422
|
control.root
|
405
423
|
end
|
406
|
-
def reset_stats
|
407
|
-
@stats_engine.reset_stats
|
408
|
-
@unsent_errors = []
|
409
|
-
@traces = nil
|
410
|
-
@unsent_timeslice_data = {}
|
411
|
-
@last_harvest_time = Time.now
|
412
|
-
@launch_time = Time.now
|
413
|
-
@histogram = NewRelic::Histogram.new(NewRelic::Control.instance.apdex_t / 10)
|
414
|
-
end
|
415
424
|
|
416
425
|
def harvest_and_send_timeslice_data
|
417
426
|
|
@@ -11,7 +11,7 @@ if defined?(PhusionPassenger)
|
|
11
11
|
# We want to reset the stats from the stats engine in case any carried
|
12
12
|
# over into the spawned process. Don't clear them in case any were
|
13
13
|
# cached.
|
14
|
-
NewRelic::Agent.after_fork
|
14
|
+
NewRelic::Agent.after_fork(:force_reconnect => true)
|
15
15
|
else
|
16
16
|
# We're in conservative spawning mode. We don't need to do anything.
|
17
17
|
end
|
@@ -3,7 +3,7 @@ if defined?(Unicorn::HttpServer)
|
|
3
3
|
NewRelic::Agent.logger.debug "Installing Unicorn worker hook."
|
4
4
|
old_worker_loop = instance_method(:worker_loop)
|
5
5
|
define_method(:worker_loop) do | worker |
|
6
|
-
NewRelic::Agent.after_fork
|
6
|
+
NewRelic::Agent.after_fork(:force_reconnect => true)
|
7
7
|
old_worker_loop.bind(self).call(worker)
|
8
8
|
end
|
9
9
|
end
|
@@ -79,7 +79,8 @@ module NewRelic
|
|
79
79
|
append_environment_value 'Framework', @framework.to_s
|
80
80
|
append_environment_value 'Dispatcher', @dispatcher.to_s if @dispatcher
|
81
81
|
append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
|
82
|
-
|
82
|
+
# This just creates a lot of keys
|
83
|
+
# append_environment_value('Application root') { File.expand_path(NewRelic::Control.instance.root) }
|
83
84
|
append_environment_value('Ruby version'){ RUBY_VERSION }
|
84
85
|
append_environment_value('Ruby description'){ RUBY_DESCRIPTION } if defined? ::RUBY_DESCRIPTION
|
85
86
|
append_environment_value('Ruby platform') { RUBY_PLATFORM }
|
data/lib/new_relic/version.rb
CHANGED
@@ -4,7 +4,7 @@ module NewRelic
|
|
4
4
|
MAJOR = 2
|
5
5
|
MINOR = 11
|
6
6
|
TINY = 0
|
7
|
-
BUILD = '
|
7
|
+
BUILD = 'beta2' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
|
8
8
|
STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
|
9
9
|
end
|
10
10
|
|
data/newrelic_rpm.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{newrelic_rpm}
|
8
|
-
s.version = "2.11.0.
|
8
|
+
s.version = "2.11.0.beta2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bill Kayser"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-29}
|
13
13
|
s.description = %q{New Relic RPM is a Ruby performance management system, developed by
|
14
14
|
New Relic, Inc (http://www.newrelic.com). RPM provides you with deep
|
15
15
|
information about the performance of your Ruby on Rails or Merb
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 2
|
7
7
|
- 11
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.11.0.
|
9
|
+
- beta2
|
10
|
+
version: 2.11.0.beta2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Kayser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-29 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|