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
@@ -0,0 +1,66 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
3
+
4
+ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
5
+ def setup
6
+ @log = ""
7
+ @logger = Logger.new(StringIO.new(@log))
8
+ @worker_loop = NewRelic::Agent::WorkerLoop.new
9
+ @worker_loop.stubs(:log).returns(@logger)
10
+ @test_start_time = Time.now
11
+ end
12
+
13
+ def test_add_task
14
+ @x = false
15
+ @worker_loop.run(0) do
16
+ @worker_loop.stop
17
+ @x = true
18
+ end
19
+ assert @x
20
+ end
21
+
22
+ def test_density
23
+ # This shows how the tasks stay aligned with the period and don't drift.
24
+ count = 0
25
+ start = Time.now
26
+ @worker_loop.run(0.2) do
27
+ count +=1
28
+ if count == 10
29
+ @worker_loop.stop
30
+ next
31
+ end
32
+ end
33
+ elapsed = Time.now - start
34
+ assert_in_delta 1.9, elapsed, 0.2
35
+ end
36
+ def test_task_error__standard
37
+ @logger.expects(:debug)
38
+ @logger.expects(:error)
39
+ # This loop task will run twice
40
+ done = false
41
+ @worker_loop.run(0) do
42
+ @worker_loop.stop
43
+ done = true
44
+ raise "Standard Error Test"
45
+ end
46
+ assert done
47
+ end
48
+ class BadBoy < Exception; end
49
+
50
+ def test_task_error__exception
51
+ @logger.expects(:error).once
52
+ @logger.expects(:debug).once
53
+ @worker_loop.run(0) do
54
+ @worker_loop.stop
55
+ raise BadBoy, "oops"
56
+ end
57
+ end
58
+ def test_task_error__server
59
+ @logger.expects(:error).never
60
+ @logger.expects(:debug).once
61
+ @worker_loop.run(0) do
62
+ @worker_loop.stop
63
+ raise NewRelic::Agent::ServerError, "Runtime Error Test"
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,127 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
3
+
4
+ class NewRelic::ControlTest < Test::Unit::TestCase
5
+
6
+ attr_reader :c
7
+
8
+ def setup
9
+ NewRelic::Agent.manual_start
10
+ @c = NewRelic::Control.instance
11
+ end
12
+ def shutdown
13
+ NewRelic::Agent.shutdown
14
+ end
15
+
16
+ def test_monitor_mode
17
+ assert ! @c.monitor_mode?
18
+ @c.settings.delete 'enabled'
19
+ @c.settings.delete 'monitor_mode'
20
+ assert !@c.monitor_mode?
21
+ @c['enabled'] = false
22
+ assert ! @c.monitor_mode?
23
+ @c['enabled'] = true
24
+ assert @c.monitor_mode?
25
+ @c['monitor_mode'] = nil
26
+ assert !@c.monitor_mode?
27
+ @c['monitor_mode'] = false
28
+ assert !@c.monitor_mode?
29
+ @c['monitor_mode'] = true
30
+ assert @c.monitor_mode?
31
+ ensure
32
+ @c['enabled'] = false
33
+ @c['monitor_mode'] = false
34
+ end
35
+
36
+ def test_test_config
37
+ assert_equal :rails, c.app if defined? Rails
38
+ assert_equal :test, c.app if !defined? Rails
39
+ assert_equal :test, c.framework
40
+ assert_match /test/i, c.dispatcher_instance_id
41
+ assert_equal nil, c.dispatcher
42
+ assert !c['enabled']
43
+ assert_equal false, c['monitor_mode']
44
+ c.local_env
45
+ end
46
+
47
+ def test_root
48
+ assert File.directory?(NewRelic::Control.newrelic_root), NewRelic::Control.newrelic_root
49
+ if defined?(Rails)
50
+ assert File.directory?(File.join(NewRelic::Control.newrelic_root, "lib")), NewRelic::Control.newrelic_root + "/lib"
51
+ end
52
+ end
53
+
54
+ def test_info
55
+ props = NewRelic::Control.instance.local_env.snapshot
56
+ if defined?(Rails)
57
+ assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last, props.inspect
58
+ end
59
+ end
60
+
61
+ def test_resolve_ip
62
+ assert_equal nil, c.send(:convert_to_ip_address, 'localhost')
63
+ assert_equal nil, c.send(:convert_to_ip_address, 'q1239988737.us')
64
+ # This might fail if you don't have a valid, accessible, DNS server
65
+ assert_equal '65.74.177.194', c.send(:convert_to_ip_address, 'rpm.newrelic.com')
66
+ end
67
+ def test_config_yaml_erb
68
+ assert_equal 'heyheyhey', c['erb_value']
69
+ assert_equal '', c['message']
70
+ assert_equal '', c['license_key']
71
+ end
72
+
73
+ def test_appnames
74
+ assert_equal %w[a b c], NewRelic::Control.instance.app_names
75
+ end
76
+
77
+ def test_config_booleans
78
+ assert_equal c['tval'], true
79
+ assert_equal c['fval'], false
80
+ assert_nil c['not_in_yaml_val']
81
+ assert_equal c['yval'], true
82
+ assert_equal c['sval'], 'sure'
83
+ end
84
+ def test_config_apdex
85
+ assert_equal 1.1, c.apdex_t
86
+ end
87
+ def test_transaction_threshold
88
+ assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
89
+ assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
90
+ end
91
+ def test_log_file_name
92
+ assert_match /newrelic_agent.log$/, c.instance_variable_get('@log_file')
93
+ end
94
+
95
+ def test_transaction_threshold__apdex
96
+ forced_start
97
+ assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
98
+ assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
99
+ end
100
+
101
+ def test_transaction_threshold__default
102
+
103
+ forced_start :transaction_tracer => { :transaction_threshold => nil}
104
+ assert_nil c['transaction_tracer']['transaction_threshold']
105
+ assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
106
+ end
107
+
108
+ def test_transaction_threshold__override
109
+ forced_start :transaction_tracer => { :transaction_threshold => 1}
110
+ assert_equal 1, c['transaction_tracer']['transaction_threshold']
111
+ assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
112
+ end
113
+ def test_merging_options
114
+ NewRelic::Control.send :public, :merge_options
115
+ @c.merge_options :api_port => 66, :transaction_tracer => { :explain_threshold => 2.0 }
116
+ assert_equal 66, NewRelic::Control.instance['api_port']
117
+ assert_equal 2.0, NewRelic::Control.instance['transaction_tracer']['explain_threshold']
118
+ assert_equal 'raw', NewRelic::Control.instance['transaction_tracer']['record_sql']
119
+ end
120
+ private
121
+ def forced_start overrides = {}
122
+ NewRelic::Agent.manual_start overrides
123
+ # This is to force the agent to start again.
124
+ NewRelic::Agent.instance.stubs(:started?).returns(nil)
125
+ NewRelic::Agent.instance.start
126
+ end
127
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../lib/new_relic/command'))
3
+ require 'rubygems'
4
+ require 'mocha'
5
+
6
+ class NewRelic::DeploymentsTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ NewRelic::Command::Deployments.class_eval do
10
+ attr_accessor :messages, :exit_status, :errors, :revision
11
+ def err(message); @errors = @errors ? @errors + message : message; end
12
+ def info(message); @messages = @messages ? @messages + message : message; end
13
+ def just_exit(status=0); @exit_status ||= status; end
14
+ end
15
+ end
16
+ def teardown
17
+ return unless @deployment
18
+ puts @deployment.errors
19
+ puts @deployment.messages
20
+ puts @deployment.exit_status
21
+ end
22
+ def test_help
23
+ begin
24
+ NewRelic::Command::Deployments.new "-h"
25
+ fail "should have thrown"
26
+ rescue NewRelic::Command::CommandFailure => c
27
+ assert_match /^Usage/, c.message
28
+ end
29
+ end
30
+ def test_bad_command
31
+ assert_raise NewRelic::Command::CommandFailure do
32
+ NewRelic::Command::Deployments.new ["-foo", "bar"]
33
+ end
34
+ end
35
+ def test_interactive
36
+ mock_the_connection
37
+ @deployment = NewRelic::Command::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
38
+ assert_nil @deployment.exit_status
39
+ assert_nil @deployment.errors
40
+ assert_equal '3838', @deployment.revision
41
+ @deployment.run
42
+ @deployment = nil
43
+ end
44
+
45
+ def test_command_line_run
46
+ mock_the_connection
47
+ # @mock_response.expects(:body).returns("<xml>deployment</xml>")
48
+ @deployment = NewRelic::Command::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
49
+ assert_nil @deployment.exit_status
50
+ assert_nil @deployment.errors
51
+ assert_equal '3838', @deployment.revision
52
+ @deployment.run
53
+
54
+ # This should pass because it's a bogus deployment
55
+ #assert_equal 1, @deployment.exit_status
56
+ #assert_match /Unable to upload/, @deployment.errors
57
+
58
+ @deployment = nil
59
+ end
60
+ private
61
+ def mock_the_connection
62
+ mock_connection = mock()
63
+ @mock_response = mock()
64
+ @mock_response.expects(:is_a?).with(Net::HTTPSuccess).returns(true)
65
+ mock_connection.expects(:request).returns(@mock_response)
66
+ NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
67
+ end
68
+
69
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+ require "test/unit"
3
+ require "mocha"
4
+ ##require 'new_relic/local_environment'
5
+ class EnvironmentTest < Test::Unit::TestCase # ActiveSupport::TestCase
6
+
7
+ def teardown
8
+ # To remove mock server instances from ObjectSpace
9
+ ObjectSpace.garbage_collect
10
+ super
11
+ end
12
+ class MockOptions
13
+ def fetch (*args)
14
+ 1000
15
+ end
16
+ end
17
+ MOCK_OPTIONS = MockOptions.new
18
+
19
+ def test_environment
20
+ e = NewRelic::LocalEnvironment.new
21
+ assert_equal nil, e.environment
22
+ assert_match /test/i, e.dispatcher_instance_id
23
+ end
24
+ def test_no_webrick
25
+ Object.const_set :OPTIONS, 'foo'
26
+ e = NewRelic::LocalEnvironment.new
27
+ assert_equal nil, e.environment
28
+ assert_match /test/i, e.dispatcher_instance_id
29
+ Object.class_eval { remove_const :OPTIONS }
30
+ end
31
+
32
+ def test_passenger
33
+ class << self
34
+ module ::Passenger
35
+ const_set "AbstractServer", 0
36
+ end
37
+ end
38
+ e = NewRelic::LocalEnvironment.new
39
+ assert_equal :passenger, e.environment
40
+ assert_nil e.dispatcher_instance_id, "dispatcher instance id should be nil: #{e.dispatcher_instance_id}"
41
+
42
+ NewRelic::Control.instance.instance_eval do
43
+ @settings['app_name'] = 'myapp'
44
+ end
45
+
46
+ e = NewRelic::LocalEnvironment.new
47
+ assert_equal :passenger, e.environment
48
+ assert_nil e.dispatcher_instance_id
49
+
50
+ ::Passenger.class_eval { remove_const :AbstractServer }
51
+ end
52
+ def test_snapshot
53
+ e = NewRelic::LocalEnvironment.new
54
+ s = e.snapshot
55
+ assert_equal 0, s.size
56
+ e.gather_environment_info
57
+ s = e.snapshot
58
+ assert_match /1\.(8\.[67]|9\.\d)/, s.assoc('Ruby version').last, s.inspect
59
+ assert_equal 'test', s.assoc('Framework').last, s.inspect
60
+ # Make sure the processor count is determined on linux systems
61
+ if File.exists? '/proc/cpuinfo'
62
+ assert s.assoc('Processors').last.to_i > 0
63
+ end
64
+ end
65
+
66
+
67
+ def test_default_port
68
+ e = NewRelic::LocalEnvironment.new
69
+ assert_equal 3000, e.send(:default_port)
70
+ ARGV.push '--port=3121'
71
+ assert_equal '3121', e.send(:default_port)
72
+ ARGV.pop
73
+ end
74
+
75
+ end
@@ -0,0 +1,226 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
3
+
4
+ class MetricParserTest < Test::Unit::TestCase
5
+
6
+ def test_memcache
7
+ m = NewRelic::MetricParser.for_metric_named "MemCache/read"
8
+ assert_equal "MemCache read", m.developer_name
9
+ end
10
+
11
+ def test_memcache__all
12
+ m = NewRelic::MetricParser.for_metric_named "MemCache/all"
13
+ assert_equal "MemCache All Operations", m.developer_name
14
+ assert_equal "All Operations", m.operation
15
+ end
16
+
17
+ def test_view__short
18
+ i = NewRelic::MetricParser.parse("View/.rhtml Processing")
19
+ assert_equal "ERB compilation", i.developer_name
20
+ end
21
+ def test_controller
22
+ ["Controller", "Controller/1/2/3","Controller//!!#!//"].each do | metric_name |
23
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
24
+ assert m.is_controller?
25
+ assert !m.is_view?
26
+ assert !m.is_database?
27
+ assert !m.is_web_service?
28
+ end
29
+
30
+ ["Controller+1/2/3","Lew//!!#!//"].each do | metric_name |
31
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
32
+
33
+ assert !m.is_controller?
34
+ end
35
+ end
36
+
37
+ def test_controller_cpu
38
+ ["Controller/1/2/3","Controller//!!#!//"].each do | metric_name |
39
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
40
+
41
+ assert m.is_controller?
42
+ assert !m.is_view?
43
+ assert !m.is_database?
44
+ assert !m.is_web_service?
45
+ end
46
+
47
+ ["ControllerCPU/1/2/3","ControllerCPU//!!#!//"].each do | metric_name |
48
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
49
+
50
+ assert m.is_controller_cpu?
51
+ assert !m.is_view?
52
+ assert !m.is_controller?
53
+ assert !m.is_database?
54
+ assert !m.is_web_service?
55
+
56
+ assert_not_nil m.base_metric_name
57
+ assert_equal 0, m.base_metric_name.index('Controller/')
58
+ end
59
+
60
+ end
61
+
62
+ def test_web_service
63
+ ["WebService/x/Controller/", "WebService","WebService/1/2/3","WebService//!!#!//"].each do |metric_name|
64
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
65
+
66
+ assert !m.is_controller?
67
+ assert !m.is_view?
68
+ assert !m.is_database?
69
+ assert m.is_web_service?
70
+ end
71
+
72
+ ["Web/Service","WEBService+1/2/3","Lew//!!#!//"].each do | metric_name |
73
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
74
+
75
+ assert !m.is_web_service?, metric_name
76
+ end
77
+ end
78
+
79
+ def test_database
80
+ ["ActiveRecord","ActiveRecord/1/2/3","ActiveRecord//!!#!//"].each do | metric_name |
81
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
82
+
83
+ assert !m.is_view?
84
+ assert !m.is_controller?
85
+ assert m.is_active_record?, "#{metric_name}: #{m.category}"
86
+ assert !m.is_web_service?
87
+ end
88
+
89
+ ["ActiveRecordxx","ActiveRecord+1/2/3","ActiveRecord#!//"].each do | metric_name |
90
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
91
+
92
+ assert !m.is_database?
93
+ end
94
+ end
95
+ def test_view
96
+ %w[View/posts/post/Rendering View/admin/users/view/Partial View/ERB/Compile].each do | name |
97
+ m = NewRelic::MetricParser.for_metric_named(name)
98
+ assert !m.is_database?
99
+ assert !m.is_controller?
100
+ assert !m.is_web_service?
101
+ assert !m.is_error?
102
+ assert m.is_view?
103
+ end
104
+ end
105
+ def test_view__render
106
+ m = NewRelic::MetricParser.parse "View/blogs/show.html.erb/Rendering"
107
+
108
+ short_name = "show.html.erb Template"
109
+ long_name = "blogs/show.html.erb Template"
110
+ assert_equal short_name, m.pie_chart_label
111
+ assert_equal long_name, m.developer_name
112
+ assert_equal short_name, m.pie_chart_label
113
+ assert_equal "blogs/show.html.erb Template", m.controller_name
114
+ assert_equal "show", m.action_name
115
+ assert_equal "/blogs/show.html.erb", m.url
116
+ end
117
+ def test_view__partial
118
+ m = NewRelic::MetricParser.for_metric_named "View/admin/users/view.html.erb/Partial"
119
+ m.pie_chart_label
120
+ assert_equal "view.html.erb Partial", m.pie_chart_label
121
+ assert_equal "admin/users/view.html.erb Partial", m.developer_name
122
+ assert_equal "admin/users/view.html.erb Partial", m.controller_name
123
+ assert_equal "view", m.action_name
124
+ assert_equal "/admin/users/view.html.erb", m.url
125
+ end
126
+ def test_view__rhtml
127
+ m = NewRelic::MetricParser.for_metric_named "View/admin/users/view.rhtml/Rendering"
128
+ m.pie_chart_label
129
+ assert_equal "view.rhtml Template", m.pie_chart_label
130
+ assert_equal "admin/users/view.rhtml Template", m.developer_name
131
+ assert_equal "admin/users/view.rhtml Template", m.controller_name
132
+ assert_equal "view", m.action_name
133
+ assert_equal "/admin/users/view.rhtml", m.url
134
+ end
135
+ def test_error
136
+ ["Errors","Errors/Type/MyType","Errors/Controller/MyController/"].each do | metric_name |
137
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
138
+
139
+ assert !m.is_database?
140
+ assert !m.is_controller?
141
+ assert !m.is_web_service?
142
+ assert !m.is_view?
143
+ assert m.is_error?
144
+ end
145
+
146
+ m = NewRelic::MetricParser.for_metric_named("Errors/Type/MyType")
147
+ assert_equal m.short_name, 'MyType'
148
+ end
149
+ def test_external
150
+ m = NewRelic::MetricParser.for_metric_named("External/all")
151
+ assert m.all?
152
+ assert !m.hosts_all?
153
+ assert_equal "All External", m.developer_name
154
+ assert_equal "calls to external systems", m.tooltip_name
155
+ assert_equal "External Services", m.legend_name
156
+ assert_nil m.operation
157
+ assert_nil m.library
158
+
159
+ m = NewRelic::MetricParser.for_metric_named("External/venus/all")
160
+ assert !m.all?
161
+ assert m.hosts_all?
162
+ assert_equal "venus", m.developer_name
163
+ assert_equal "calls to venus", m.tooltip_name
164
+ assert_equal "All venus calls", m.legend_name
165
+ assert_nil m.operation
166
+ assert_equal 'all', m.library
167
+
168
+ m = NewRelic::MetricParser.for_metric_named("External/venus/Net::Http/get")
169
+ assert !m.all?
170
+ assert !m.hosts_all?
171
+ assert_equal "Net::Http[venus]: get", m.developer_name
172
+ assert_equal "calls to Net::Http[venus]: get", m.tooltip_name
173
+ assert_equal "Net::Http[venus]: get", m.legend_name
174
+ assert_equal 'get', m.operation
175
+ assert_equal 'Net::Http', m.library
176
+
177
+
178
+ end
179
+
180
+ context "with apdex" do
181
+
182
+ context "client" do
183
+ setup do
184
+ @client_name = NewRelic::MetricParser::Apdex.client_metric(NewRelic::Control.instance.apdex_t)
185
+ @apdex_client = NewRelic::MetricParser.for_metric_named(@client_name)
186
+ end
187
+ should "produce a client metric name" do
188
+ assert_equal "Apdex/Client/#{NewRelic::Control.instance.apdex_t}", @client_name
189
+ end
190
+ should "display the apdex value in " do
191
+ assert_equal "Apdex Client (1.1)", @apdex_client.developer_name
192
+ end
193
+ should "act like a client score" do
194
+ assert ! @apdex_client.is_summary?
195
+ assert @apdex_client.is_client?
196
+ end
197
+ should "display nicely" do
198
+ assert_equal "Apdex Client (#{NewRelic::Control.instance.apdex_t})", @apdex_client.developer_name
199
+ end
200
+
201
+ end
202
+
203
+ context "summary" do
204
+ setup do
205
+ @apdex_summary = NewRelic::MetricParser.for_metric_named('Apdex')
206
+ end
207
+
208
+ should "act like a summary" do
209
+ assert @apdex_summary.is_summary?
210
+ assert ! @apdex_summary.is_client?
211
+ end
212
+ end
213
+ context "controller score" do
214
+ setup do
215
+ @controller_apdex = NewRelic::MetricParser.for_metric_named('Apdex/sessions/guest_index')
216
+ end
217
+ should "act like a controller" do
218
+ assert ! @controller_apdex.is_summary?
219
+ assert ! @controller_apdex.is_client?
220
+ end
221
+ should "display nicely" do
222
+ assert_equal "Apdex sessions/guest_index", @controller_apdex.developer_name
223
+ end
224
+ end
225
+ end
226
+ end