honkster-newrelic_rpm 2.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/CHANGELOG +462 -0
  2. data/LICENSE +37 -0
  3. data/README.rdoc +172 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +34 -0
  8. data/install.rb +9 -0
  9. data/lib/new_relic/agent.rb +382 -0
  10. data/lib/new_relic/agent/agent.rb +741 -0
  11. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  12. data/lib/new_relic/agent/chained_call.rb +13 -0
  13. data/lib/new_relic/agent/error_collector.rb +131 -0
  14. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  15. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
  16. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
  17. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +409 -0
  19. data/lib/new_relic/agent/instrumentation/data_mapper.rb +58 -0
  20. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  21. data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
  22. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  23. data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
  24. data/lib/new_relic/agent/instrumentation/metric_frame.rb +319 -0
  25. data/lib/new_relic/agent/instrumentation/net.rb +17 -0
  26. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  28. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  29. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  30. data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
  31. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
  32. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
  33. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  34. data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
  35. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
  36. data/lib/new_relic/agent/method_tracer.rb +350 -0
  37. data/lib/new_relic/agent/sampler.rb +50 -0
  38. data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
  39. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  40. data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
  41. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  42. data/lib/new_relic/agent/shim_agent.rb +25 -0
  43. data/lib/new_relic/agent/stats_engine.rb +24 -0
  44. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  45. data/lib/new_relic/agent/stats_engine/samplers.rb +83 -0
  46. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  47. data/lib/new_relic/agent/transaction_sampler.rb +330 -0
  48. data/lib/new_relic/agent/worker_loop.rb +81 -0
  49. data/lib/new_relic/collection_helper.rb +71 -0
  50. data/lib/new_relic/command.rb +85 -0
  51. data/lib/new_relic/commands/deployments.rb +105 -0
  52. data/lib/new_relic/commands/install.rb +81 -0
  53. data/lib/new_relic/control.rb +203 -0
  54. data/lib/new_relic/control/configuration.rb +149 -0
  55. data/lib/new_relic/control/frameworks/external.rb +13 -0
  56. data/lib/new_relic/control/frameworks/merb.rb +24 -0
  57. data/lib/new_relic/control/frameworks/rails.rb +126 -0
  58. data/lib/new_relic/control/frameworks/rails3.rb +60 -0
  59. data/lib/new_relic/control/frameworks/ruby.rb +36 -0
  60. data/lib/new_relic/control/frameworks/sinatra.rb +18 -0
  61. data/lib/new_relic/control/instrumentation.rb +95 -0
  62. data/lib/new_relic/control/logging_methods.rb +74 -0
  63. data/lib/new_relic/control/profiling.rb +24 -0
  64. data/lib/new_relic/control/server_methods.rb +88 -0
  65. data/lib/new_relic/delayed_job_injection.rb +27 -0
  66. data/lib/new_relic/histogram.rb +91 -0
  67. data/lib/new_relic/local_environment.rb +333 -0
  68. data/lib/new_relic/merbtasks.rb +6 -0
  69. data/lib/new_relic/metric_data.rb +42 -0
  70. data/lib/new_relic/metric_parser.rb +136 -0
  71. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  72. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  73. data/lib/new_relic/metric_parser/active_record.rb +28 -0
  74. data/lib/new_relic/metric_parser/apdex.rb +88 -0
  75. data/lib/new_relic/metric_parser/controller.rb +62 -0
  76. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  77. data/lib/new_relic/metric_parser/errors.rb +6 -0
  78. data/lib/new_relic/metric_parser/external.rb +50 -0
  79. data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
  80. data/lib/new_relic/metric_parser/other_transaction.rb +36 -0
  81. data/lib/new_relic/metric_parser/view.rb +61 -0
  82. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  83. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  84. data/lib/new_relic/metric_spec.rb +67 -0
  85. data/lib/new_relic/metrics.rb +9 -0
  86. data/lib/new_relic/noticed_error.rb +24 -0
  87. data/lib/new_relic/rack/developer_mode.rb +257 -0
  88. data/lib/new_relic/rack/metric_app.rb +64 -0
  89. data/lib/new_relic/rack/mongrel_rpm.ru +26 -0
  90. data/lib/new_relic/rack/newrelic.yml +27 -0
  91. data/lib/new_relic/rack_app.rb +6 -0
  92. data/lib/new_relic/recipes.rb +82 -0
  93. data/lib/new_relic/stats.rb +368 -0
  94. data/lib/new_relic/timer_lib.rb +27 -0
  95. data/lib/new_relic/transaction_analysis.rb +119 -0
  96. data/lib/new_relic/transaction_sample.rb +586 -0
  97. data/lib/new_relic/url_rule.rb +14 -0
  98. data/lib/new_relic/version.rb +55 -0
  99. data/lib/new_relic_api.rb +276 -0
  100. data/lib/newrelic_rpm.rb +49 -0
  101. data/lib/tasks/all.rb +4 -0
  102. data/lib/tasks/install.rake +7 -0
  103. data/lib/tasks/tests.rake +15 -0
  104. data/newrelic.yml +246 -0
  105. data/newrelic_rpm.gemspec +254 -0
  106. data/recipes/newrelic.rb +6 -0
  107. data/test/active_record_fixtures.rb +55 -0
  108. data/test/config/newrelic.yml +48 -0
  109. data/test/config/test_control.rb +36 -0
  110. data/test/new_relic/agent/active_record_instrumentation_test.rb +286 -0
  111. data/test/new_relic/agent/agent_controller_test.rb +294 -0
  112. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  113. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  114. data/test/new_relic/agent/collection_helper_test.rb +125 -0
  115. data/test/new_relic/agent/error_collector_test.rb +163 -0
  116. data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
  117. data/test/new_relic/agent/method_tracer_test.rb +340 -0
  118. data/test/new_relic/agent/metric_data_test.rb +53 -0
  119. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  120. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  121. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  122. data/test/new_relic/agent/rpm_agent_test.rb +142 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  124. data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
  125. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
  126. data/test/new_relic/agent/task_instrumentation_test.rb +188 -0
  127. data/test/new_relic/agent/testable_agent.rb +13 -0
  128. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  129. data/test/new_relic/agent/transaction_sample_test.rb +192 -0
  130. data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
  131. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  132. data/test/new_relic/control_test.rb +127 -0
  133. data/test/new_relic/deployments_api_test.rb +69 -0
  134. data/test/new_relic/environment_test.rb +75 -0
  135. data/test/new_relic/metric_parser_test.rb +226 -0
  136. data/test/new_relic/metric_spec_test.rb +177 -0
  137. data/test/new_relic/rack/episodes_test.rb +318 -0
  138. data/test/new_relic/shim_agent_test.rb +9 -0
  139. data/test/new_relic/stats_test.rb +312 -0
  140. data/test/new_relic/version_number_test.rb +89 -0
  141. data/test/test_contexts.rb +28 -0
  142. data/test/test_helper.rb +72 -0
  143. data/ui/helpers/developer_mode_helper.rb +359 -0
  144. data/ui/helpers/google_pie_chart.rb +49 -0
  145. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  146. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  147. data/ui/views/newrelic/_sample.rhtml +20 -0
  148. data/ui/views/newrelic/_segment.rhtml +29 -0
  149. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  150. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  151. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  152. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  153. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  154. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  155. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  156. data/ui/views/newrelic/_table.rhtml +12 -0
  157. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  158. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  159. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  160. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  161. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  162. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  163. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  164. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  165. data/ui/views/newrelic/file/images/textmate.png +0 -0
  166. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  167. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  168. data/ui/views/newrelic/file/stylesheets/style.css +484 -0
  169. data/ui/views/newrelic/index.rhtml +59 -0
  170. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  171. data/ui/views/newrelic/show_sample.rhtml +79 -0
  172. data/ui/views/newrelic/show_source.rhtml +3 -0
  173. data/ui/views/newrelic/threads.rhtml +52 -0
  174. metadata +307 -0
data/LICENSE ADDED
@@ -0,0 +1,37 @@
1
+ Copyright (c) 2008-2009 New Relic, Inc. All rights reserved.
2
+
3
+ Certain inventions disclosed in this file may be claimed within
4
+ patents owned or patent applications filed by New Relic, Inc. or third
5
+ parties.
6
+
7
+ Subject to the terms of this notice, New Relic grants you a
8
+ nonexclusive, nontransferable license, without the right to
9
+ sublicense, to (a) install and execute one copy of these files on any
10
+ number of workstations owned or controlled by you and (b) distribute
11
+ verbatim copies of these files to third parties. As a condition to the
12
+ foregoing grant, you must provide this notice along with each copy you
13
+ distribute and you must not remove, alter, or obscure this notice. All
14
+ other use, reproduction, modification, distribution, or other
15
+ exploitation of these files is strictly prohibited, except as may be set
16
+ forth in a separate written license agreement between you and New
17
+ Relic. The terms of any such license agreement will control over this
18
+ notice. The license stated above will be automatically terminated and
19
+ revoked if you exceed its scope or violate any of the terms of this
20
+ notice.
21
+
22
+ This License does not grant permission to use the trade names,
23
+ trademarks, service marks, or product names of New Relic, except as
24
+ required for reasonable and customary use in describing the origin of
25
+ this file and reproducing the content of this notice. You may not
26
+ mark or brand this file with any trade name, trademarks, service
27
+ marks, or product names other than the original brand (if any)
28
+ provided by New Relic.
29
+
30
+ Unless otherwise expressly agreed by New Relic in a separate written
31
+ license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
32
+ ANY KIND, including without any implied warranties of MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
34
+ condition to your use of these files, you are solely responsible for
35
+ such use. New Relic will have no liability to you for direct,
36
+ indirect, consequential, incidental, special, or punitive damages or
37
+ for lost profits or data.
@@ -0,0 +1,172 @@
1
+ = New Relic RPM
2
+
3
+ New Relic RPM is a Ruby performance management system, developed by
4
+ New Relic, Inc (http://www.newrelic.com). RPM provides you with deep
5
+ information about the performance of your Ruby on Rails or Merb
6
+ application as it runs in production. The New Relic Agent is
7
+ dual-purposed as a either a Rails plugin or a Gem, hosted on
8
+ github[http://github.com/newrelic/rpm/tree/master] and Rubyforge.
9
+
10
+ The New Relic Agent runs in one of two modes:
11
+
12
+ ==== Production Mode
13
+
14
+ Low overhead instrumentation that captures detailed information on
15
+ your application running in production and transmits them to
16
+ rpm.newrelic.com where you can monitor them in real time.
17
+
18
+ ==== Developer Mode
19
+
20
+ A Rack middleware that maps /newrelic to an application for showing
21
+ detailed performance metrics on a page by page basis. Installed
22
+ automatically in Rails applications.
23
+
24
+ == Supported Environments
25
+
26
+ * Ruby 1.8.6, 1.8.7 or 1.9.1, including REE
27
+ * JRuby 1.3 minimum
28
+ * Rails 1.2.6 or later for Production Mode
29
+ * Rails 2.2 or later for Developer Mode
30
+ * Merb 1.0 or later
31
+ * Sinatra
32
+ * Rack
33
+
34
+ Any Rack based framework should work but may not be tested. Install
35
+ RPM as a gem and add the Developer Mode middleware if desired. Report
36
+ any problems to support@newrelic.com.
37
+
38
+ You can also monitor non-web applications. Refer to the "Other
39
+ Environments" section under "Getting Started".
40
+
41
+ = Getting Started
42
+
43
+ Install the RPM agent as a gem. If you are using Rails you can
44
+ install the gem as a plug-in--details below.
45
+
46
+ gem install newrelic_rpm
47
+
48
+ To monitor your applications in production, create an account at
49
+ http://newrelic.com/get-RPM.html. There you can
50
+ sign up for a free Lite account or one of our paid subscriptions.
51
+
52
+ Once you receive the welcome e-mail with a license key and
53
+ +newrelic.yml+ file, copy the +newrelic.yml+ file into your app config
54
+ directory.
55
+
56
+ All agent configuration is done in the +newrelic.yml+ file. This file
57
+ is by default read from the +config+ directory of the application root
58
+ and is subsequently searched for in the application root directory,
59
+ and then in a <tt>~/.newrelic</tt> directory
60
+
61
+ === Rails Installation
62
+
63
+ You can install the agent as a plug-in or a Gem. To install the agent
64
+ as a Rails plug-in, do the following:
65
+
66
+ script/plugin install http://newrelic.rubyforge.org/svn/newrelic_rpm
67
+
68
+ If using the Agent as a gem, edit +environment.rb+ and add to the initalizer block:
69
+
70
+ config.gem "newrelic_rpm"
71
+
72
+ === Merb Installation
73
+
74
+ To monitor a merb app install the newrelic_rpm gem and add
75
+
76
+ dependency 'newrelic_rpm'
77
+
78
+ to your init.rb file.
79
+
80
+ === Sinatra Installation
81
+
82
+ To use RPM with a Sinatra app, add
83
+ require 'newrelic_rpm'
84
+ in your Sinatra app, below the Sinatra require directive.
85
+
86
+ Then make sure you set RACK_ENV to the environment corresponding to the
87
+ configuration definitions in the newrelic.yml file; i.e., development,
88
+ staging, production, etc.
89
+
90
+ To use Developer Mode in Sinatra, add NewRelic::Rack::DeveloperMode to
91
+ the middleware stack. See the +config.ru+ sample below.
92
+
93
+ === Other Environments
94
+
95
+ You can use RPM to monitor any Ruby application. Add
96
+ require 'newrelic_rpm'
97
+ to your startup sequence and then manually start the agent using
98
+ NewRelic::Agent.manual_start
99
+
100
+ To instrument Rack based applications, refer to the docs in
101
+ NewRelic::Agent::Instrumentation::Rack.
102
+
103
+ Refer to the docs in NewRelic for details on how to monitor other web
104
+ frameworks, background jobs, and daemons.
105
+
106
+ Also, see if your environment is already supported by the
107
+ rpm_contrib[http://newrelic.github.com/rpm_contrib] gem.
108
+
109
+ == Developer Mode
110
+
111
+ When running the RPM Developer Mode, the RPM Agent will track the
112
+ performance of every HTTP request serviced by your application, and
113
+ store in memory this information for the last 100 HTTP transactions.
114
+
115
+ To view this performance information, including detailed SQL statement
116
+ analysis, open +/newrelic+ in your web application. For instance if
117
+ you are running mongrel or thin on port 3000, enter the following into
118
+ your browser:
119
+
120
+ http://localhost:3000/newrelic
121
+
122
+ Developer Mode is only initialized if the +developer_mode+ setting in
123
+ the newrelic.yml file is set to true. By default, it is turned off in
124
+ all environments but +development+.
125
+
126
+ ==== Developer Mode in Rails
127
+
128
+ Developer Mode is available automatically in Rails Applications
129
+ based on Rails 2.3 and later. No additional configuration is
130
+ required.
131
+
132
+ For earlier versions of Rails that support Rack, you can use
133
+ a +config.ru+ as below.
134
+
135
+ ==== Developer Mode in Rack Applications
136
+
137
+ Developer Mode is available for any Rack based application such as
138
+ Sinatra by installing the NewRelic::Rack::DeveloperMode
139
+ middleware. This middleware passes all requests that do not start with
140
+ /newrelic.
141
+
142
+ Here's an example entry for Developer Mode in a +config.ru+ file:
143
+
144
+ require 'new_relic/rack_app'
145
+ use NewRelic::Rack::DeveloperMode
146
+
147
+
148
+ == Production Mode
149
+
150
+ When your application runs in the production environment, the New
151
+ Relic agent runs in production mode. It connects to the New Relic RPM
152
+ service and sends deep performance data to the RPM service for your
153
+ analysis. To view this data, log in to http://rpm.newrelic.com.
154
+
155
+ NOTE: You must have a valid account and license key to view this data
156
+ online. Refer to instructions in *Getting Started*, below.
157
+
158
+
159
+ = Support
160
+
161
+ Reach out to us--and to fellow RPM users--at
162
+ support.newrelic.com[http://support.newrelic.com/discussions/support].
163
+ There you'll find documentation, FAQs, and forums where you can submit
164
+ suggestions and discuss RPM with New Relic staff and other users.
165
+
166
+ Find a bug? E-mail support@newrelic.com, or post it to
167
+ support.newrelic.com[http://support.newrelic.com/discussions/support].
168
+
169
+ Thank you, and may your application scale to infinity plus one.
170
+
171
+ Lew Cirne, Founder and CEO<br/>
172
+ New Relic, Inc.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rack'
4
+ require 'rack/handler/mongrel'
5
+ require 'optparse'
6
+
7
+ port = 3000
8
+ options = { }
9
+ appname = nil
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: #{File.basename($0)} [options] [app_name]"
12
+ opts.on("-p", "--port=port", Integer, "default: #{port}") { | port | }
13
+ opts.on("--[no-]logging", "turn off request logging" ) { | l | options[:logging] = l }
14
+ opts.on("--license=rpm_license_key", "override license key" ) { | l | options[:license_key] = l }
15
+ opts.on("--install", "install a newrelic.yml template" ) { | l | options[:install] = true }
16
+ opts.separator ""
17
+ opts.separator "app_name is the name of the application where the metrics will be stored"
18
+ opts.separator ""
19
+ # The rackup file references this var
20
+ appname = opts.parse!(ARGV.clone).first
21
+ end
22
+
23
+ options[:app_name] = appname if appname
24
+
25
+ ru_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "new_relic", "rack", "mongrel_rpm.ru"))
26
+ rackup_code = File.read ru_file
27
+ builder = Rack::Builder.new { eval rackup_code, binding, ru_file }
28
+
29
+ options = { :Host => '127.0.0.1', :Port => port }
30
+ Rack::Handler::Mongrel.run(builder.to_app, options) do | server |
31
+ NewRelic::Control.instance.log! "Started Mongrel listening for '#{NewRelic::Control.instance.app_names.join(" and ")}' data at #{server.host}:#{server.port}"
32
+ end
33
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # executes one of the commands in the new_relic/commands directory
3
+ # pass the name of the command as an argument
4
+
5
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..','lib'))
6
+ require 'new_relic/command'
7
+ begin
8
+ NewRelic::Command.run
9
+ rescue NewRelic::Command::CommandFailure => failure
10
+ STDERR.puts failure.message
11
+ STDERR.puts failure.options if failure.options
12
+ exit 1
13
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # This command has been renamed "newrelic"
3
+ # executes one of the commands in the new_relic/commands directory
4
+ # pass the name of the command as an argument
5
+ load File.dirname(__FILE__) + '/newrelic'
@@ -0,0 +1,34 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIC5zCCAlACAQEwDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRp
3
+ b24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENs
4
+ YXNzIDEgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZh
5
+ bGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNTIy
6
+ MjM0OFoXDTE5MDYyNTIyMjM0OFowgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTmV0
7
+ d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDEg
8
+ UG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0
9
+ LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMIGfMA0GCSqGSIb3DQEBAQUA
10
+ A4GNADCBiQKBgQDYWYJ6ibiWuqYvaG9YLqdUHAZu9OqNSLwxlBfw8068srg1knaw0KWlAdcAAxIi
11
+ GQj4/xEjm84H9b9pGib+TunRf50sQB1ZaG6m+FiwnRqP0z/x3BkGgagO4DrdyFNFCQbmD3DD+kCm
12
+ DuJWBQ8YTfwggtFzVXSNdnKgHZ0dwN0/cQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAFBoPUn0LBwG
13
+ lN+VYH+Wexf+T3GtZMjdd9LvWVXoP+iOBSoh8gfStadS/pyxtuJbdxdA6nLWI8sogTLDAHkY7FkX
14
+ icnGah5xyf23dKUlRWnFSKsZ4UWKJWsZ7uW7EvV/96aNUcPwnXS3qT6gpf+2SQMT2iLM7XGCK5nP
15
+ Orf1LXLI
16
+ -----END CERTIFICATE-----
17
+
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIC5zCCAlACAQEwDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRp
20
+ b24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENs
21
+ YXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZh
22
+ bGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNjAw
23
+ MTk1NFoXDTE5MDYyNjAwMTk1NFowgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTmV0
24
+ d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIg
25
+ UG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0
26
+ LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMIGfMA0GCSqGSIb3DQEBAQUA
27
+ A4GNADCBiQKBgQDOOnHK5avIWZJV16vYdA757tn2VUdZZUcOBVXc65g2PFxTXdMwzzjsvUGJ7SVC
28
+ CSRrCl6zfN1SLUzm1NZ9WlmpZdRJEy0kTRxQb7XBhVQ7/nHk01xC+YDgkRoKWzk2Z/M/VXwbP7Rf
29
+ ZHM047QSv4dk+NoS/zcnwbNDu+97bi5p9wIDAQABMA0GCSqGSIb3DQEBBQUAA4GBADt/UG9vUJSZ
30
+ SWI4OB9L+KXIPqeCgfYrx+jFzug6EILLGACOTb2oWH+heQC1u+mNr0HZDzTuIYEZoDJJKPTEjlbV
31
+ UjP9UNV+mWwD5MlM/Mtsq2azSiGM5bUMMj4QssxsodyamEwCW/POuZ6lcg5Ktz885hZo+L7tdEy8
32
+ W9ViH0Pd
33
+ -----END CERTIFICATE-----
34
+
@@ -0,0 +1,9 @@
1
+ if __FILE__ == $0 || $0 =~ /script\/plugin/
2
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
3
+ require 'new_relic/command'
4
+ begin
5
+ NewRelic::Command::Install.new(:quiet => true, :app_name => 'My Application').run
6
+ rescue NewRelic::Command::CommandFailure => e
7
+ $stderr.puts e.message
8
+ end
9
+ end
@@ -0,0 +1,382 @@
1
+ # = New Relic RPM Agent
2
+ #
3
+ # New Relic RPM is a performance monitoring application for Ruby
4
+ # applications running in production. For more information on RPM
5
+ # please visit http://www.newrelic.com.
6
+ #
7
+ # The New Relic Agent can be installed in Rails applications to gather
8
+ # runtime performance metrics, traces, and errors for display in a
9
+ # Developer Mode UI (mapped to /newrelic in your application server)
10
+ # or for monitoring and analysis at http://rpm.newrelic.com with just
11
+ # about any Ruby application.
12
+ #
13
+ # == Getting Started
14
+ # For instructions on installation and setup, see
15
+ # the README[link:./files/README_rdoc.html] file.
16
+ #
17
+ # == Using with Rack/Metal
18
+ #
19
+ # To instrument Rack middlwares or Metal apps, refer to the docs in
20
+ # NewRelic::Agent::Instrumentation::Rack.
21
+ #
22
+ # == Agent API
23
+ #
24
+ # For details on the Agent API, refer to NewRelic::Agent.
25
+ #
26
+ # == Customizing RPM
27
+ #
28
+ # For detailed information on customizing the RPM Agent
29
+ # please visit our {support and documentation site}[http://support.newrelic.com].
30
+ #
31
+ module NewRelic
32
+ # == Agent APIs
33
+ # This module contains the public API methods for the Agent.
34
+ #
35
+ # For adding custom instrumentation to method invocations, refer to
36
+ # the docs in the class NewRelic::Agent::MethodTracer.
37
+ #
38
+ # For information on how to customize the controller
39
+ # instrumentation, or to instrument something other than Rails so
40
+ # that high level dispatcher actions or background tasks show up as
41
+ # first class operations in RPM, refer to
42
+ # NewRelic::Agent::Instrumentation::ControllerInstrumentation and
43
+ # NewRelic::Agent::Instrumentation::ControllerInstrumentation::ClassMethods.
44
+ #
45
+ # Methods in this module as well as documented methods in
46
+ # NewRelic::Agent::MethodTracer and
47
+ # NewRelic::Agent::Instrumentation::ControllerInstrumentation are
48
+ # available to applications. When the agent is not enabled the
49
+ # method implementations are stubbed into no-ops to reduce overhead.
50
+ #
51
+ # Methods and classes in other parts of the agent are not guaranteed
52
+ # to be available between releases.
53
+ #
54
+ # Refer to the online docs at support.newrelic.com to see how to
55
+ # access the data collected by custom instrumentation, or e-mail
56
+ # support at New Relic for help.
57
+ module Agent
58
+ extend self
59
+
60
+ require 'new_relic/version'
61
+ require 'new_relic/local_environment'
62
+ require 'new_relic/stats'
63
+ require 'new_relic/metrics'
64
+ require 'new_relic/metric_spec'
65
+ require 'new_relic/metric_data'
66
+ require 'new_relic/metric_parser'
67
+ require 'new_relic/collection_helper'
68
+ require 'new_relic/transaction_analysis'
69
+ require 'new_relic/transaction_sample'
70
+ require 'new_relic/url_rule'
71
+ require 'new_relic/noticed_error'
72
+ require 'new_relic/histogram'
73
+ require 'new_relic/timer_lib'
74
+
75
+ require 'new_relic/agent/chained_call'
76
+ require 'new_relic/agent/agent'
77
+ require 'new_relic/agent/shim_agent'
78
+ require 'new_relic/agent/method_tracer'
79
+ require 'new_relic/agent/worker_loop'
80
+ require 'new_relic/agent/stats_engine'
81
+ require 'new_relic/agent/transaction_sampler'
82
+ require 'new_relic/agent/error_collector'
83
+ require 'new_relic/agent/busy_calculator'
84
+ require 'new_relic/agent/sampler'
85
+
86
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
87
+
88
+ require 'new_relic/agent/samplers/cpu_sampler'
89
+ require 'new_relic/agent/samplers/memory_sampler'
90
+ require 'new_relic/agent/samplers/object_sampler'
91
+ require 'new_relic/agent/samplers/delayed_job_lock_sampler'
92
+ require 'set'
93
+ require 'thread'
94
+ require 'resolv'
95
+
96
+ # An exception that is thrown by the server if the agent license is invalid.
97
+ class LicenseException < StandardError; end
98
+
99
+ # An exception that forces an agent to stop reporting until its mongrel is restarted.
100
+ class ForceDisconnectException < StandardError; end
101
+
102
+ # An exception that forces an agent to restart.
103
+ class ForceRestartException < StandardError; end
104
+
105
+ # Used to blow out of a periodic task without logging a an error, such as for routine
106
+ # failures.
107
+ class ServerConnectionException < StandardError; end
108
+
109
+ # Used for when a transaction trace or error report has too much
110
+ # data, so we reset the queue to clear the extra-large item
111
+ class PostTooBigException < ServerConnectionException; end
112
+
113
+ # Reserved for future use. Meant to represent a problem on the server side.
114
+ class ServerError < StandardError; end
115
+
116
+ class BackgroundLoadingError < StandardError; end
117
+
118
+ @agent = nil
119
+
120
+ # The singleton Agent instance. Used internally.
121
+ def agent #:nodoc:
122
+ raise "Plugin not initialized!" if @agent.nil?
123
+ @agent
124
+ end
125
+
126
+ def agent= new_instance #:nodoc:
127
+ @agent = new_instance
128
+ end
129
+
130
+ alias instance agent #:nodoc:
131
+
132
+ # Get or create a statistics gatherer that will aggregate numerical data
133
+ # under a metric name.
134
+ #
135
+ # +metric_name+ should follow a slash separated path convention. Application
136
+ # specific metrics should begin with "Custom/".
137
+ #
138
+ # Return a NewRelic::Stats that accepts data
139
+ # via calls to add_data_point(value).
140
+ def get_stats(metric_name, use_scope=false)
141
+ @agent.stats_engine.get_stats(metric_name, use_scope)
142
+ end
143
+
144
+ alias get_stats_no_scope get_stats
145
+
146
+ # Get the logger for the agent. Available after the agent has initialized.
147
+ # This sends output to the agent log file.
148
+ def logger
149
+ NewRelic::Control.instance.log
150
+ end
151
+
152
+ # Call this to manually start the Agent in situations where the Agent does
153
+ # not auto-start.
154
+ #
155
+ # When the app environment loads, so does the Agent. However, the
156
+ # Agent will only connect to RPM if a web front-end is found. If
157
+ # you want to selectively monitor ruby processes that don't use
158
+ # web plugins, then call this method in your code and the Agent
159
+ # will fire up and start reporting to RPM.
160
+ #
161
+ # Options are passed in as overrides for values in the
162
+ # newrelic.yml, such as app_name. In addition, the option +log+
163
+ # will take a logger that will be used instead of the standard
164
+ # file logger. The setting for the newrelic.yml section to use
165
+ # (ie, RAILS_ENV) can be overridden with an :env argument.
166
+ #
167
+ def manual_start(options={})
168
+ raise unless Hash === options
169
+ NewRelic::Control.instance.init_plugin({ :agent_enabled => true, :sync_startup => true }.merge(options))
170
+ end
171
+
172
+ # Register this method as a callback for processes that fork
173
+ # jobs.
174
+ #
175
+ # If the master/parent connects to the agent prior to forking the
176
+ # agent in the forked process will use that agent_run. Otherwise
177
+ # the forked process will establish a new connection with the
178
+ # server.
179
+ #
180
+ # Use this especially when you fork the process to run background
181
+ # jobs or other work. If you are doing this with a web dispatcher
182
+ # that forks worker processes then you will need to force the
183
+ # agent to reconnect, which it won't do by default. Passenger and
184
+ # Unicorn are already handled, nothing special needed for them.
185
+ #
186
+ # Options:
187
+ # * <tt>:force_reconnect => true</tt> to force the spawned process to
188
+ # establish a new connection, such as when forking a long running process.
189
+ # The default is false--it will only connect to the server if the parent
190
+ # had not connected.
191
+ # * <tt>:keep_retrying => false</tt> if we try to initiate a new
192
+ # connection, this tells me to only try it once so this method returns
193
+ # quickly if there is some kind of latency with the server.
194
+ def after_fork(options={})
195
+ agent.after_fork(options)
196
+ end
197
+
198
+ # Clear out any unsent metric data.
199
+ def reset_stats
200
+ agent.reset_stats
201
+ end
202
+
203
+ # Shutdown the agent. Call this before exiting. Sends any queued data
204
+ # and kills the background thread.
205
+ def shutdown
206
+ agent.shutdown
207
+ end
208
+
209
+ # Add instrumentation files to the agent. The argument should be
210
+ # a glob matching ruby scripts which will be executed at the time
211
+ # instrumentation is loaded. Since instrumentation is not loaded
212
+ # when the agent is not running it's better to use this method to
213
+ # register instrumentation than just loading the files directly,
214
+ # although that probably also works.
215
+ def add_instrumentation file_pattern
216
+ NewRelic::Control.instance.add_instrumentation file_pattern
217
+ end
218
+
219
+ # This method sets the block sent to this method as a sql
220
+ # obfuscator. The block will be called with a single String SQL
221
+ # statement to obfuscate. The method must return the obfuscated
222
+ # String SQL. If chaining of obfuscators is required, use type =
223
+ # :before or :after
224
+ #
225
+ # type = :before, :replace, :after
226
+ #
227
+ # Example:
228
+ #
229
+ # NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
230
+ # my_obfuscator(sql)
231
+ # end
232
+ #
233
+ def set_sql_obfuscator(type = :replace, &block)
234
+ agent.set_sql_obfuscator type, &block
235
+ end
236
+
237
+
238
+ # This method sets the state of sql recording in the transaction
239
+ # sampler feature. Within the given block, no sql will be recorded
240
+ #
241
+ # usage:
242
+ #
243
+ # NewRelic::Agent.disable_sql_recording do
244
+ # ...
245
+ # end
246
+ #
247
+ def disable_sql_recording
248
+ state = agent.set_record_sql(false)
249
+ begin
250
+ yield
251
+ ensure
252
+ agent.set_record_sql(state)
253
+ end
254
+ end
255
+
256
+ # This method disables the recording of transaction traces in the given
257
+ # block. See also #disable_all_tracing
258
+ def disable_transaction_tracing
259
+ state = agent.set_record_tt(false)
260
+ begin
261
+ yield
262
+ ensure
263
+ agent.set_record_tt(state)
264
+ end
265
+ end
266
+
267
+ # Cancel the collection of the current transaction in progress, if
268
+ # any. Only affects the transaction started on this thread once
269
+ # it has started and before it has completed.
270
+ def abort_transaction!
271
+ # The class may not be loaded if the agent is disabled
272
+ if defined? NewRelic::Agent::Instrumentation::MetricFrame
273
+ NewRelic::Agent::Instrumentation::MetricFrame.abort_transaction!
274
+ end
275
+ end
276
+
277
+ # Yield to the block without collecting any metrics or traces in
278
+ # any of the subsequent calls. If executed recursively, will keep
279
+ # track of the first entry point and turn on tracing again after
280
+ # leaving that block. This uses the thread local
281
+ # +newrelic_untrace+
282
+ def disable_all_tracing
283
+ agent.push_trace_execution_flag(false)
284
+ yield
285
+ ensure
286
+ agent.pop_trace_execution_flag
287
+ end
288
+
289
+ # Check to see if we are capturing metrics currently on this thread.
290
+ def is_execution_traced?
291
+ Thread.current[:newrelic_untraced].nil? || Thread.current[:newrelic_untraced].last != false
292
+ end
293
+
294
+ # Set a filter to be applied to errors that RPM will track. The
295
+ # block should evalute to the exception to track (which could be
296
+ # different from the original exception) or nil to ignore this
297
+ # exception.
298
+ #
299
+ # The block is yielded to with the exception to filter.
300
+ #
301
+ # Return the new block or the existing filter Proc if no block is passed.
302
+ #
303
+ def ignore_error_filter(&block)
304
+ agent.error_collector.ignore_error_filter(&block)
305
+ end
306
+
307
+ # Record the given error in RPM. It will be passed through the
308
+ # #ignore_error_filter if there is one.
309
+ #
310
+ # * <tt>exception</tt> is the exception which will be recorded. May also be
311
+ # an error message.
312
+ # Options:
313
+ # * <tt>:uri</tt> => The request path, minus any request params or query string.
314
+ # * <tt>:referer</tt> => The URI of the referer
315
+ # * <tt>:metric</tt> => The metric name associated with the transaction
316
+ # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
317
+ # * <tt>:custom_params</tt> => Custom parameters
318
+ #
319
+ # Anything left over is treated as custom params.
320
+ #
321
+ def notice_error(exception, options={})
322
+ NewRelic::Agent::Instrumentation::MetricFrame.notice_error(exception, options)
323
+ end
324
+
325
+ # Add parameters to the current transaction trace (and traced error if any)
326
+ # on the call stack.
327
+ #
328
+ def add_custom_parameters(params)
329
+ NewRelic::Agent::Instrumentation::MetricFrame.add_custom_parameters(params)
330
+ end
331
+
332
+ # The #add_request_parameters method is aliased to #add_custom_parameters
333
+ # and is now deprecated.
334
+ alias add_request_parameters add_custom_parameters #:nodoc:
335
+
336
+ # Yield to a block that is run with a database metric name
337
+ # context. This means the Database instrumentation will use this
338
+ # for the metric name if it does not otherwise know about a model.
339
+ # This is re-entrant.
340
+ #
341
+ # * <tt>model</tt> is the DB model class
342
+ # * <tt>method</tt> is the name of the finder method or other
343
+ # method to identify the operation with.
344
+ def with_database_metric_name(model, method, &block)
345
+ if frame = NewRelic::Agent::Instrumentation::MetricFrame.current
346
+ frame.with_database_metric_name(model, method, &block)
347
+ else
348
+ yield
349
+ end
350
+ end
351
+
352
+ # Record a web transaction from an external source. This will
353
+ # process the response time, error, and score an apdex value.
354
+ #
355
+ # First argument is a float value, time in seconds. Option
356
+ # keys are strings.
357
+ #
358
+ # == Identifying the transaction
359
+ # * <tt>'uri' => uri</tt> to record the value for a given web request.
360
+ # If not provided, just record the aggregate dispatcher and apdex scores.
361
+ # * <tt>'metric' => metric_name</tt> to record with a general metric name
362
+ # like +OtherTransaction/Background/Class/method+. Ignored if +uri+ is
363
+ # provided.
364
+ #
365
+ # == Error options
366
+ # Provide one of the following:
367
+ # * <tt>'is_error' => true</tt> if an unknown error occurred
368
+ # * <tt>'error_message' => msg</tt> if an error message is available
369
+ # * <tt>'exception' => exception</tt> if a ruby exception is recorded
370
+ #
371
+ # == Misc options
372
+ # Additional information captured in errors
373
+ # * <tt>'referer' => referer_url</tt>
374
+ # * <tt>'request_params' => hash</tt> to record a set of name/value pairs as the
375
+ # request parameters.
376
+ # * <tt>'custom_params' => hash</tt> to record extra information in traced errors
377
+ #
378
+ def record_transaction(response_sec, options = {})
379
+ agent.record_transaction(response_sec, options)
380
+ end
381
+ end
382
+ end