techarch-newrelic_rpm 2.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/CHANGELOG +335 -0
  2. data/LICENSE +37 -0
  3. data/Manifest +159 -0
  4. data/README.md +138 -0
  5. data/Rakefile +22 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic_cmd +4 -0
  8. data/cert/cacert.pem +34 -0
  9. data/init.rb +38 -0
  10. data/install.rb +45 -0
  11. data/lib/new_relic/agent.rb +281 -0
  12. data/lib/new_relic/agent/agent.rb +636 -0
  13. data/lib/new_relic/agent/chained_call.rb +13 -0
  14. data/lib/new_relic/agent/collection_helper.rb +66 -0
  15. data/lib/new_relic/agent/error_collector.rb +121 -0
  16. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  17. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +88 -0
  18. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  19. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +437 -0
  20. data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
  21. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +167 -0
  22. data/lib/new_relic/agent/instrumentation/memcache.rb +24 -0
  23. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  24. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +13 -0
  25. data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
  26. data/lib/new_relic/agent/instrumentation/net.rb +23 -0
  27. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
  28. data/lib/new_relic/agent/instrumentation/rack.rb +108 -0
  29. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  30. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  31. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +41 -0
  32. data/lib/new_relic/agent/instrumentation/rails/errors.rb +27 -0
  33. data/lib/new_relic/agent/instrumentation/sinatra.rb +39 -0
  34. data/lib/new_relic/agent/method_tracer.rb +349 -0
  35. data/lib/new_relic/agent/patch_const_missing.rb +125 -0
  36. data/lib/new_relic/agent/sampler.rb +12 -0
  37. data/lib/new_relic/agent/samplers/cpu_sampler.rb +49 -0
  38. data/lib/new_relic/agent/samplers/memory_sampler.rb +138 -0
  39. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  40. data/lib/new_relic/agent/shim_agent.rb +21 -0
  41. data/lib/new_relic/agent/stats_engine.rb +22 -0
  42. data/lib/new_relic/agent/stats_engine/metric_stats.rb +111 -0
  43. data/lib/new_relic/agent/stats_engine/samplers.rb +71 -0
  44. data/lib/new_relic/agent/stats_engine/transactions.rb +152 -0
  45. data/lib/new_relic/agent/transaction_sampler.rb +310 -0
  46. data/lib/new_relic/agent/worker_loop.rb +118 -0
  47. data/lib/new_relic/commands/deployments.rb +145 -0
  48. data/lib/new_relic/commands/new_relic_commands.rb +30 -0
  49. data/lib/new_relic/control.rb +473 -0
  50. data/lib/new_relic/control/external.rb +13 -0
  51. data/lib/new_relic/control/merb.rb +22 -0
  52. data/lib/new_relic/control/rails.rb +145 -0
  53. data/lib/new_relic/control/ruby.rb +36 -0
  54. data/lib/new_relic/control/sinatra.rb +14 -0
  55. data/lib/new_relic/histogram.rb +89 -0
  56. data/lib/new_relic/local_environment.rb +328 -0
  57. data/lib/new_relic/merbtasks.rb +6 -0
  58. data/lib/new_relic/metric_data.rb +42 -0
  59. data/lib/new_relic/metric_parser.rb +124 -0
  60. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  61. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  62. data/lib/new_relic/metric_parser/active_record.rb +25 -0
  63. data/lib/new_relic/metric_parser/controller.rb +54 -0
  64. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  65. data/lib/new_relic/metric_parser/errors.rb +6 -0
  66. data/lib/new_relic/metric_parser/external.rb +50 -0
  67. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  68. data/lib/new_relic/metric_parser/view.rb +61 -0
  69. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  70. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  71. data/lib/new_relic/metric_spec.rb +52 -0
  72. data/lib/new_relic/metrics.rb +7 -0
  73. data/lib/new_relic/noticed_error.rb +23 -0
  74. data/lib/new_relic/rack/metric_app.rb +56 -0
  75. data/lib/new_relic/rack/newrelic.ru +25 -0
  76. data/lib/new_relic/rack/newrelic.yml +25 -0
  77. data/lib/new_relic/rack_app.rb +5 -0
  78. data/lib/new_relic/recipes.rb +82 -0
  79. data/lib/new_relic/stats.rb +361 -0
  80. data/lib/new_relic/transaction_analysis.rb +121 -0
  81. data/lib/new_relic/transaction_sample.rb +666 -0
  82. data/lib/new_relic/version.rb +54 -0
  83. data/lib/new_relic_api.rb +313 -0
  84. data/lib/newrelic_rpm.rb +40 -0
  85. data/lib/tasks/all.rb +4 -0
  86. data/lib/tasks/install.rake +7 -0
  87. data/lib/tasks/tests.rake +13 -0
  88. data/newrelic.yml +227 -0
  89. data/recipes/newrelic.rb +6 -0
  90. data/techarch-newrelic_rpm.gemspec +32 -0
  91. data/test/active_record_fixtures.rb +55 -0
  92. data/test/config/newrelic.yml +46 -0
  93. data/test/config/test_control.rb +39 -0
  94. data/test/new_relic/agent/active_record_instrumentation_test.rb +264 -0
  95. data/test/new_relic/agent/agent_controller_test.rb +107 -0
  96. data/test/new_relic/agent/agent_test.rb +119 -0
  97. data/test/new_relic/agent/agent_test_controller.rb +44 -0
  98. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  99. data/test/new_relic/agent/collection_helper_test.rb +125 -0
  100. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +76 -0
  101. data/test/new_relic/agent/error_collector_test.rb +172 -0
  102. data/test/new_relic/agent/method_tracer_test.rb +340 -0
  103. data/test/new_relic/agent/metric_data_test.rb +56 -0
  104. data/test/new_relic/agent/mock_ar_connection.rb +40 -0
  105. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  106. data/test/new_relic/agent/net_instrumentation_test.rb +63 -0
  107. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  108. data/test/new_relic/agent/stats_engine/samplers_test.rb +81 -0
  109. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
  110. data/test/new_relic/agent/task_instrumentation_test.rb +126 -0
  111. data/test/new_relic/agent/testable_agent.rb +13 -0
  112. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  113. data/test/new_relic/agent/transaction_sample_test.rb +186 -0
  114. data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
  115. data/test/new_relic/agent/worker_loop_test.rb +103 -0
  116. data/test/new_relic/control_test.rb +113 -0
  117. data/test/new_relic/deployments_api_test.rb +68 -0
  118. data/test/new_relic/environment_test.rb +75 -0
  119. data/test/new_relic/metric_parser_test.rb +172 -0
  120. data/test/new_relic/metric_spec_test.rb +177 -0
  121. data/test/new_relic/shim_agent_test.rb +9 -0
  122. data/test/new_relic/stats_test.rb +291 -0
  123. data/test/new_relic/version_number_test.rb +74 -0
  124. data/test/test_helper.rb +38 -0
  125. data/test/ui/newrelic_controller_test.rb +14 -0
  126. data/test/ui/newrelic_helper_test.rb +53 -0
  127. data/ui/controllers/newrelic_controller.rb +220 -0
  128. data/ui/helpers/google_pie_chart.rb +55 -0
  129. data/ui/helpers/newrelic_helper.rb +317 -0
  130. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  131. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  132. data/ui/views/newrelic/_sample.rhtml +19 -0
  133. data/ui/views/newrelic/_segment.rhtml +28 -0
  134. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  135. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  136. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  137. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  138. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  139. data/ui/views/newrelic/_sql_row.rhtml +11 -0
  140. data/ui/views/newrelic/_stack_trace.rhtml +30 -0
  141. data/ui/views/newrelic/_table.rhtml +12 -0
  142. data/ui/views/newrelic/explain_sql.rhtml +42 -0
  143. data/ui/views/newrelic/images/arrow-close.png +0 -0
  144. data/ui/views/newrelic/images/arrow-open.png +0 -0
  145. data/ui/views/newrelic/images/blue_bar.gif +0 -0
  146. data/ui/views/newrelic/images/file_icon.png +0 -0
  147. data/ui/views/newrelic/images/gray_bar.gif +0 -0
  148. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  149. data/ui/views/newrelic/images/textmate.png +0 -0
  150. data/ui/views/newrelic/index.rhtml +57 -0
  151. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  152. data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
  153. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  154. data/ui/views/newrelic/show_sample.rhtml +80 -0
  155. data/ui/views/newrelic/show_source.rhtml +3 -0
  156. data/ui/views/newrelic/stylesheets/style.css +484 -0
  157. data/ui/views/newrelic/threads.rhtml +52 -0
  158. metadata +330 -0
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/ruby
2
+ module NewRelic
3
+ module VERSION #:nodoc:
4
+ MAJOR = 2
5
+ MINOR = 10
6
+ TINY = 1
7
+ EXPERIMENTAL = 12
8
+ STRING = [MAJOR, MINOR, TINY, EXPERIMENTAL].compact.join('.')
9
+ end
10
+
11
+ # Helper class for managing version comparisons
12
+ class VersionNumber
13
+ attr_reader :parts
14
+ include Comparable
15
+ def initialize(version_string)
16
+ version_string ||= '1.0.0'
17
+ @parts = version_string.split('.').map{|n| n.to_i }
18
+ end
19
+ def major_version; @parts[0]; end
20
+ def minor_version; @parts[1]; end
21
+ def tiny_version; @parts[2]; end
22
+
23
+ def <=>(other)
24
+ other = self.class.new(other) if other.is_a? String
25
+ self.class.compare(self.parts, other.parts)
26
+ end
27
+
28
+ def to_s
29
+ @parts.join(".")
30
+ end
31
+
32
+ def hash
33
+ @parts.hash
34
+ end
35
+
36
+ def eql? other
37
+ (self <=> other) == 0
38
+ end
39
+
40
+ private
41
+ def self.compare(parts1, parts2)
42
+ a, b = parts1.first, parts2.first
43
+ case
44
+ when a.nil? && b.nil? then 0
45
+ when a.nil? then -1
46
+ when b.nil? then 1
47
+ when a == b
48
+ compare(parts1[1..-1], parts2[1..-1])
49
+ else
50
+ a <=> b
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,313 @@
1
+ # == REST API Helpers
2
+ #
3
+ # Ruby lib for working with the New Relic API's XML interface. Requires Rails 2.0 or later to be loaded.
4
+ #
5
+ # Can also be used as a script using script/runner
6
+ #
7
+ # Authentication is handled using your agent license key or HTTP Basic Authentication. To authenticate
8
+ # using your license key your newrelic.yml configuration file must be in your application config directory
9
+ # and contain your license key. The New Relic account associated with the license key must allow api access.
10
+ # Log into RPM, click Account at the top of the page and check the "Make my account data accessible" checkbox.
11
+ #
12
+ # Basic authentication uses your site credentials to authenticate.
13
+ #
14
+ # # To authenticate using basic authentication, make this call with your username and password:
15
+ # NewRelicApi.authenticate('user@example.com', 'test')
16
+ #
17
+ # This API does not have any agent dependencies. It can be used independent of the agent by copying it into your application.
18
+ #
19
+ # == Examples
20
+ #
21
+ # # Fetching the list of applications for an account
22
+ # NewRelicApi::Account.find(:first).applications
23
+ #
24
+ # # Fetching the health values for all account applications
25
+ # NewRelicApi::Account.application_health
26
+ #
27
+ # # Fetching the health values for an application
28
+ # NewRelicApi::Account.find(:first).applications.first.threshold_values
29
+ #
30
+ # # Finding an application by name
31
+ # NewRelicApi::Account.find(:first).applications(:params => {:conditions => {:name => 'My App'}})
32
+ #
33
+
34
+ module NewRelicApi
35
+
36
+ # This mixin defines ActiveRecord style associations (like has_many) for ActiveResource objects.
37
+ # ActiveResource objects using this mixin must define the method 'query_params'.
38
+ module ActiveResourceAssociations #:nodoc:
39
+ class << self
40
+ protected
41
+ def included(base)
42
+ class << base
43
+ # a special activeresource implementation of has_many
44
+ def has_many(*associations)
45
+ associations.to_a.each do |association|
46
+ define_method association do |*args|
47
+ val = attributes[association.to_s] # if we've already fetched the relationship in the initial fetch, return it
48
+ return val if val
49
+
50
+ options = args.extract_options!
51
+ type = args.first || :all
52
+
53
+ begin
54
+ # look for the class definition within the current class
55
+ clazz = ( self.class.name + '::' + association.to_s.camelize.singularize).constantize
56
+ rescue
57
+ # look for the class definition in the NRAPI module
58
+ clazz = ( 'NewRelicApi::' + association.to_s.camelize.singularize).constantize
59
+ end
60
+ params = (options[:params] || {}).update(self.query_params)
61
+ options[:params] = params
62
+ clazz.find(type, options)
63
+
64
+ #clazz.find(type, :params => options.update(self.query_params))
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+ class << self
74
+ attr_accessor :email, :password, :license_key, :ssl, :host, :port
75
+
76
+ # Sets up basic authentication credentials for all the resources. This is not necessary if you are
77
+ # using agent license key authentication.
78
+ def authenticate(email, password)
79
+ @password = password
80
+ @email = email
81
+ end
82
+
83
+ # Resets the base path of all resources. This should be called when overridding the newrelic.yml settings
84
+ # using the ssl, host or port accessors.
85
+ def reset!
86
+ @classes.each {|klass| klass.reset!} if @classes
87
+ NewRelicApi::Account.site_url
88
+ end
89
+
90
+
91
+ def track_resource(klass) #:nodoc:
92
+ (@classes ||= []) << klass
93
+ end
94
+ end
95
+
96
+ class BaseResource < ActiveResource::Base #:nodoc:
97
+ include ActiveResourceAssociations
98
+
99
+ class << self
100
+ def inherited(klass) #:nodoc:
101
+ NewRelicApi.track_resource(klass)
102
+ end
103
+
104
+ def headers
105
+ h = {'x-license-key' => NewRelicApi.license_key || NewRelic::Control.instance['license_key']}
106
+ h['Authorization'] = 'Basic ' + ["#{NewRelicApi.email}:#{NewRelicApi.password}"].pack('m').delete("\r\n") if NewRelicApi.email
107
+ h
108
+ end
109
+
110
+ def site_url
111
+ host = NewRelicApi.host || NewRelic::Control.instance.api_server.name
112
+ port = NewRelicApi.port || NewRelic::Control.instance.api_server.port
113
+ "#{port == 443 ? 'https' : 'http'}://#{host}:#{port}"
114
+ end
115
+
116
+ def reset!
117
+ self.site = self.site_url
118
+ end
119
+
120
+ protected
121
+
122
+ def fix_fields(*fields)
123
+ fields.to_a.each do |field|
124
+ define_method field do
125
+ yield super
126
+ end
127
+ end
128
+ end
129
+
130
+ def fix_integer_fields(*fields)
131
+ fix_fields(*fields) { |sup| sup.to_i }
132
+ end
133
+
134
+ def fix_float_fields(*fields)
135
+ fix_fields(*fields) { |sup| sup.to_f }
136
+ end
137
+
138
+ end
139
+ self.site = self.site_url
140
+ end
141
+ ACCOUNT_RESOURCE_PATH = '/accounts/:account_id/' #:nodoc:
142
+ ACCOUNT_AGENT_RESOURCE_PATH = ACCOUNT_RESOURCE_PATH + 'agents/:agent_id/' #:nodoc:
143
+ ACCOUNT_APPLICATION_RESOURCE_PATH = ACCOUNT_RESOURCE_PATH + 'applications/:application_id/' #:nodoc:
144
+
145
+ module AccountResource #:nodoc:
146
+ def account_id
147
+ prefix_options[:account_id]
148
+ end
149
+ def account_query_params(extra_params = {})
150
+ {:account_id => account_id}.merge(extra_params)
151
+ end
152
+
153
+ def query_params#:nodoc:
154
+ account_query_params
155
+ end
156
+ end
157
+
158
+ module AgentResource #:nodoc:
159
+ include ActiveResourceAssociations
160
+ end
161
+
162
+ # An application has many:
163
+ # +agents+:: the agent instances associated with this app
164
+ # +threshold_values+:: the health indicators for this application.
165
+ class Application < BaseResource
166
+ include AccountResource
167
+ include AgentResource
168
+
169
+ has_many :agents, :threshold_values
170
+
171
+ self.prefix = ACCOUNT_RESOURCE_PATH
172
+
173
+ def query_params#:nodoc:
174
+ account_query_params(:application_id => id)
175
+ end
176
+
177
+ class Agent < BaseResource
178
+ include AccountResource
179
+ include AgentResource
180
+
181
+ self.prefix = ACCOUNT_APPLICATION_RESOURCE_PATH
182
+
183
+ def query_params#:nodoc:
184
+ super.merge(:application_id => cluster_agent_id)
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+ # A threshold value represents a single health indicator for an application such as CPU, memory or response time.
191
+ #
192
+ # ==Fields
193
+ # +name+:: The name of the threshold setting associated with this threshold value.
194
+ # +threshold_value+:: A value of 0, 1, 2 or 3 representing gray (not reporting), green, yellow and red
195
+ # +metric_value+:: The metric value associated with this threshold
196
+ class ThresholdValue < BaseResource
197
+ self.prefix = ACCOUNT_APPLICATION_RESOURCE_PATH
198
+ # attr_reader :name, :begin_time, :metric_value, :threshold_value
199
+
200
+ fix_integer_fields :threshold_value
201
+ fix_float_fields :metric_value
202
+
203
+ # Returns the color value for this threshold (Gray, Green, Yellow or Red).
204
+ def color_value
205
+ case threshold_value
206
+ when 3: 'Red'
207
+ when 2: 'Yellow'
208
+ when 1: 'Green'
209
+ else 'Gray'
210
+ end
211
+ end
212
+
213
+ def to_s #:nodoc:
214
+ "#{name}: #{color_value} (#{formatted_metric_value})"
215
+ end
216
+ end
217
+
218
+ # An account contains your basic account information.
219
+ #
220
+ # Accounts have many
221
+ # +applications+:: the applications contained within the account
222
+ #
223
+ # Find Accounts
224
+ #
225
+ # NewRelicApi::Account.find(:all) # find all accounts for the current user.
226
+ # NewRelicApi::Account.find(44) # find individual account by ID
227
+ #
228
+ class Account < BaseResource
229
+ has_many :applications
230
+ has_many :account_views
231
+
232
+ def query_params #:nodoc:
233
+ {:account_id => id}
234
+ end
235
+
236
+ # Returns an account including all of its applications and the threshold values for each application.
237
+ def self.application_health(type = :first)
238
+ find(type, :params => {:include => :application_health})
239
+ end
240
+
241
+ # Add a user to an account.
242
+ # +user_params+:: User parameters as a hash consisting of the following:
243
+ # email, first_name, password, password_confirmation
244
+ # If a user record already exists for this email, the name
245
+ # and password fields are ignored.
246
+ # +is_admin+:: Set administrative privileges for this user.
247
+ def add_user(user_params, is_admin = false)
248
+ account_id = self.id
249
+ account_view = NewRelicApi::Account::AccountView.create(:account_id => account_id, :user => user_params, :is_admin => is_admin)
250
+ account_views << account_view if account_view.valid?
251
+ account_view
252
+ end
253
+
254
+ # Change the subscription for an account
255
+ # +product_id+:: ID or name of product (e.g. Lite) (required).
256
+ # +number_of_hosts+:: Number of hosts. This is required for fixed host products.
257
+ # For utility based products, this is set to the maximum
258
+ # number of hosts allowed to connect.
259
+ def change_subscription(sub_params)
260
+ NewRelicApi::Subscription.create(sub_params.merge(:account_id => self.id))
261
+ end
262
+
263
+ # Remove a user's access from an account.
264
+ # +email+:: User's email address.
265
+ def remove_user(email)
266
+ view = account_views.detect{|av| av.user.email == email}
267
+ if view
268
+ view.destroy
269
+ else
270
+ raise "No user matching email #{email} for account"
271
+ end
272
+ end
273
+
274
+ # Change the primary admin for an account. The administrator must be a
275
+ # user that is already associated with the account
276
+ # +email+:: Email address of the new administrator
277
+ def change_primary_admin(email)
278
+ put(:update_primary_admin, :email => email)
279
+ end
280
+
281
+ class AccountView < BaseResource
282
+ self.prefix = ACCOUNT_RESOURCE_PATH
283
+
284
+ def query_params(extra_params = {}) #:nodoc:
285
+ {:account_id => account_id}.merge(extra_params)
286
+ end
287
+
288
+ def user
289
+ @attributes['user']
290
+ end
291
+ end
292
+ end
293
+
294
+ # This model is used to mark production deployments in RPM
295
+ # Only create is supported.
296
+ # ==Examples
297
+ # # Creating a new deployment
298
+ # NewRelicApi::Deployment.create
299
+ #
300
+ class Deployment < BaseResource
301
+ end
302
+
303
+ class Subscription < BaseResource
304
+ def query_params(extra_params = {}) #:nodoc:
305
+ {:account_id => account_id}.merge(extra_params)
306
+ end
307
+ end
308
+
309
+ class User < BaseResource
310
+ end
311
+
312
+ end
313
+
@@ -0,0 +1,40 @@
1
+ # == New Relic Initialization
2
+ #
3
+ # When installed as a gem, you can activate the New Relic agent one of the following ways:
4
+ #
5
+ # For Rails, add:
6
+ # config.gem 'newrelic_rpm'
7
+ # to your initialization sequence.
8
+ #
9
+ # For merb, do
10
+ # dependency 'newrelic_rpm'
11
+ # in the Merb config/init.rb
12
+ #
13
+ # For other frameworks, or to manage the agent manually, invoke NewRelic::Agent#manual_start
14
+ # directly.
15
+ #
16
+ require 'new_relic/control'
17
+
18
+ def log!(message)
19
+ STDERR.puts "[NewRelic] #{message}"
20
+ end
21
+
22
+ # After verison 2.0 of Rails we can access the configuration directly.
23
+ # We need it to add dev mode routes after initialization finished.
24
+ if defined? Rails.configuration
25
+ Rails.configuration.after_initialize do
26
+ NewRelic::Control.instance.init_plugin :config => Rails.configuration
27
+ end
28
+ elsif defined? Merb
29
+ module NewRelic
30
+ class MerbBootLoader < Merb::BootLoader
31
+ after Merb::BootLoader::ChooseAdapter
32
+
33
+ def self.run
34
+ NewRelic::Control.instance.init_plugin
35
+ end
36
+ end
37
+ end
38
+ else
39
+ NewRelic::Control.instance.init_plugin
40
+ end
@@ -0,0 +1,4 @@
1
+ # This is required to load in task definitions from merb
2
+ Dir.glob(File.join(File.dirname(__FILE__),'*.rake')) do |file|
3
+ load file
4
+ end
@@ -0,0 +1,7 @@
1
+ # run unit tests for the NewRelic Agent
2
+ namespace :newrelic do
3
+ desc "install a default config/newrelic.yml file"
4
+ task :install do
5
+ load File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "install.rb"))
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # run unit tests for the NewRelic Agent
2
+ if defined? Rake::TestTask
3
+ namespace :test do
4
+ AGENT_HOME = File.expand_path(File.join(File.dirname(__FILE__), "..",".."))
5
+ Rake::TestTask.new(:newrelic) do |t|
6
+ t.libs << "#{AGENT_HOME}/test"
7
+ t.libs << "#{AGENT_HOME}/lib"
8
+ t.pattern = "#{AGENT_HOME}/test/**/*_test.rb"
9
+ t.verbose = true
10
+ end
11
+ Rake::Task['test:newrelic'].comment = "Run the unit tests for the Agent"
12
+ end
13
+ end
@@ -0,0 +1,227 @@
1
+ #
2
+ # This file configures the NewRelic RPM Agent, NewRelic RPM monitors
3
+ # Rails applications with deep visibility and low overhead. For more
4
+ # information, visit www.newrelic.com.
5
+ #
6
+ # <%= generated_for_user %>
7
+ #
8
+ # here are the settings that are common to all environments
9
+ common: &default_settings
10
+ # ============================== LICENSE KEY ===============================
11
+
12
+ # You must specify the licence key associated with your New Relic
13
+ # account. This key binds your Agent's data to your account in the
14
+ # New Relic RPM service.
15
+ license_key: '<%= license_key %>'
16
+
17
+ # Agent Enabled (Rails Only)
18
+ # Use this setting to force the agent to run or not run.
19
+ # Default is 'auto' which means the agent will install and run only
20
+ # if a valid dispatcher such as Mongrel is running. This prevents
21
+ # it from running with Rake or the console. Set to false to
22
+ # completely turn the agent off regardless of the other settings.
23
+ # Valid values are true, false and auto.
24
+ # agent_enabled: auto
25
+
26
+ # Application Name
27
+ # Set this to be the name of your application as you'd like it show
28
+ # up in RPM. RPM will then auto-map instances of your application
29
+ # into a RPM "application" on your home dashboard page. If you want
30
+ # to map this instance into multiple apps, like "AJAX Requests" and
31
+ # "All UI" then specify a semicolon separated list of up to three
32
+ # distinct names. If you comment this out, it defaults to the
33
+ # capitalized RAILS_ENV (i.e., Production, Staging, etc)
34
+ app_name: My Application
35
+
36
+ # When "true", the agent collects performance data about your
37
+ # application and reports this data to the NewRelic RPM service at
38
+ # newrelic.com. This global switch is normally overridden for each
39
+ # environment below. (formerly called 'enabled')
40
+ monitor_mode: true
41
+
42
+ # Developer mode should be off in every environment but
43
+ # development as it has very high overhead in memory.
44
+ developer_mode: false
45
+
46
+ # The newrelic agent generates its own log file to keep its logging
47
+ # information separate from that of your application. Specify its
48
+ # log level here.
49
+ log_level: info
50
+
51
+ # The newrelic agent communicates with the RPM service via http by
52
+ # default. If you want to communicate via https to increase
53
+ # security, then turn on SSL by setting this value to true. Note,
54
+ # this will result in increased CPU overhead to perform the
55
+ # encryption involved in SSL communication, but this work is done
56
+ # asynchronously to the threads that process your application code,
57
+ # so it should not impact response times.
58
+ ssl: false
59
+
60
+ # EXPERIMENTAL: enable verification of the SSL certificate sent by
61
+ # the server. This setting has no effect unless SSL is enabled
62
+ # above. This may block your application. Only enable it if the data
63
+ # you send us needs end-to-end verified certificates.
64
+ #
65
+ # This means we cannot cache the DNS lookup, so each request to the
66
+ # RPM service will perform a lookup. It also means that we cannot
67
+ # use a non-blocking lookup, so in a worst case, if you have DNS
68
+ # problems, your app may block indefinitely.
69
+ # verify_certificate: true
70
+
71
+ # Set your application's Apdex threshold value with the 'apdex_t'
72
+ # setting, in seconds. The apdex_t value determines the buckets used
73
+ # to compute your overall Apdex score.
74
+ # Requests that take less than apdex_t seconds to process will be
75
+ # classified as Satisfying transactions; more than apdex_t seconds
76
+ # as Tolerating transactions; and more than four times the apdex_t
77
+ # value as Frustrating transactions.
78
+ # For more about the Apdex standard, see
79
+ # http://support.newrelic.com/faqs/general/apdex
80
+
81
+ apdex_t: 0.5
82
+
83
+ # Proxy settings for connecting to the RPM server.
84
+ #
85
+ # If a proxy is used, the host setting is required. Other settings
86
+ # are optional. Default port is 8080.
87
+ #
88
+ # proxy_host: hostname
89
+ # proxy_port: 8080
90
+ # proxy_user:
91
+ # proxy_pass:
92
+
93
+
94
+ # Tells transaction tracer and error collector (when enabled)
95
+ # whether or not to capture HTTP params. When true, frameworks can
96
+ # exclude HTTP parameters from being captured.
97
+ # Rails: the RoR filter_parameter_logging excludes parameters
98
+ # Java: create a config setting called "ignored_params" and set it to
99
+ # a comma separated list of HTTP parameter names.
100
+ # ex: ignored_params: credit_card, ssn, password
101
+ capture_params: false
102
+
103
+
104
+ # Transaction tracer captures deep information about slow
105
+ # transactions and sends this to the RPM service once a
106
+ # minute. Included in the transaction is the exact call sequence of
107
+ # the transactions including any SQL statements issued.
108
+ transaction_tracer:
109
+
110
+ # Transaction tracer is enabled by default. Set this to false to
111
+ # turn it off. This feature is only available at the Silver and
112
+ # above product levels.
113
+ enabled: true
114
+
115
+ # Threshold in seconds for when to collect a transaction
116
+ # trace. When the response time of a controller action exceeds
117
+ # this threshold, a transaction trace will be recorded and sent to
118
+ # RPM. Valid values are any float value, or (default) "apdex_f",
119
+ # which will use the threshold for an dissatisfying Apdex
120
+ # controller action - four times the Apdex T value.
121
+ transaction_threshold: apdex_f
122
+
123
+ # When transaction tracer is on, SQL statements can optionally be
124
+ # recorded. The recorder has three modes, "off" which sends no
125
+ # SQL, "raw" which sends the SQL statement in its original form,
126
+ # and "obfuscated", which strips out numeric and string literals
127
+ record_sql: obfuscated
128
+
129
+ # Threshold in seconds for when to collect stack trace for a SQL
130
+ # call. In other words, when SQL statements exceed this threshold,
131
+ # then capture and send to RPM the current stack trace. This is
132
+ # helpful for pinpointing where long SQL calls originate from
133
+ stack_trace_threshold: 0.500
134
+
135
+ # Determines whether the agent will capture query plans for slow
136
+ # SQL queries. Only supported in mysql and postgres. Should be
137
+ # set to false when using other adapters.
138
+ # explain_enabled: true
139
+
140
+ # Threshold for query execution time below which query plans will not
141
+ # not be captured. Relevant only when `explain_enabled` is true.
142
+ # explain_threshold: 0.5
143
+
144
+ # Error collector captures information about uncaught exceptions and
145
+ # sends them to RPM for viewing
146
+ error_collector:
147
+
148
+ # Error collector is enabled by default. Set this to false to turn
149
+ # it off. This feature is only available at the Silver and above
150
+ # product levels
151
+ enabled: true
152
+
153
+ # Rails Only - tells error collector whether or not to capture a
154
+ # source snippet around the place of the error when errors are View
155
+ # related.
156
+ capture_source: true
157
+
158
+ # To stop specific errors from reporting to RPM, set this property
159
+ # to comma separated values
160
+ #
161
+ #ignore_errors: ActionController::RoutingError, ...
162
+
163
+ # (Advanced) Uncomment this to ensure the cpu and memory samplers
164
+ # won't run. Useful when you are using the agent to monitor an
165
+ # external resource
166
+ # disable_samplers: true
167
+
168
+ # If you aren't interested in visibility in these areas, you can disable
169
+ # the instrumentation to reduce overhead.
170
+ #
171
+ # disable_view_instrumentation: true
172
+ # disable_activerecord_instrumentation: true
173
+ # disable_memcache_instrumentation: true
174
+
175
+ # Certain types of instrumentation such as GC stats will not work if
176
+ # you are running multi-threaded. Please let us know.
177
+ # multi_threaded = false
178
+
179
+ # Application Environments
180
+ # ------------------------------------------
181
+ # Environment specific settings are in this section.
182
+ # For Rails applications, RAILS_ENV is used to determine the environment
183
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
184
+ # the environment
185
+
186
+ # NOTE if your application has other named environments, you should
187
+ # provide newrelic conifguration settings for these enviromnents here.
188
+
189
+ development:
190
+ <<: *default_settings
191
+ # Turn off communication to RPM service in development mode (also
192
+ # 'enabled').
193
+ # NOTE: for initial evaluation purposes, you may want to temporarily
194
+ # turn the agent on in development mode.
195
+ monitor_mode: false
196
+
197
+ # Rails Only - when running in Developer Mode, the New Relic Agent will
198
+ # present performance information on the last 100 transactions you have
199
+ # executed since starting the mongrel.
200
+ # NOTE: There is substantial overhead when running in developer mode.
201
+ # Do not use for production or load testing.
202
+ developer_mode: true
203
+
204
+ # Enable textmate links
205
+ # textmate: true
206
+
207
+ test:
208
+ <<: *default_settings
209
+ # It almost never makes sense to turn on the agent when running
210
+ # unit, functional or integration tests or the like.
211
+ monitor_mode: false
212
+
213
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
214
+ # testing shows an average performance impact of < 5 ms per
215
+ # transaction, you you can leave this on all the time without
216
+ # incurring any user-visible performance degredation.
217
+ production:
218
+ <<: *default_settings
219
+ monitor_mode: true
220
+
221
+ # Many applications have a staging environment which behaves
222
+ # identically to production. Support for that environment is provided
223
+ # here. By default, the staging environment has the agent turned on.
224
+ staging:
225
+ <<: *default_settings
226
+ monitor_mode: true
227
+ app_name: My Application (Staging)