newrelic_rpm 2.8.0
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/LICENSE +37 -0
- data/README +93 -0
- data/Rakefile +38 -0
- data/install.rb +37 -0
- data/lib/new_relic/agent.rb +26 -0
- data/lib/new_relic/agent/agent.rb +762 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/collection_helper.rb +81 -0
- data/lib/new_relic/agent/error_collector.rb +105 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +95 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +151 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +105 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +18 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +17 -0
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +15 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +6 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +35 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +30 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +23 -0
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +6 -0
- data/lib/new_relic/agent/method_tracer.rb +171 -0
- data/lib/new_relic/agent/patch_const_missing.rb +31 -0
- data/lib/new_relic/agent/samplers/cpu.rb +29 -0
- data/lib/new_relic/agent/samplers/memory.rb +55 -0
- data/lib/new_relic/agent/samplers/mongrel.rb +26 -0
- data/lib/new_relic/agent/stats_engine.rb +241 -0
- data/lib/new_relic/agent/synchronize.rb +40 -0
- data/lib/new_relic/agent/transaction_sampler.rb +281 -0
- data/lib/new_relic/agent/worker_loop.rb +128 -0
- data/lib/new_relic/api/deployments.rb +92 -0
- data/lib/new_relic/config.rb +194 -0
- data/lib/new_relic/config/merb.rb +35 -0
- data/lib/new_relic/config/rails.rb +113 -0
- data/lib/new_relic/config/ruby.rb +9 -0
- data/lib/new_relic/local_environment.rb +108 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +26 -0
- data/lib/new_relic/metric_spec.rb +39 -0
- data/lib/new_relic/metrics.rb +7 -0
- data/lib/new_relic/noticed_error.rb +21 -0
- data/lib/new_relic/shim_agent.rb +95 -0
- data/lib/new_relic/stats.rb +359 -0
- data/lib/new_relic/transaction_analysis.rb +122 -0
- data/lib/new_relic/transaction_sample.rb +499 -0
- data/lib/new_relic/version.rb +111 -0
- data/lib/new_relic_api.rb +275 -0
- data/lib/newrelic_rpm.rb +27 -0
- data/lib/tasks/agent_tests.rake +14 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/newrelic.yml +137 -0
- data/recipes/newrelic.rb +46 -0
- data/test/config/newrelic.yml +26 -0
- data/test/config/test_config.rb +9 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/model_fixture.rb +17 -0
- data/test/new_relic/agent/tc_active_record.rb +91 -0
- data/test/new_relic/agent/tc_agent.rb +112 -0
- data/test/new_relic/agent/tc_collection_helper.rb +104 -0
- data/test/new_relic/agent/tc_controller.rb +98 -0
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +52 -0
- data/test/new_relic/agent/tc_error_collector.rb +127 -0
- data/test/new_relic/agent/tc_method_tracer.rb +306 -0
- data/test/new_relic/agent/tc_stats_engine.rb +218 -0
- data/test/new_relic/agent/tc_synchronize.rb +37 -0
- data/test/new_relic/agent/tc_transaction_sample.rb +175 -0
- data/test/new_relic/agent/tc_transaction_sample_builder.rb +200 -0
- data/test/new_relic/agent/tc_transaction_sampler.rb +305 -0
- data/test/new_relic/agent/tc_worker_loop.rb +101 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/tc_config.rb +36 -0
- data/test/new_relic/tc_deployments_api.rb +37 -0
- data/test/new_relic/tc_environment.rb +94 -0
- data/test/new_relic/tc_metric_spec.rb +150 -0
- data/test/new_relic/tc_shim_agent.rb +9 -0
- data/test/new_relic/tc_stats.rb +141 -0
- data/test/test_helper.rb +39 -0
- data/test/ui/tc_newrelic_helper.rb +44 -0
- data/ui/controllers/newrelic_controller.rb +200 -0
- data/ui/helpers/google_pie_chart.rb +55 -0
- data/ui/helpers/newrelic_helper.rb +286 -0
- data/ui/views/layouts/newrelic_default.rhtml +49 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +12 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +22 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +19 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +45 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/index.rhtml +37 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +62 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +394 -0
- metadata +180 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
module NewRelic
|
3
|
+
module VERSION #:nodoc:
|
4
|
+
MAJOR = 2
|
5
|
+
MINOR = 8
|
6
|
+
TINY = 0
|
7
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
8
|
+
def self.changes
|
9
|
+
puts "NewRelic RPM Plugin Version: #{NewRelic::VERSION}"
|
10
|
+
puts CHANGELOG
|
11
|
+
end
|
12
|
+
|
13
|
+
CHANGELOG = <<EOF
|
14
|
+
2008-12-18 version 2.8.0
|
15
|
+
* add beta of api in new_relic_api.rb
|
16
|
+
* instrumented dynamic finders in ActiveRecord
|
17
|
+
* preliminary support for capturing deployment information via capistrano
|
18
|
+
* change memory sampler for solaris to use /usr/bin/ps
|
19
|
+
* allow ERB in newrelic.yml file
|
20
|
+
* merged support for merb into this version
|
21
|
+
* fix incompatibility in the developer mode with the safe_erb plugin
|
22
|
+
* fix module namespace issue causing an error accessing NewRelic::Instrumentation modules
|
23
|
+
* fix issue where the agent sometimes failed to start up if there was a transient network problem
|
24
|
+
* fix IgnoreSilentlyException message
|
25
|
+
2008-12-09 version 2.7.4
|
26
|
+
* fix error when trying to serialize some kinds of Enumerable objects
|
27
|
+
* added extra debug logging
|
28
|
+
* added app_name to app mapping
|
29
|
+
2008-11-26 version 2.7.3
|
30
|
+
* fix compatibility issue with 1.8.5 causing error with Dir.glob
|
31
|
+
2008-11-24 version 2.7.2
|
32
|
+
* fix problem with passenger edge not being a detected environment
|
33
|
+
2008-11-22 verison 2.7.1
|
34
|
+
* fix problem with skipped dispatcher instrumentation
|
35
|
+
2008-11-23 version 2.7.0
|
36
|
+
* Repackage to support both plugin and Gem installation
|
37
|
+
* Support passenger/litespeed/jruby application naming
|
38
|
+
* Update method for calculating dispatcher queue time
|
39
|
+
* Show stack traces in RPM Transaction Traces
|
40
|
+
* Capture error source for TemplateErrors
|
41
|
+
* Clean up error stack traces.
|
42
|
+
* Support query plans from postgres
|
43
|
+
* Performance tuning
|
44
|
+
* bugfixes
|
45
|
+
2008-10-06 version 2.5.3
|
46
|
+
* fix error in transaction tracing causing traces not to show up
|
47
|
+
2008-09-30 version 2.5.2
|
48
|
+
* fixes for postgres explain plan support
|
49
|
+
2008-09-09 version 2.5.1
|
50
|
+
* bugfixes
|
51
|
+
2008-08-29 version 2.5.0
|
52
|
+
* add agent support for rpm 1.1 features
|
53
|
+
* Fix regression error with thin support
|
54
|
+
2008-08-27 version 2.4.3
|
55
|
+
* added 'newrelic_ignore' controller class method with :except and :only options for finer grained control
|
56
|
+
over the blocking of instrumentation in controllers.
|
57
|
+
* bugfixes
|
58
|
+
2008-07-31 version 2.4.2
|
59
|
+
* error reporting in early access
|
60
|
+
2008-07-30 version 2.4.1
|
61
|
+
* bugfix: initializing developer mode
|
62
|
+
2008-07-29 version 2.4.0
|
63
|
+
* Beta support for LiteSpeed and Passenger
|
64
|
+
2008-07-28 version 2.3.7
|
65
|
+
* bugfixes
|
66
|
+
2008-07-28 version 2.3.6
|
67
|
+
* bugfixes
|
68
|
+
2008-07-17 version 2.3.5
|
69
|
+
* bugfixes: pie chart data, rails 1.1 compability
|
70
|
+
2008-07-11 version 2.3.4
|
71
|
+
* bugfix
|
72
|
+
2008-07-10 version 2.3.3
|
73
|
+
* bugfix for non-mysql databases
|
74
|
+
2008-07-07 version 2.3.2
|
75
|
+
* bugfixes
|
76
|
+
* Add enhancement for Transaction Traces early access feature
|
77
|
+
2008-06-26 version 2.3.1
|
78
|
+
* bugfixes
|
79
|
+
2008-06-26 version 2.3.0
|
80
|
+
+ Add support for Transaction Traces early access feature
|
81
|
+
2008-06-13 version 2.2.2
|
82
|
+
* bugfixes
|
83
|
+
2008-06-10 version 2.2.1
|
84
|
+
+ Add rails 2.1 support for Developer Mode
|
85
|
+
+ Changes to memory sampler: Add support for JRuby and fix Solaris support.
|
86
|
+
* Stop catching exceptions and start catching StandardError; other exception cleanup
|
87
|
+
* Add protective exception catching to the stats engine
|
88
|
+
* Improved support for thin domain sockets
|
89
|
+
* Support JRuby environments
|
90
|
+
2008-05-22 version 2.1.6
|
91
|
+
* bugfixes
|
92
|
+
2008-05-22 version 2.1.5
|
93
|
+
* bugfixes
|
94
|
+
2008-05-14 version 2.1.4
|
95
|
+
* bugfixes
|
96
|
+
2008-05-13 version 2.1.3
|
97
|
+
* bugfixes
|
98
|
+
2008-05-08 version 2.1.2
|
99
|
+
* bugfixes
|
100
|
+
2008-05-07 version 2.1.1
|
101
|
+
* bugfixes
|
102
|
+
2008-04-25 version 2.1.0
|
103
|
+
* release for private beta
|
104
|
+
EOF
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if __FILE__ == $0
|
109
|
+
NewRelic::VERSION.changes
|
110
|
+
end
|
111
|
+
|
@@ -0,0 +1,275 @@
|
|
1
|
+
# Ruby lib for working with the New Relic API's XML interface. Requires Rails 2.0 or later to be loaded.
|
2
|
+
#
|
3
|
+
# Can also be used as a script using script/runner
|
4
|
+
#
|
5
|
+
# Authentication is handled using your agent license key or HTTP Basic Authentication. To authenticate
|
6
|
+
# using your license key your newrelic.yml configuration file must be in your application config directory
|
7
|
+
# and contain your license key. The New Relic account associated with the license key must allow api access.
|
8
|
+
# Log into RPM, click Account at the top of the page and check the "Make my account data accessible" checkbox.
|
9
|
+
#
|
10
|
+
# Basic authentication uses your site credentials to authenticate.
|
11
|
+
#
|
12
|
+
# # To authenticate using basic authentication, make this call with your username and password:
|
13
|
+
# NewRelicApi.authenticate('user@example.com', 'test')
|
14
|
+
#
|
15
|
+
# This API does not have any agent dependencies. It can be used independent of the agent by copying it into your application.
|
16
|
+
#
|
17
|
+
# ==Examples
|
18
|
+
# # Fetching the list of applications for an account
|
19
|
+
# NewRelicApi::Account.find(:first).applications
|
20
|
+
#
|
21
|
+
# # Fetching the health values for all account applications
|
22
|
+
# NewRelicApi::Account.application_health
|
23
|
+
#
|
24
|
+
# # Fetching the health values for an application
|
25
|
+
# NewRelicApi::Account.find(:first).applications.first.threshold_values
|
26
|
+
#
|
27
|
+
# # Finding an application by name
|
28
|
+
# NewRelicApi::Account.find(:first).applications(:params => {:conditions => {:name => 'My App'}})
|
29
|
+
#
|
30
|
+
|
31
|
+
module NewRelicApi
|
32
|
+
|
33
|
+
# This mixin defines ActiveRecord style associations (like has_many) for ActiveResource objects.
|
34
|
+
# ActiveResource objects using this mixin must define the method 'query_params'.
|
35
|
+
module ActiveResourceAssociations #:nodoc:
|
36
|
+
class << self
|
37
|
+
|
38
|
+
protected
|
39
|
+
def included(base)
|
40
|
+
class << base
|
41
|
+
# a special activeresource implementation of has_many
|
42
|
+
def has_many(*associations)
|
43
|
+
associations.to_a.each do |association|
|
44
|
+
define_method association do |*args|
|
45
|
+
val = attributes[association.to_s] # if we've already fetched the relationship in the initial fetch, return it
|
46
|
+
return val if val
|
47
|
+
|
48
|
+
options = args.extract_options!
|
49
|
+
type = args.first || :all
|
50
|
+
|
51
|
+
begin
|
52
|
+
# look for the class definition within the current class
|
53
|
+
clazz = ( self.class.name + '::' + association.to_s.camelize.singularize).constantize
|
54
|
+
rescue
|
55
|
+
# look for the class definition in the NRAPI module
|
56
|
+
clazz = ( 'NewRelicApi::' + association.to_s.camelize.singularize).constantize
|
57
|
+
end
|
58
|
+
params = (options[:params] || {}).update(self.query_params)
|
59
|
+
options[:params] = params
|
60
|
+
clazz.find(type, options)
|
61
|
+
|
62
|
+
#clazz.find(type, :params => options.update(self.query_params))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
class << self
|
72
|
+
attr_accessor :email, :password, :license_key, :ssl, :host, :port
|
73
|
+
|
74
|
+
# Sets up basic authentication credentials for all the resources. This is not necessary if you are
|
75
|
+
# using agent license key authentication.
|
76
|
+
def authenticate(email, password)
|
77
|
+
@password = password
|
78
|
+
@email = email
|
79
|
+
end
|
80
|
+
|
81
|
+
# Resets the base path of all resources. This should be called when overridding the newrelic.yml settings
|
82
|
+
# using the ssl, host or port accessors.
|
83
|
+
def reset!
|
84
|
+
@classes.each {|klass| klass.reset!} if @classes
|
85
|
+
NewRelicApi::Account.site_url
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def track_resource(klass) #:nodoc:
|
90
|
+
(@classes ||= []) << klass
|
91
|
+
end
|
92
|
+
end
|
93
|
+
class BaseResource < ActiveResource::Base #:nodoc:
|
94
|
+
include ActiveResourceAssociations
|
95
|
+
|
96
|
+
class << self
|
97
|
+
def inherited(klass) #:nodoc:
|
98
|
+
NewRelicApi.track_resource(klass)
|
99
|
+
end
|
100
|
+
|
101
|
+
def headers
|
102
|
+
h = {'x-license-key' => NewRelicApi.license_key || NewRelic::Config.instance['license_key']}
|
103
|
+
h['Authorization'] = 'Basic ' + ["#{NewRelicApi.email}:#{NewRelicApi.password}"].pack('m').delete("\r\n") if NewRelicApi.email
|
104
|
+
h
|
105
|
+
end
|
106
|
+
|
107
|
+
def site_url
|
108
|
+
"http#{'s' if (NewRelicApi.ssl || NewRelic::Config.instance['ssl'])}://#{NewRelicApi.host || NewRelic::Config.instance['host']}:#{NewRelicApi.port || NewRelic::Config.instance['port']}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def reset!
|
112
|
+
self.site = self.site_url
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
117
|
+
def fix_fields(*fields)
|
118
|
+
fields.to_a.each do |field|
|
119
|
+
define_method field do
|
120
|
+
yield super
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def fix_integer_fields(*fields)
|
126
|
+
fix_fields(*fields) { |sup| sup.to_i }
|
127
|
+
end
|
128
|
+
|
129
|
+
def fix_float_fields(*fields)
|
130
|
+
fix_fields(*fields) { |sup| sup.to_f }
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
self.site = self.site_url
|
135
|
+
end
|
136
|
+
ACCOUNT_RESOURCE_PATH = '/accounts/:account_id/' #:nodoc:
|
137
|
+
ACCOUNT_AGENT_RESOURCE_PATH = ACCOUNT_RESOURCE_PATH + 'agents/:agent_id/' #:nodoc:
|
138
|
+
ACCOUNT_APPLICATION_RESOURCE_PATH = ACCOUNT_RESOURCE_PATH + 'applications/:application_id/' #:nodoc:
|
139
|
+
|
140
|
+
module AccountResource #:nodoc:
|
141
|
+
def account_id
|
142
|
+
prefix_options[:account_id]
|
143
|
+
end
|
144
|
+
def account_query_params(extra_params = {})
|
145
|
+
{:account_id => account_id}.merge(extra_params)
|
146
|
+
end
|
147
|
+
|
148
|
+
def query_params#:nodoc:
|
149
|
+
account_query_params
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
module AgentResource #:nodoc:
|
155
|
+
include ActiveResourceAssociations
|
156
|
+
end
|
157
|
+
|
158
|
+
# An application has many:
|
159
|
+
# +agents+:: the agent instances associated with this app
|
160
|
+
# +threshold_values+:: the health indicators for this application.
|
161
|
+
class Application < BaseResource
|
162
|
+
include AccountResource
|
163
|
+
include AgentResource
|
164
|
+
|
165
|
+
has_many :agents, :threshold_values
|
166
|
+
|
167
|
+
self.prefix = ACCOUNT_RESOURCE_PATH
|
168
|
+
|
169
|
+
def query_params#:nodoc:
|
170
|
+
account_query_params(:application_id => id)
|
171
|
+
end
|
172
|
+
|
173
|
+
class Agent < BaseResource
|
174
|
+
include AccountResource
|
175
|
+
include AgentResource
|
176
|
+
|
177
|
+
self.prefix = ACCOUNT_APPLICATION_RESOURCE_PATH
|
178
|
+
|
179
|
+
def query_params#:nodoc:
|
180
|
+
super.merge(:application_id => cluster_agent_id)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
# A threshold value represents a single health indicator for an application such as CPU, memory or response time.
|
187
|
+
#
|
188
|
+
# ==Fields
|
189
|
+
# +name+:: The name of the threshold setting associated with this threshold value.
|
190
|
+
# +threshold_value+:: A value of 0, 1, 2 or 3 representing gray (not reporting), green, yellow and red
|
191
|
+
# +metric_value+:: The metric value associated with this threshold
|
192
|
+
class ThresholdValue < BaseResource
|
193
|
+
self.prefix = ACCOUNT_APPLICATION_RESOURCE_PATH
|
194
|
+
# attr_reader :name, :begin_time, :metric_value, :threshold_value
|
195
|
+
|
196
|
+
fix_integer_fields :threshold_value
|
197
|
+
fix_float_fields :metric_value
|
198
|
+
|
199
|
+
# Returns the color value for this threshold (Gray, Green, Yellow or Red).
|
200
|
+
def color_value
|
201
|
+
case threshold_value
|
202
|
+
when 3: 'Red'
|
203
|
+
when 2: 'Yellow'
|
204
|
+
when 1: 'Green'
|
205
|
+
else 'Gray'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_s #:nodoc:
|
210
|
+
"#{name}: #{color_value} (#{formatted_metric_value})"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# An account contains your basic account information.
|
215
|
+
#
|
216
|
+
# Accounts have many
|
217
|
+
# +applications+:: the applications contained within the account
|
218
|
+
#
|
219
|
+
# Find Accounts
|
220
|
+
#
|
221
|
+
# NewRelicApi::Account.find(:all) # find all accounts for the current user.
|
222
|
+
# NewRelicApi::Account.find(44) # find individual account by ID
|
223
|
+
#
|
224
|
+
class Account < BaseResource
|
225
|
+
has_many :applications
|
226
|
+
|
227
|
+
def query_params #:nodoc:
|
228
|
+
{:account_id => id}
|
229
|
+
end
|
230
|
+
|
231
|
+
# Returns an account including all of its applications and the threshold values for each application.
|
232
|
+
def self.application_health(type = :first)
|
233
|
+
find(type, :params => {:include => :application_health})
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
# This model is used to mark production deployments in RPM
|
239
|
+
# Only create is supported.
|
240
|
+
# ==Examples
|
241
|
+
# # Creating a new deployment
|
242
|
+
# NewRelicApi::Deployment.create
|
243
|
+
#
|
244
|
+
class Deployment < BaseResource
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
if (__FILE__ == $0) || ($0 =~ /script\/runner$/)
|
249
|
+
# Run the command given by the first argument. Right
|
250
|
+
# now all we have is deployments. We hope to have other
|
251
|
+
# kinds of events here later
|
252
|
+
command = "(no command given)"
|
253
|
+
extra = [command]
|
254
|
+
ARGV.options do |opts|
|
255
|
+
script_name = File.basename($0)
|
256
|
+
opts.banner = "Usage: #{__FILE__} command [options]"
|
257
|
+
|
258
|
+
opts.separator ""
|
259
|
+
|
260
|
+
opts.on("-e", "--environment=name", String,
|
261
|
+
"Specifies the environment for the runner to operate under (test/development/production).",
|
262
|
+
"Default: development")
|
263
|
+
|
264
|
+
extra = opts.order!
|
265
|
+
end
|
266
|
+
command = extra.shift
|
267
|
+
begin
|
268
|
+
require "new_relic/api/#{command}"
|
269
|
+
command_class = NewRelic::API.const_get(command.camelize)
|
270
|
+
rescue
|
271
|
+
STDERR.puts "Unknown command: #{command}"
|
272
|
+
exit 1
|
273
|
+
end
|
274
|
+
command_class.new(extra).run
|
275
|
+
end
|
data/lib/newrelic_rpm.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Initialization script for the gem.
|
2
|
+
# Add
|
3
|
+
# #require 'new_relic'
|
4
|
+
# to your initialization sequence, as late as possible.
|
5
|
+
#
|
6
|
+
require 'new_relic/config'
|
7
|
+
|
8
|
+
def log!(message)
|
9
|
+
STDERR.puts "[NewRelic] #{message}"
|
10
|
+
end
|
11
|
+
|
12
|
+
# START THE AGENT
|
13
|
+
# We install the shim agent unless the tracers are enabled, the plugin
|
14
|
+
# env setting is not false, and the agent started okay.
|
15
|
+
if !NewRelic::Config.instance.tracers_enabled?
|
16
|
+
require 'new_relic/shim_agent'
|
17
|
+
else
|
18
|
+
# After verison 2.0 of Rails we can access the configuration directly.
|
19
|
+
# We need it to add dev mode routes after initialization finished.
|
20
|
+
if defined? Rails.configuration
|
21
|
+
Rails.configuration.after_initialize do
|
22
|
+
NewRelic::Config.instance.start_plugin Rails.configuration
|
23
|
+
end
|
24
|
+
else
|
25
|
+
NewRelic::Config.instance.start_plugin
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# run unit tests for the NewRelic Agent
|
2
|
+
namespace :test do
|
3
|
+
AGENT_HOME = File.expand_path(File.join(File.dirname(__FILE__), "..",".."))
|
4
|
+
Rake::TestTask.new(:agent) do |t|
|
5
|
+
t.libs << "#{AGENT_HOME}/test"
|
6
|
+
t.libs << "#{AGENT_HOME}/lib"
|
7
|
+
t.pattern = "#{AGENT_HOME}/test/**/tc_*.rb"
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
Rake::Task['test:agent'].comment = "Run the unit tests for the Agent"
|
11
|
+
|
12
|
+
Rake::TestTask.new(:all => ["test", "test:agent"])
|
13
|
+
Rake::Task['test:all'].comment = "Run all tests including agent code"
|
14
|
+
end
|
data/lib/tasks/all.rb
ADDED
data/newrelic.yml
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#
|
2
|
+
# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails
|
3
|
+
# applications with deep visibility and low overhead. For more information,
|
4
|
+
# 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
|
+
# You must specify the licence key associated with your New Relic account.
|
12
|
+
# This key binds your Agent's data to your account in the New Relic RPM service.
|
13
|
+
license_key: '<%= license_key %>'
|
14
|
+
|
15
|
+
# Application Name
|
16
|
+
# Set this to be the name of your application as you'd like it show up in RPM.
|
17
|
+
# RPM will then auto-map instances of your application into a RPM "application"
|
18
|
+
# on your home dashboard page. This setting does not prevent you from manually
|
19
|
+
# defining applications.
|
20
|
+
app_name: My Application
|
21
|
+
|
22
|
+
# the 'enabled' setting is used to turn on the NewRelic Agent. When false,
|
23
|
+
# your application is not instrumented and the Agent does not start up or
|
24
|
+
# collect any data; it is a complete shut-off.
|
25
|
+
#
|
26
|
+
# when turned on, the agent collects performance data by inserting lightweight
|
27
|
+
# tracers on key methods inside the rails framework and asynchronously aggregating
|
28
|
+
# and reporting this performance data to the NewRelic RPM service at NewRelic.com.
|
29
|
+
# below.
|
30
|
+
enabled: false
|
31
|
+
|
32
|
+
# The newrelic agent generates its own log file to keep its logging information
|
33
|
+
# separate from that of your application. Specify its log level here.
|
34
|
+
log_level: info
|
35
|
+
|
36
|
+
# The newrelic agent communicates with the RPM service via http by default.
|
37
|
+
# If you want to communicate via https to increase security, then turn on
|
38
|
+
# SSL by setting this value to true. Note, this will result in increased
|
39
|
+
# CPU overhead to perform the encryption involved in SSL communication, but this
|
40
|
+
# work is done asynchronously to the threads that process your application code, so
|
41
|
+
# it should not impact response times.
|
42
|
+
ssl: false
|
43
|
+
|
44
|
+
|
45
|
+
# Proxy settings for connecting to the RPM server.
|
46
|
+
#
|
47
|
+
# If a proxy is used, the host setting is required. Other settings are optional. Default
|
48
|
+
# port is 8080.
|
49
|
+
#
|
50
|
+
# proxy_host: proxy.sample.com
|
51
|
+
# proxy_port: 8080
|
52
|
+
# proxy_user:
|
53
|
+
# proxy_pass:
|
54
|
+
|
55
|
+
|
56
|
+
# Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params.
|
57
|
+
# When true, the RoR filter_parameters mechanism is used so that sensitive parameters are not recorded
|
58
|
+
capture_params: false
|
59
|
+
|
60
|
+
|
61
|
+
# Transaction tracer captures deep information about slow
|
62
|
+
# transactions and sends this to the RPM service once a minute. Included in the
|
63
|
+
# transaction is the exact call sequence of the transactions including any SQL statements
|
64
|
+
# issued.
|
65
|
+
transaction_tracer:
|
66
|
+
|
67
|
+
# Transaction tracer is enabled by default. Set this to false to turn it off. This feature
|
68
|
+
# is only available at the Silver and above product levels.
|
69
|
+
enabled: true
|
70
|
+
|
71
|
+
|
72
|
+
# When transaction tracer is on, SQL statements can optionally be recorded. The recorder
|
73
|
+
# has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its
|
74
|
+
# original form, and "obfuscated", which strips out numeric and string literals
|
75
|
+
record_sql: obfuscated
|
76
|
+
|
77
|
+
# Threshold in seconds for when to collect stack trace for a SQL call. In other words,
|
78
|
+
# when SQL statements exceed this threshold, then capture and send to RPM the current
|
79
|
+
# stack trace. This is helpful for pinpointing where long SQL calls originate from
|
80
|
+
stack_trace_threshold: 0.500
|
81
|
+
|
82
|
+
# Error collector captures information about uncaught exceptions and sends them to RPM for
|
83
|
+
# viewing
|
84
|
+
error_collector:
|
85
|
+
|
86
|
+
# Error collector is enabled by default. Set this to false to turn it off. This feature
|
87
|
+
# is only available at the Silver and above product levels
|
88
|
+
enabled: true
|
89
|
+
|
90
|
+
# Tells error collector whether or not to capture a source snippet around the place of the
|
91
|
+
# error when errors are View related.
|
92
|
+
capture_source: true
|
93
|
+
|
94
|
+
# To stop specific errors from reporting to RPM, set this property to comma separated
|
95
|
+
# values
|
96
|
+
#
|
97
|
+
#ignore_errors: ActionController::RoutingError, ...
|
98
|
+
|
99
|
+
|
100
|
+
# override default settings based on your application's environment
|
101
|
+
|
102
|
+
# NOTE if your application has other named environments, you should
|
103
|
+
# provide newrelic conifguration settings for these enviromnents here.
|
104
|
+
|
105
|
+
development:
|
106
|
+
<<: *default_settings
|
107
|
+
# turn off communication to RPM service in development mode.
|
108
|
+
# NOTE: for initial evaluation purposes, you may want to temporarily turn
|
109
|
+
# the agent on in development mode.
|
110
|
+
enabled: false
|
111
|
+
|
112
|
+
# When running in Developer Mode, the New Relic Agent will present
|
113
|
+
# performance information on the last 100 transactions you have
|
114
|
+
# executed since starting the mongrel. to view this data, go to
|
115
|
+
# http://localhost:3000/newrelic
|
116
|
+
developer: true
|
117
|
+
|
118
|
+
test:
|
119
|
+
<<: *default_settings
|
120
|
+
# it almost never makes sense to turn on the agent when running unit, functional or
|
121
|
+
# integration tests or the like.
|
122
|
+
enabled: false
|
123
|
+
|
124
|
+
# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows
|
125
|
+
# an average performance impact of < 5 ms per transaction, you you can leave this on
|
126
|
+
# all the time without incurring any user-visible performance degredation.
|
127
|
+
production:
|
128
|
+
<<: *default_settings
|
129
|
+
enabled: true
|
130
|
+
|
131
|
+
# many applications have a staging environment which behaves identically to production.
|
132
|
+
# Support for that environment is provided here. By default, the staging environment has
|
133
|
+
# the agent turned on.
|
134
|
+
staging:
|
135
|
+
<<: *default_settings
|
136
|
+
enabled: true
|
137
|
+
app_name: My Application (Staging)
|