newrelic_rpm 2.13.0.beta5 → 2.13.1

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.

Files changed (86) hide show
  1. data/CHANGELOG +4 -0
  2. data/lib/new_relic/agent.rb +50 -50
  3. data/lib/new_relic/agent/agent.rb +24 -19
  4. data/lib/new_relic/agent/busy_calculator.rb +22 -22
  5. data/lib/new_relic/agent/chained_call.rb +3 -3
  6. data/lib/new_relic/agent/error_collector.rb +19 -19
  7. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +11 -11
  8. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
  9. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +43 -43
  10. data/lib/new_relic/agent/instrumentation/data_mapper.rb +6 -6
  11. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  12. data/lib/new_relic/agent/instrumentation/memcache.rb +8 -8
  13. data/lib/new_relic/agent/instrumentation/merb/controller.rb +4 -4
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +307 -303
  15. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +8 -8
  16. data/lib/new_relic/agent/instrumentation/rack.rb +2 -2
  17. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +10 -10
  18. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
  20. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +5 -5
  22. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  23. data/lib/new_relic/agent/method_tracer.rb +55 -55
  24. data/lib/new_relic/agent/sampler.rb +42 -38
  25. data/lib/new_relic/agent/samplers/cpu_sampler.rb +4 -4
  26. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +7 -7
  27. data/lib/new_relic/agent/samplers/memory_sampler.rb +11 -11
  28. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  29. data/lib/new_relic/agent/shim_agent.rb +20 -16
  30. data/lib/new_relic/agent/stats_engine.rb +3 -3
  31. data/lib/new_relic/agent/stats_engine/metric_stats.rb +28 -28
  32. data/lib/new_relic/agent/stats_engine/samplers.rb +16 -16
  33. data/lib/new_relic/agent/stats_engine/transactions.rb +25 -25
  34. data/lib/new_relic/agent/transaction_sampler.rb +68 -69
  35. data/lib/new_relic/agent/worker_loop.rb +13 -13
  36. data/lib/new_relic/collection_helper.rb +6 -6
  37. data/lib/new_relic/command.rb +14 -14
  38. data/lib/new_relic/commands/deployments.rb +19 -19
  39. data/lib/new_relic/commands/install.rb +25 -15
  40. data/lib/new_relic/control.rb +25 -25
  41. data/lib/new_relic/control/configuration.rb +17 -17
  42. data/lib/new_relic/control/frameworks/external.rb +3 -3
  43. data/lib/new_relic/control/frameworks/merb.rb +6 -6
  44. data/lib/new_relic/control/frameworks/rails.rb +17 -17
  45. data/lib/new_relic/control/frameworks/rails3.rb +11 -27
  46. data/lib/new_relic/control/frameworks/ruby.rb +6 -6
  47. data/lib/new_relic/control/frameworks/sinatra.rb +4 -4
  48. data/lib/new_relic/control/instrumentation.rb +8 -8
  49. data/lib/new_relic/control/logging_methods.rb +13 -13
  50. data/lib/new_relic/control/profiling.rb +2 -2
  51. data/lib/new_relic/control/server_methods.rb +17 -17
  52. data/lib/new_relic/delayed_job_injection.rb +1 -1
  53. data/lib/new_relic/histogram.rb +73 -71
  54. data/lib/new_relic/local_environment.rb +45 -45
  55. data/lib/new_relic/merbtasks.rb +1 -1
  56. data/lib/new_relic/metric_data.rb +5 -5
  57. data/lib/new_relic/metric_parser.rb +22 -22
  58. data/lib/new_relic/metric_parser/action_mailer.rb +4 -4
  59. data/lib/new_relic/metric_parser/active_merchant.rb +8 -8
  60. data/lib/new_relic/metric_parser/active_record.rb +2 -2
  61. data/lib/new_relic/metric_parser/apdex.rb +86 -51
  62. data/lib/new_relic/metric_parser/controller.rb +10 -10
  63. data/lib/new_relic/metric_parser/controller_cpu.rb +5 -5
  64. data/lib/new_relic/metric_parser/errors.rb +1 -1
  65. data/lib/new_relic/metric_parser/external.rb +3 -3
  66. data/lib/new_relic/metric_parser/mem_cache.rb +2 -2
  67. data/lib/new_relic/metric_parser/other_transaction.rb +7 -7
  68. data/lib/new_relic/metric_parser/view.rb +5 -5
  69. data/lib/new_relic/metric_parser/web_frontend.rb +1 -1
  70. data/lib/new_relic/metric_parser/web_service.rb +1 -1
  71. data/lib/new_relic/metric_spec.rb +13 -13
  72. data/lib/new_relic/noticed_error.rb +4 -4
  73. data/lib/new_relic/rack/developer_mode.rb +33 -33
  74. data/lib/new_relic/rack/metric_app.rb +2 -2
  75. data/lib/new_relic/recipes.rb +9 -9
  76. data/lib/new_relic/stats.rb +57 -57
  77. data/lib/new_relic/timer_lib.rb +2 -2
  78. data/lib/new_relic/transaction_analysis.rb +19 -19
  79. data/lib/new_relic/transaction_sample.rb +101 -101
  80. data/lib/new_relic/url_rule.rb +3 -3
  81. data/lib/new_relic/version.rb +10 -10
  82. data/lib/newrelic_rpm.rb +6 -4
  83. data/lib/tasks/all.rb +1 -1
  84. data/newrelic_rpm.gemspec +3 -3
  85. data/test/new_relic/rack/episodes_test.rb +1 -0
  86. metadata +24 -42
@@ -1,6 +1,6 @@
1
1
  # When installed as a plugin this is loaded automatically.
2
2
  #
3
- # When installed as a gem, you need to add
3
+ # When installed as a gem, you need to add
4
4
  # require 'new_relic/recipes'
5
5
  # to your deploy.rb
6
6
  #
@@ -9,10 +9,10 @@
9
9
  # If it fails, it will not affect the task execution or do a rollback.
10
10
  #
11
11
  make_notify_task = lambda do
12
-
12
+
13
13
  namespace :newrelic do
14
-
15
- # on all deployments, notify RPM
14
+
15
+ # on all deployments, notify RPM
16
16
  desc "Record a deployment in New Relic RPM (rpm.newrelic.com)"
17
17
  task :notice_deployment, :roles => :app, :except => {:no_release => true } do
18
18
  rails_env = fetch(:newrelic_rails_env, fetch(:rails_env, "production"))
@@ -22,7 +22,7 @@ make_notify_task = lambda do
22
22
  # if it doesn't work. Problem is that I don't know what directory the .git is
23
23
  # in when using git. I could possibly use the remote cache but i don't know
24
24
  # if that's always there.
25
- =begin
25
+ =begin
26
26
  run "cd #{current_release}; #{log_command}" do | io, stream_id, output |
27
27
  changelog = output
28
28
  end
@@ -42,13 +42,13 @@ make_notify_task = lambda do
42
42
  end
43
43
  changelog = `#{log_command}`
44
44
  end
45
- new_revision = rev || source.query_revision(source.head()) do |cmd|
45
+ new_revision = rev || source.query_revision(source.head()) do |cmd|
46
46
  logger.debug "executing locally: '#{cmd}'"
47
- `#{cmd}`
47
+ `#{cmd}`
48
48
  end
49
49
  deploy_options = { :environment => rails_env,
50
50
  :revision => new_revision,
51
- :changelog => changelog,
51
+ :changelog => changelog,
52
52
  :description => description,
53
53
  :appname => appname }
54
54
  logger.debug "Uploading deployment to New Relic"
@@ -79,4 +79,4 @@ else
79
79
  else
80
80
  make_notify_task.call
81
81
  end
82
- end
82
+ end
@@ -1,23 +1,23 @@
1
1
 
2
2
  module NewRelic
3
3
  module Stats
4
-
4
+
5
5
  def absent?
6
6
  # guess on absent values
7
7
  call_count == 0
8
- end
8
+ end
9
9
 
10
10
  def time_str(value_ms)
11
11
  case
12
- when value_ms >= 10000
12
+ when value_ms >= 10000
13
13
  "%.1f s" % (value_ms / 1000.0)
14
- when value_ms >= 5000
14
+ when value_ms >= 5000
15
15
  "%.2f s" % (value_ms / 1000.0)
16
16
  else
17
17
  "%.0f ms" % value_ms
18
18
  end
19
19
  end
20
-
20
+
21
21
  def average_call_time
22
22
  return 0 if call_count == 0
23
23
  total_call_time / call_count
@@ -55,15 +55,15 @@ module NewRelic
55
55
  self.begin_time = s.begin_time if s.begin_time.to_f < begin_time.to_f || begin_time.to_f == 0.0
56
56
  self.end_time = s.end_time if s.end_time.to_f > end_time.to_f
57
57
  end
58
-
58
+
59
59
  self
60
60
  end
61
-
61
+
62
62
  def merge(other_stats)
63
63
  stats = self.clone
64
64
  stats.merge! other_stats
65
65
  end
66
-
66
+
67
67
  # split into an array of timeslices whose
68
68
  # time boundaries start on (begin_time + (n * duration)) and whose
69
69
  # end time ends on (begin_time * (n + 1) * duration), except for the
@@ -78,7 +78,7 @@ module NewRelic
78
78
  current_end_time = rollup_begin_time + rollup_period
79
79
 
80
80
  return [self] if current_end_time >= self.end_time
81
-
81
+
82
82
  timeslices = []
83
83
  while current_end_time < self.end_time do
84
84
  ts = yield(current_begin_time, current_end_time)
@@ -89,7 +89,7 @@ module NewRelic
89
89
  current_begin_time = current_end_time
90
90
  current_end_time = current_begin_time + rollup_period
91
91
  end
92
-
92
+
93
93
  if self.end_time > current_begin_time
94
94
  percentage = rollup_period / self.duration + (self.begin_time - rollup_begin_time) / rollup_period
95
95
  ts = yield(current_begin_time, self.end_time)
@@ -98,14 +98,14 @@ module NewRelic
98
98
  timeslices << ts
99
99
  end
100
100
  end
101
-
101
+
102
102
  timeslices
103
103
  end
104
-
104
+
105
105
  def is_reset?
106
106
  call_count == 0 && total_call_time == 0.0 && total_exclusive_time == 0.0
107
107
  end
108
-
108
+
109
109
  def reset
110
110
  self.call_count = 0
111
111
  self.total_call_time = 0.0
@@ -116,12 +116,12 @@ module NewRelic
116
116
  self.begin_time = Time.at(0)
117
117
  self.end_time = Time.at(0)
118
118
  end
119
-
119
+
120
120
  def as_percentage_of(other_stats)
121
121
  return 0 if other_stats.total_call_time == 0
122
122
  return (total_call_time / other_stats.total_call_time) * 100.0
123
123
  end
124
-
124
+
125
125
  # the stat total_call_time is a percent
126
126
  def as_percentage
127
127
  if call_count.zero?
@@ -130,7 +130,7 @@ module NewRelic
130
130
  (total_call_time / call_count) * 100.0
131
131
  end
132
132
  end
133
-
133
+
134
134
  def duration
135
135
  end_time - begin_time
136
136
  end
@@ -141,23 +141,23 @@ module NewRelic
141
141
  else
142
142
  (call_count / duration.to_f) * 60.0
143
143
  end
144
- end
145
-
144
+ end
145
+
146
146
  def total_call_time_per_minute
147
147
  60.0 * time_percentage
148
148
  end
149
-
149
+
150
150
  def standard_deviation
151
151
  return 0 if call_count < 2 || self.sum_of_squares.nil?
152
-
152
+
153
153
  # Convert sum of squares into standard deviation based on
154
154
  # formula for the standard deviation for the entire population
155
155
  x = self.sum_of_squares - (self.call_count * (self.average_value**2))
156
156
  return 0 if x <= 0
157
-
157
+
158
158
  Math.sqrt(x / self.call_count)
159
159
  end
160
-
160
+
161
161
  # returns the time spent in this component as a percentage of the total
162
162
  # time window.
163
163
  def time_percentage
@@ -173,7 +173,7 @@ module NewRelic
173
173
  alias average_value average_call_time
174
174
  alias average_response_time average_call_time
175
175
  alias requests_per_minute calls_per_minute
176
-
176
+
177
177
  def to_s
178
178
  summary
179
179
  end
@@ -183,7 +183,7 @@ module NewRelic
183
183
  format = "%m/%d/%y %I:%M%p"
184
184
  "[#{Time.at(begin_time).utc.strftime(format)} UTC, #{'%2.3fs' % duration}; #{'%2i' % call_count} calls #{'%4i' % to_ms(average_call_time)} ms]"
185
185
  end
186
-
186
+
187
187
  # round all of the values to n decimal points
188
188
  def round!
189
189
  self.total_call_time = round_to_3(total_call_time)
@@ -195,7 +195,7 @@ module NewRelic
195
195
  self.end_time = end_time
196
196
  end
197
197
 
198
- # calculate this set of stats to be a percentage fraction
198
+ # calculate this set of stats to be a percentage fraction
199
199
  # of the provided stats, which has an overlapping time window.
200
200
  # used as a key part of the split algorithm
201
201
  def fraction_of(s)
@@ -210,16 +210,16 @@ module NewRelic
210
210
  self.call_count = s.call_count * percentage
211
211
  self.sum_of_squares = (s.sum_of_squares || 0) * percentage
212
212
  end
213
-
214
- # multiply the total time and rate by the given percentage
213
+
214
+ # multiply the total time and rate by the given percentage
215
215
  def multiply_by(percentage)
216
216
  self.total_call_time = total_call_time * percentage
217
217
  self.call_count = call_count * percentage
218
218
  self.sum_of_squares = sum_of_squares * percentage
219
-
219
+
220
220
  self
221
221
  end
222
-
222
+
223
223
 
224
224
  # returns s,t,f
225
225
  def get_apdex
@@ -232,17 +232,17 @@ module NewRelic
232
232
  end
233
233
 
234
234
  private
235
-
235
+
236
236
  def to_ms(number)
237
237
  (number*1000).round
238
238
  end
239
-
239
+
240
240
  def round_to_3(val)
241
241
  (val * 1000).round / 1000.0
242
242
  end
243
243
  end
244
-
245
-
244
+
245
+
246
246
  class StatsBase
247
247
  include Stats
248
248
 
@@ -252,67 +252,67 @@ module NewRelic
252
252
  attr_accessor :total_call_time
253
253
  attr_accessor :total_exclusive_time
254
254
  attr_accessor :sum_of_squares
255
-
256
- def initialize
255
+
256
+ def initialize
257
257
  reset
258
258
  end
259
-
259
+
260
260
  def freeze
261
261
  @end_time = Time.now
262
262
  super
263
263
  end
264
-
264
+
265
265
  def to_json(*a)
266
- {'call_count' => call_count,
267
- 'min_call_time' => min_call_time,
268
- 'max_call_time' => max_call_time,
266
+ {'call_count' => call_count,
267
+ 'min_call_time' => min_call_time,
268
+ 'max_call_time' => max_call_time,
269
269
  'total_call_time' => total_call_time,
270
270
  'total_exclusive_time' => total_exclusive_time,
271
271
  'sum_of_squares' => sum_of_squares}.to_json(*a)
272
272
  end
273
273
 
274
-
274
+
275
275
  # In this class, we explicitly don't track begin and end time here, to save space during
276
276
  # cross process serialization via xml. Still the accessor methods must be provided for merge to work.
277
277
  def begin_time=(t)
278
278
  end
279
-
279
+
280
280
  def end_time=(t)
281
281
  end
282
-
282
+
283
283
  def begin_time
284
284
  0.0
285
285
  end
286
-
286
+
287
287
  def end_time
288
288
  0.0
289
289
  end
290
290
  end
291
-
292
-
291
+
292
+
293
293
  class BasicStats < StatsBase
294
294
  end
295
-
295
+
296
296
  class ApdexStats < StatsBase
297
-
297
+
298
298
  def record_apdex_s
299
299
  @call_count += 1
300
300
  end
301
-
301
+
302
302
  def record_apdex_t
303
303
  @total_call_time += 1
304
304
  end
305
-
305
+
306
306
  def record_apdex_f
307
307
  @total_exclusive_time += 1
308
308
  end
309
309
  end
310
-
310
+
311
311
  # Statistics used to track the performance of traced methods
312
312
  class MethodTraceStats < StatsBase
313
-
313
+
314
314
  alias data_point_count call_count
315
-
315
+
316
316
  # record a single data point into the statistical gatherer. The gatherer
317
317
  # will aggregate all data points collected over a specified period and upload
318
318
  # its data to the NewRelic server
@@ -326,9 +326,9 @@ module NewRelic
326
326
  @sum_of_squares += (value * value)
327
327
  self
328
328
  end
329
-
329
+
330
330
  alias trace_call record_data_point
331
-
331
+
332
332
  def record_multiple_data_points(total_value, count=1)
333
333
  return record_data_point(total_value) if count == 1
334
334
  @call_count += count
@@ -340,13 +340,13 @@ module NewRelic
340
340
  @sum_of_squares += (avg_val * avg_val) * count
341
341
  self
342
342
  end
343
-
343
+
344
344
  def increment_count(value = 1)
345
345
  @call_count += value
346
346
  end
347
347
 
348
348
  end
349
-
349
+
350
350
  class ScopedMethodTraceStats < MethodTraceStats
351
351
  def initialize(unscoped_stats)
352
352
  super()
@@ -23,5 +23,5 @@ module NewRelic #:nodoc:
23
23
  require 'timeout'
24
24
  TimerLib = Timeout
25
25
  end
26
-
27
- end
26
+
27
+ end
@@ -4,11 +4,11 @@ module TransactionAnalysis
4
4
  def database_time
5
5
  time_percentage(/^Database\/.*/)
6
6
  end
7
-
7
+
8
8
  def render_time
9
9
  time_percentage(/^View\/.*/)
10
10
  end
11
-
11
+
12
12
  # summarizes performance data for all calls to segments
13
13
  # with the same metric_name
14
14
  class SegmentSummary
@@ -18,41 +18,41 @@ module TransactionAnalysis
18
18
  @total_time, @exclusive_time, @call_count = 0,0,0
19
19
  @sample = sample
20
20
  end
21
-
21
+
22
22
  def <<(segment)
23
23
  if metric_name != segment.metric_name
24
- raise ArgumentError, "Metric Name Mismatch: #{segment.metric_name} != #{metric_name}"
24
+ raise ArgumentError, "Metric Name Mismatch: #{segment.metric_name} != #{metric_name}"
25
25
  end
26
-
26
+
27
27
  @total_time += segment.duration
28
28
  @exclusive_time += segment.exclusive_duration
29
29
  @call_count += 1
30
30
  end
31
-
31
+
32
32
  def average_time
33
33
  @total_time / @call_count
34
34
  end
35
-
35
+
36
36
  def average_exclusive_time
37
37
  @exclusive_time / @call_count
38
38
  end
39
-
39
+
40
40
  def exclusive_time_percentage
41
41
  return 0 unless @exclusive_time && @sample.duration && @sample.duration > 0
42
42
  @exclusive_time / @sample.duration
43
43
  end
44
-
44
+
45
45
  def total_time_percentage
46
46
  return 0 unless @total_time && @sample.duration && @sample.duration > 0
47
47
  @total_time / @sample.duration
48
48
  end
49
-
49
+
50
50
  def developer_name
51
51
  return @metric_name if @metric_name == 'Remainder'
52
52
  NewRelic::MetricParser.parse(@metric_name).developer_name
53
53
  end
54
54
  end
55
-
55
+
56
56
  # return the data that breaks down the performance of the transaction
57
57
  # as an array of SegmentSummary objects. If a limit is specified, then
58
58
  # limit the data set to the top n
@@ -65,13 +65,13 @@ module TransactionAnalysis
65
65
  metric_hash[metric_name] << segment
66
66
  end
67
67
  end
68
-
68
+
69
69
  data = metric_hash.values
70
-
70
+
71
71
  data.sort! do |x,y|
72
72
  y.exclusive_time <=> x.exclusive_time
73
73
  end
74
-
74
+
75
75
  if limit && data.length > limit
76
76
  data = data[0..limit - 1]
77
77
  end
@@ -81,17 +81,17 @@ module TransactionAnalysis
81
81
  data.each do |segment|
82
82
  remainder -= segment.exclusive_time
83
83
  end
84
-
84
+
85
85
  if (remainder*1000).round > 0
86
86
  remainder_summary = SegmentSummary.new('Remainder', self)
87
87
  remainder_summary.total_time = remainder_summary.exclusive_time = remainder
88
88
  remainder_summary.call_count = 1
89
89
  data << remainder_summary
90
90
  end
91
-
91
+
92
92
  data
93
93
  end
94
-
94
+
95
95
  # return an array of sql statements executed by this transaction
96
96
  # each element in the array contains [sql, parent_segment_metric_name, duration]
97
97
  def sql_segments(show_non_sql_segments = true)
@@ -101,8 +101,8 @@ module TransactionAnalysis
101
101
  end
102
102
  segments
103
103
  end
104
-
105
- private
104
+
105
+ private
106
106
  def time_percentage(regex)
107
107
  total = 0
108
108
  each_segment do |segment|