honkster-newrelic_rpm 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +462 -0
- data/LICENSE +37 -0
- data/README.rdoc +172 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +34 -0
- data/install.rb +9 -0
- data/lib/new_relic/agent.rb +382 -0
- data/lib/new_relic/agent/agent.rb +741 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +131 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +409 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +58 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +319 -0
- data/lib/new_relic/agent/instrumentation/net.rb +17 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
- data/lib/new_relic/agent/method_tracer.rb +350 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
- data/lib/new_relic/agent/shim_agent.rb +25 -0
- data/lib/new_relic/agent/stats_engine.rb +24 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +83 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
- data/lib/new_relic/agent/transaction_sampler.rb +330 -0
- data/lib/new_relic/agent/worker_loop.rb +81 -0
- data/lib/new_relic/collection_helper.rb +71 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +81 -0
- data/lib/new_relic/control.rb +203 -0
- data/lib/new_relic/control/configuration.rb +149 -0
- data/lib/new_relic/control/frameworks/external.rb +13 -0
- data/lib/new_relic/control/frameworks/merb.rb +24 -0
- data/lib/new_relic/control/frameworks/rails.rb +126 -0
- data/lib/new_relic/control/frameworks/rails3.rb +60 -0
- data/lib/new_relic/control/frameworks/ruby.rb +36 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +18 -0
- data/lib/new_relic/control/instrumentation.rb +95 -0
- data/lib/new_relic/control/logging_methods.rb +74 -0
- data/lib/new_relic/control/profiling.rb +24 -0
- data/lib/new_relic/control/server_methods.rb +88 -0
- data/lib/new_relic/delayed_job_injection.rb +27 -0
- data/lib/new_relic/histogram.rb +91 -0
- data/lib/new_relic/local_environment.rb +333 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -0
- data/lib/new_relic/metric_parser.rb +136 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +28 -0
- data/lib/new_relic/metric_parser/apdex.rb +88 -0
- data/lib/new_relic/metric_parser/controller.rb +62 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/external.rb +50 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
- data/lib/new_relic/metric_parser/other_transaction.rb +36 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_spec.rb +67 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/developer_mode.rb +257 -0
- data/lib/new_relic/rack/metric_app.rb +64 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +26 -0
- data/lib/new_relic/rack/newrelic.yml +27 -0
- data/lib/new_relic/rack_app.rb +6 -0
- data/lib/new_relic/recipes.rb +82 -0
- data/lib/new_relic/stats.rb +368 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +119 -0
- data/lib/new_relic/transaction_sample.rb +586 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/new_relic_api.rb +276 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +15 -0
- data/newrelic.yml +246 -0
- data/newrelic_rpm.gemspec +254 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +36 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +286 -0
- data/test/new_relic/agent/agent_controller_test.rb +294 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/error_collector_test.rb +163 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
- data/test/new_relic/agent/method_tracer_test.rb +340 -0
- data/test/new_relic/agent/metric_data_test.rb +53 -0
- data/test/new_relic/agent/metric_frame_test.rb +51 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
- data/test/new_relic/agent/rpm_agent_test.rb +142 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +188 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sample_test.rb +192 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/control_test.rb +127 -0
- data/test/new_relic/deployments_api_test.rb +69 -0
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +226 -0
- data/test/new_relic/metric_spec_test.rb +177 -0
- data/test/new_relic/rack/episodes_test.rb +318 -0
- data/test/new_relic/shim_agent_test.rb +9 -0
- data/test/new_relic/stats_test.rb +312 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_contexts.rb +28 -0
- data/test/test_helper.rb +72 -0
- data/ui/helpers/developer_mode_helper.rb +359 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +29 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +484 -0
- data/ui/views/newrelic/index.rhtml +59 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +79 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +307 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
# Represents url mapping rules stored on the server. These rules should be applied
|
2
|
+
# to URLs which are not normalized into controller class/action by Rails routes.
|
3
|
+
# Insantiated strictly by Marshal.
|
4
|
+
class NewRelic::UrlRule
|
5
|
+
attr_reader :match_expression, :replacement, :eval_order, :terminate_chain
|
6
|
+
|
7
|
+
def apply url
|
8
|
+
return nil
|
9
|
+
end
|
10
|
+
|
11
|
+
class RuleSet
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
module NewRelic
|
3
|
+
module VERSION #:nodoc:
|
4
|
+
MAJOR = 2
|
5
|
+
MINOR = 13
|
6
|
+
TINY = 0
|
7
|
+
BUILD = nil #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
|
8
|
+
STRING = [MAJOR, MINOR, TINY, BUILD].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 =~ /^\d+$/ ? n.to_i : n}
|
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 b.is_a?(Fixnum) ? -1 : 1
|
46
|
+
when b.nil? then -compare(parts2, parts1)
|
47
|
+
when a.to_s == b.to_s then compare(parts1[1..-1], parts2[1..-1])
|
48
|
+
when a.is_a?(String) then b.is_a?(Fixnum) ? -1 : (a <=> b)
|
49
|
+
when b.is_a?(String) then -compare(parts2, parts1)
|
50
|
+
else # they are both fixnums, not nil
|
51
|
+
a <=> b
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,276 @@
|
|
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
|
+
class AccountView < BaseResource
|
242
|
+
self.prefix = ACCOUNT_RESOURCE_PATH
|
243
|
+
|
244
|
+
def query_params(extra_params = {}) #:nodoc:
|
245
|
+
{:account_id => account_id}.merge(extra_params)
|
246
|
+
end
|
247
|
+
|
248
|
+
def user
|
249
|
+
@attributes['user']
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
class AccountUsage < BaseResource
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
# This model is used to mark production deployments in RPM
|
258
|
+
# Only create is supported.
|
259
|
+
# ==Examples
|
260
|
+
# # Creating a new deployment
|
261
|
+
# NewRelicApi::Deployment.create
|
262
|
+
#
|
263
|
+
class Deployment < BaseResource
|
264
|
+
end
|
265
|
+
|
266
|
+
class Subscription < BaseResource
|
267
|
+
def query_params(extra_params = {}) #:nodoc:
|
268
|
+
{:account_id => account_id}.merge(extra_params)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
class User < BaseResource
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
data/lib/newrelic_rpm.rb
ADDED
@@ -0,0 +1,49 @@
|
|
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 Sinatra, do
|
14
|
+
# require 'newrelic_rpm'
|
15
|
+
# after requiring 'sinatra'.
|
16
|
+
#
|
17
|
+
# For other frameworks, or to manage the agent manually, invoke NewRelic::Agent#manual_start
|
18
|
+
# directly.
|
19
|
+
#
|
20
|
+
require 'new_relic/control'
|
21
|
+
|
22
|
+
if defined? Merb
|
23
|
+
module NewRelic
|
24
|
+
class MerbBootLoader < Merb::BootLoader
|
25
|
+
after Merb::BootLoader::ChooseAdapter
|
26
|
+
def self.run
|
27
|
+
NewRelic::Control.instance.init_plugin
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
elsif defined? Rails
|
32
|
+
if Rails.respond_to?(:version) && Rails.version =~ /^3/
|
33
|
+
module NewRelic
|
34
|
+
class Railtie < Rails::Railtie
|
35
|
+
|
36
|
+
initializer "newrelic_rpm.start_plugin" do |app|
|
37
|
+
NewRelic::Control.instance.init_plugin(:config => app.config)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
else
|
42
|
+
# After verison 2.0 of Rails we can access the configuration directly.
|
43
|
+
# We need it to add dev mode routes after initialization finished.
|
44
|
+
config = Rails.configuration if defined?(Rails.configuration)
|
45
|
+
NewRelic::Control.instance.init_plugin :config => config
|
46
|
+
end
|
47
|
+
else
|
48
|
+
NewRelic::Control.instance.init_plugin
|
49
|
+
end
|
data/lib/tasks/all.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# run unit tests for the NewRelic Agent
|
2
|
+
|
3
|
+
if defined? Rake::TestTask
|
4
|
+
namespace :test do
|
5
|
+
AGENT_HOME = File.expand_path(File.join(File.dirname(__FILE__), "..",".."))
|
6
|
+
Rake::TestTask.new(:newrelic) do |t|
|
7
|
+
t.libs << "#{AGENT_HOME}/test"
|
8
|
+
t.libs << "#{AGENT_HOME}/lib"
|
9
|
+
t.pattern = "#{AGENT_HOME}/test/**/*_test.rb"
|
10
|
+
t.verbose = true
|
11
|
+
end
|
12
|
+
Rake::Task['test:newrelic'].comment = "Run the unit tests for the Agent"
|
13
|
+
task :default => :newrelic
|
14
|
+
end
|
15
|
+
end
|
data/newrelic.yml
ADDED
@@ -0,0 +1,246 @@
|
|
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 <%= Time.now.strftime('%B %d, %Y') %>, for version <%= NewRelic::VERSION::STRING %>
|
7
|
+
#
|
8
|
+
# <%= generated_for_user %>
|
9
|
+
|
10
|
+
|
11
|
+
# Here are the settings that are common to all environments
|
12
|
+
common: &default_settings
|
13
|
+
# ============================== LICENSE KEY ===============================
|
14
|
+
|
15
|
+
# You must specify the license key associated with your New Relic
|
16
|
+
# account. This key binds your Agent's data to your account in the
|
17
|
+
# New Relic RPM service.
|
18
|
+
license_key: '<%= license_key %>'
|
19
|
+
|
20
|
+
# Agent Enabled (Rails Only)
|
21
|
+
# Use this setting to force the agent to run or not run.
|
22
|
+
# Default is 'auto' which means the agent will install and run only
|
23
|
+
# if a valid dispatcher such as Mongrel is running. This prevents
|
24
|
+
# it from running with Rake or the console. Set to false to
|
25
|
+
# completely turn the agent off regardless of the other settings.
|
26
|
+
# Valid values are true, false and auto.
|
27
|
+
#
|
28
|
+
# agent_enabled: auto
|
29
|
+
|
30
|
+
# Application Name
|
31
|
+
# Set this to be the name of your application as you'd like it show
|
32
|
+
# up in RPM. RPM will then auto-map instances of your application
|
33
|
+
# into a RPM "application" on your home dashboard page. If you want
|
34
|
+
# to map this instance into multiple apps, like "AJAX Requests" and
|
35
|
+
# "All UI" then specify a semicolon separated list of up to three
|
36
|
+
# distinct names, or a yaml list. Defaults to the
|
37
|
+
# capitalized RAILS_ENV or RACK_ENV (i.e., Production, Staging, etc)
|
38
|
+
#
|
39
|
+
# Example:
|
40
|
+
#
|
41
|
+
# app_name:
|
42
|
+
# - Ajax Service
|
43
|
+
# - All Services
|
44
|
+
#
|
45
|
+
app_name: <%= @app_name %>
|
46
|
+
|
47
|
+
# When "true", the agent collects performance data about your
|
48
|
+
# application and reports this data to the NewRelic RPM service at
|
49
|
+
# newrelic.com. This global switch is normally overridden for each
|
50
|
+
# environment below. (formerly called 'enabled')
|
51
|
+
monitor_mode: true
|
52
|
+
|
53
|
+
# Developer mode should be off in every environment but
|
54
|
+
# development as it has very high overhead in memory.
|
55
|
+
developer_mode: false
|
56
|
+
|
57
|
+
# The newrelic agent generates its own log file to keep its logging
|
58
|
+
# information separate from that of your application. Specify its
|
59
|
+
# log level here.
|
60
|
+
log_level: info
|
61
|
+
|
62
|
+
# The newrelic agent communicates with the RPM service via http by
|
63
|
+
# default. If you want to communicate via https to increase
|
64
|
+
# security, then turn on SSL by setting this value to true. Note,
|
65
|
+
# this will result in increased CPU overhead to perform the
|
66
|
+
# encryption involved in SSL communication, but this work is done
|
67
|
+
# asynchronously to the threads that process your application code,
|
68
|
+
# so it should not impact response times.
|
69
|
+
ssl: false
|
70
|
+
|
71
|
+
# EXPERIMENTAL: enable verification of the SSL certificate sent by
|
72
|
+
# the server. This setting has no effect unless SSL is enabled
|
73
|
+
# above. This may block your application. Only enable it if the data
|
74
|
+
# you send us needs end-to-end verified certificates.
|
75
|
+
#
|
76
|
+
# This means we cannot cache the DNS lookup, so each request to the
|
77
|
+
# RPM service will perform a lookup. It also means that we cannot
|
78
|
+
# use a non-blocking lookup, so in a worst case, if you have DNS
|
79
|
+
# problems, your app may block indefinitely.
|
80
|
+
# verify_certificate: true
|
81
|
+
|
82
|
+
# Set your application's Apdex threshold value with the 'apdex_t'
|
83
|
+
# setting, in seconds. The apdex_t value determines the buckets used
|
84
|
+
# to compute your overall Apdex score.
|
85
|
+
# Requests that take less than apdex_t seconds to process will be
|
86
|
+
# classified as Satisfying transactions; more than apdex_t seconds
|
87
|
+
# as Tolerating transactions; and more than four times the apdex_t
|
88
|
+
# value as Frustrating transactions.
|
89
|
+
# For more about the Apdex standard, see
|
90
|
+
# http://support.newrelic.com/faqs/general/apdex
|
91
|
+
|
92
|
+
apdex_t: 0.5
|
93
|
+
|
94
|
+
# Proxy settings for connecting to the RPM server.
|
95
|
+
#
|
96
|
+
# If a proxy is used, the host setting is required. Other settings
|
97
|
+
# are optional. Default port is 8080.
|
98
|
+
#
|
99
|
+
# proxy_host: hostname
|
100
|
+
# proxy_port: 8080
|
101
|
+
# proxy_user:
|
102
|
+
# proxy_pass:
|
103
|
+
|
104
|
+
|
105
|
+
# Tells transaction tracer and error collector (when enabled)
|
106
|
+
# whether or not to capture HTTP params. When true, frameworks can
|
107
|
+
# exclude HTTP parameters from being captured.
|
108
|
+
# Rails: the RoR filter_parameter_logging excludes parameters
|
109
|
+
# Java: create a config setting called "ignored_params" and set it to
|
110
|
+
# a comma separated list of HTTP parameter names.
|
111
|
+
# ex: ignored_params: credit_card, ssn, password
|
112
|
+
capture_params: false
|
113
|
+
|
114
|
+
|
115
|
+
# Transaction tracer captures deep information about slow
|
116
|
+
# transactions and sends this to the RPM service once a
|
117
|
+
# minute. Included in the transaction is the exact call sequence of
|
118
|
+
# the transactions including any SQL statements issued.
|
119
|
+
transaction_tracer:
|
120
|
+
|
121
|
+
# Transaction tracer is enabled by default. Set this to false to
|
122
|
+
# turn it off. This feature is only available at the Silver and
|
123
|
+
# above product levels.
|
124
|
+
enabled: true
|
125
|
+
|
126
|
+
# Threshold in seconds for when to collect a transaction
|
127
|
+
# trace. When the response time of a controller action exceeds
|
128
|
+
# this threshold, a transaction trace will be recorded and sent to
|
129
|
+
# RPM. Valid values are any float value, or (default) "apdex_f",
|
130
|
+
# which will use the threshold for an dissatisfying Apdex
|
131
|
+
# controller action - four times the Apdex T value.
|
132
|
+
transaction_threshold: apdex_f
|
133
|
+
|
134
|
+
# When transaction tracer is on, SQL statements can optionally be
|
135
|
+
# recorded. The recorder has three modes, "off" which sends no
|
136
|
+
# SQL, "raw" which sends the SQL statement in its original form,
|
137
|
+
# and "obfuscated", which strips out numeric and string literals
|
138
|
+
record_sql: obfuscated
|
139
|
+
|
140
|
+
# Threshold in seconds for when to collect stack trace for a SQL
|
141
|
+
# call. In other words, when SQL statements exceed this threshold,
|
142
|
+
# then capture and send to RPM the current stack trace. This is
|
143
|
+
# helpful for pinpointing where long SQL calls originate from
|
144
|
+
stack_trace_threshold: 0.500
|
145
|
+
|
146
|
+
# Determines whether the agent will capture query plans for slow
|
147
|
+
# SQL queries. Only supported in mysql and postgres. Should be
|
148
|
+
# set to false when using other adapters.
|
149
|
+
# explain_enabled: true
|
150
|
+
|
151
|
+
# Threshold for query execution time below which query plans will not
|
152
|
+
# not be captured. Relevant only when `explain_enabled` is true.
|
153
|
+
# explain_threshold: 0.5
|
154
|
+
|
155
|
+
# Error collector captures information about uncaught exceptions and
|
156
|
+
# sends them to RPM for viewing
|
157
|
+
error_collector:
|
158
|
+
|
159
|
+
# Error collector is enabled by default. Set this to false to turn
|
160
|
+
# it off. This feature is only available at the Silver and above
|
161
|
+
# product levels
|
162
|
+
enabled: true
|
163
|
+
|
164
|
+
# Rails Only - tells error collector whether or not to capture a
|
165
|
+
# source snippet around the place of the error when errors are View
|
166
|
+
# related.
|
167
|
+
capture_source: true
|
168
|
+
|
169
|
+
# To stop specific errors from reporting to RPM, set this property
|
170
|
+
# to comma separated values. Default is to ignore routing errors
|
171
|
+
# which are how 404's get triggered.
|
172
|
+
#
|
173
|
+
ignore_errors: ActionController::RoutingError
|
174
|
+
|
175
|
+
# (Advanced) Uncomment this to ensure the cpu and memory samplers
|
176
|
+
# won't run. Useful when you are using the agent to monitor an
|
177
|
+
# external resource
|
178
|
+
# disable_samplers: true
|
179
|
+
|
180
|
+
# If you aren't interested in visibility in these areas, you can
|
181
|
+
# disable the instrumentation to reduce overhead.
|
182
|
+
#
|
183
|
+
# disable_view_instrumentation: true
|
184
|
+
# disable_activerecord_instrumentation: true
|
185
|
+
# disable_memcache_instrumentation: true
|
186
|
+
# disable_dj: true
|
187
|
+
|
188
|
+
# If you're interested in capturing memcache keys as though they
|
189
|
+
# were SQL uncomment this flag. Note that this does increase
|
190
|
+
# overhead slightly on every memcached call, and can have security
|
191
|
+
# implications if your memcached keys are sensitive
|
192
|
+
# capture_memcache_keys: true
|
193
|
+
|
194
|
+
# Certain types of instrumentation such as GC stats will not work if
|
195
|
+
# you are running multi-threaded. Please let us know.
|
196
|
+
# multi_threaded = false
|
197
|
+
|
198
|
+
# Application Environments
|
199
|
+
# ------------------------------------------
|
200
|
+
# Environment specific settings are in this section.
|
201
|
+
# For Rails applications, RAILS_ENV is used to determine the environment
|
202
|
+
# For Java applications, pass -Dnewrelic.environment <environment> to set
|
203
|
+
# the environment
|
204
|
+
|
205
|
+
# NOTE if your application has other named environments, you should
|
206
|
+
# provide newrelic configuration settings for these environments here.
|
207
|
+
|
208
|
+
development:
|
209
|
+
<<: *default_settings
|
210
|
+
# Turn off communication to RPM service in development mode (also
|
211
|
+
# 'enabled').
|
212
|
+
# NOTE: for initial evaluation purposes, you may want to temporarily
|
213
|
+
# turn the agent on in development mode.
|
214
|
+
monitor_mode: false
|
215
|
+
|
216
|
+
# Rails Only - when running in Developer Mode, the New Relic Agent will
|
217
|
+
# present performance information on the last 100 transactions you have
|
218
|
+
# executed since starting the mongrel.
|
219
|
+
# NOTE: There is substantial overhead when running in developer mode.
|
220
|
+
# Do not use for production or load testing.
|
221
|
+
developer_mode: true
|
222
|
+
|
223
|
+
# Enable textmate links
|
224
|
+
# textmate: true
|
225
|
+
|
226
|
+
test:
|
227
|
+
<<: *default_settings
|
228
|
+
# It almost never makes sense to turn on the agent when running
|
229
|
+
# unit, functional or integration tests or the like.
|
230
|
+
monitor_mode: false
|
231
|
+
|
232
|
+
# Turn on the agent in production for 24x7 monitoring. NewRelic
|
233
|
+
# testing shows an average performance impact of < 5 ms per
|
234
|
+
# transaction, you you can leave this on all the time without
|
235
|
+
# incurring any user-visible performance degradation.
|
236
|
+
production:
|
237
|
+
<<: *default_settings
|
238
|
+
monitor_mode: true
|
239
|
+
|
240
|
+
# Many applications have a staging environment which behaves
|
241
|
+
# identically to production. Support for that environment is provided
|
242
|
+
# here. By default, the staging environment has the agent turned on.
|
243
|
+
staging:
|
244
|
+
<<: *default_settings
|
245
|
+
monitor_mode: true
|
246
|
+
app_name: <%= @app_name %> (Staging)
|