newrelic_rpm 2.8.11 → 2.9.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (137) hide show
  1. data/CHANGELOG +267 -0
  2. data/LICENSE +1 -1
  3. data/Manifest +142 -0
  4. data/README.md +138 -0
  5. data/Rakefile +10 -28
  6. data/bin/mongrel_rpm +33 -0
  7. data/cert/cacert.pem +34 -0
  8. data/init.rb +38 -0
  9. data/lib/new_relic/agent/agent.rb +160 -347
  10. data/lib/new_relic/agent/collection_helper.rb +13 -24
  11. data/lib/new_relic/agent/error_collector.rb +29 -15
  12. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
  14. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
  15. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
  16. data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
  17. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
  18. data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
  19. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
  20. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
  21. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
  22. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
  23. data/lib/new_relic/agent/method_tracer.rb +159 -135
  24. data/lib/new_relic/agent/patch_const_missing.rb +46 -26
  25. data/lib/new_relic/agent/sampler.rb +12 -0
  26. data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
  27. data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
  28. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  29. data/lib/new_relic/agent/shim_agent.rb +11 -0
  30. data/lib/new_relic/agent/stats_engine.rb +85 -46
  31. data/lib/new_relic/agent/transaction_sampler.rb +63 -38
  32. data/lib/new_relic/agent/worker_loop.rb +8 -18
  33. data/lib/new_relic/agent.rb +200 -25
  34. data/lib/new_relic/commands/deployments.rb +9 -9
  35. data/lib/new_relic/control/merb.rb +22 -0
  36. data/lib/new_relic/control/rails.rb +141 -0
  37. data/lib/new_relic/{config → control}/ruby.rb +13 -2
  38. data/lib/new_relic/control.rb +424 -0
  39. data/lib/new_relic/local_environment.rb +201 -79
  40. data/lib/new_relic/metric_data.rb +7 -0
  41. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  42. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  43. data/lib/new_relic/metric_parser/active_record.rb +11 -0
  44. data/lib/new_relic/metric_parser/controller.rb +51 -0
  45. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  46. data/lib/new_relic/metric_parser/database.rb +23 -0
  47. data/lib/new_relic/metric_parser/errors.rb +6 -0
  48. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  49. data/lib/new_relic/metric_parser/view.rb +61 -0
  50. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  51. data/lib/new_relic/metric_parser.rb +107 -0
  52. data/lib/new_relic/metric_spec.rb +5 -0
  53. data/lib/new_relic/noticed_error.rb +5 -1
  54. data/lib/new_relic/rack/metric_app.rb +57 -0
  55. data/lib/new_relic/rack/newrelic.ru +25 -0
  56. data/lib/new_relic/rack/newrelic.yml +25 -0
  57. data/lib/new_relic/rack.rb +5 -0
  58. data/lib/new_relic/recipes.rb +10 -3
  59. data/lib/new_relic/stats.rb +130 -144
  60. data/lib/new_relic/transaction_analysis.rb +7 -8
  61. data/lib/new_relic/transaction_sample.rb +86 -10
  62. data/lib/new_relic/version.rb +41 -160
  63. data/lib/new_relic_api.rb +7 -6
  64. data/lib/newrelic_rpm.rb +30 -17
  65. data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
  66. data/newrelic.yml +115 -62
  67. data/newrelic_rpm.gemspec +36 -0
  68. data/test/active_record_fixtures.rb +55 -0
  69. data/test/config/newrelic.yml +21 -3
  70. data/test/config/{test_config.rb → test_control.rb} +14 -10
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
  72. data/test/new_relic/agent/agent_test.rb +104 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +18 -1
  74. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  75. data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
  76. data/test/new_relic/agent/controller_test.rb +107 -0
  77. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
  78. data/test/new_relic/agent/error_collector_test.rb +155 -0
  79. data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
  80. data/test/new_relic/agent/metric_data_test.rb +56 -0
  81. data/test/new_relic/agent/stats_engine_test.rb +266 -0
  82. data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
  83. data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
  84. data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
  85. data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
  86. data/test/new_relic/control_test.rb +97 -0
  87. data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
  88. data/test/new_relic/environment_test.rb +75 -0
  89. data/test/new_relic/metric_parser_test.rb +142 -0
  90. data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
  91. data/test/new_relic/samplers_test.rb +71 -0
  92. data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
  93. data/test/new_relic/stats_test.rb +291 -0
  94. data/test/new_relic/version_number_test.rb +46 -0
  95. data/test/test_helper.rb +7 -30
  96. data/test/ui/newrelic_controller_test.rb +14 -0
  97. data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
  98. data/ui/controllers/newrelic_controller.rb +17 -3
  99. data/ui/helpers/newrelic_helper.rb +44 -15
  100. data/ui/views/layouts/newrelic_default.rhtml +7 -8
  101. data/ui/views/newrelic/_sample.rhtml +5 -2
  102. data/ui/views/newrelic/_segment.rhtml +1 -1
  103. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  104. data/ui/views/newrelic/_segment_row.rhtml +4 -4
  105. data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
  106. data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
  107. data/ui/views/newrelic/explain_sql.rhtml +2 -5
  108. data/ui/views/newrelic/images/file_icon.png +0 -0
  109. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  110. data/ui/views/newrelic/index.rhtml +21 -13
  111. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  112. data/ui/views/newrelic/show_sample.rhtml +18 -3
  113. data/ui/views/newrelic/stylesheets/style.css +39 -0
  114. data/ui/views/newrelic/threads.rhtml +52 -0
  115. metadata +192 -70
  116. data/README +0 -136
  117. data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
  118. data/lib/new_relic/agent/samplers/cpu.rb +0 -29
  119. data/lib/new_relic/agent/samplers/memory.rb +0 -53
  120. data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
  121. data/lib/new_relic/agent/synchronize.rb +0 -40
  122. data/lib/new_relic/config/merb.rb +0 -35
  123. data/lib/new_relic/config/rails.rb +0 -114
  124. data/lib/new_relic/config.rb +0 -279
  125. data/lib/new_relic/shim_agent.rb +0 -96
  126. data/test/new_relic/agent/model_fixture.rb +0 -15
  127. data/test/new_relic/agent/tc_active_record.rb +0 -90
  128. data/test/new_relic/agent/tc_agent.rb +0 -148
  129. data/test/new_relic/agent/tc_controller.rb +0 -77
  130. data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
  131. data/test/new_relic/agent/tc_error_collector.rb +0 -127
  132. data/test/new_relic/agent/tc_stats_engine.rb +0 -218
  133. data/test/new_relic/agent/tc_synchronize.rb +0 -37
  134. data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
  135. data/test/new_relic/tc_config.rb +0 -36
  136. data/test/new_relic/tc_environment.rb +0 -94
  137. data/test/new_relic/tc_stats.rb +0 -141
@@ -5,7 +5,7 @@ NewRelic::Agent::WorkerLoop.class_eval do
5
5
  public :run_next_task
6
6
  end
7
7
 
8
- class NewRelic::Agent::WorkerLoopTests < Test::Unit::TestCase
8
+ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
9
9
  def setup
10
10
  @log = ""
11
11
  @logger = Logger.new(StringIO.new(@log))
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
+
3
+ class NewRelic::ControlTest < Test::Unit::TestCase
4
+
5
+ attr_reader :c
6
+
7
+ def setup
8
+ NewRelic::Agent.manual_start
9
+ @c = NewRelic::Control.instance
10
+ end
11
+
12
+ def test_test_config
13
+ assert_equal :rails, c.app
14
+ assert_equal :test, c.framework
15
+ assert_match /test/i, c.dispatcher_instance_id
16
+ assert_equal nil, c.dispatcher
17
+
18
+ assert_equal false, c['enabled']
19
+ c.local_env
20
+ end
21
+
22
+ def test_root
23
+ assert File.directory?(NewRelic::Control.newrelic_root), NewRelic::Control.newrelic_root
24
+ assert File.directory?(File.join(NewRelic::Control.newrelic_root, "lib")), NewRelic::Control.newrelic_root + "/lib"
25
+ end
26
+
27
+ def test_info
28
+ props = NewRelic::Control.instance.local_env.snapshot
29
+ list = props.assoc('Plugin List').last.sort
30
+ assert_not_nil list # can't really guess what might be in here.
31
+ assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last
32
+ end
33
+
34
+ def test_resolve_ip
35
+ assert_equal nil, c.send(:convert_to_ip_address, 'localhost')
36
+ assert_equal nil, c.send(:convert_to_ip_address, 'q1239988737.us')
37
+ # This might fail if you don't have a valid, accessible, DNS server
38
+ assert_equal '65.74.177.194', c.send(:convert_to_ip_address, 'rpm.newrelic.com')
39
+ end
40
+ def test_config_yaml_erb
41
+ assert_equal 'heyheyhey', c['erb_value']
42
+ assert_equal '', c['message']
43
+ assert_equal '', c['license_key']
44
+ end
45
+
46
+ def test_config_booleans
47
+ assert_equal c['tval'], true
48
+ assert_equal c['fval'], false
49
+ assert_nil c['not_in_yaml_val']
50
+ assert_equal c['yval'], true
51
+ assert_equal c['sval'], 'sure'
52
+ end
53
+ def test_config_apdex
54
+ assert_equal 1.1, c['apdex_t']
55
+ end
56
+ def test_transaction_threshold
57
+ assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
58
+ assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
59
+ end
60
+ def test_log_file_name
61
+ assert_match /newrelic_agent.log$/, c.instance_variable_get('@log_file')
62
+ end
63
+ def test_environment_info
64
+ NewRelic::Control.instance.send :append_environment_info
65
+ snapshot = NewRelic::Control.instance.local_env.snapshot
66
+ assert snapshot.assoc('Plugin List').last.include?('newrelic_rpm'), snapshot.inspect
67
+ end
68
+ def test_config_apdex
69
+ assert_equal 1.1, c['apdex_t']
70
+ end
71
+
72
+ def test_transaction_threshold__apdex
73
+ forced_start
74
+ assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
75
+ assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
76
+ end
77
+
78
+ def test_transaction_threshold__default
79
+
80
+ forced_start :transaction_tracer => {}
81
+ assert_nil c['transaction_tracer']['transaction_threshold']
82
+ assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
83
+ end
84
+
85
+ def test_transaction_threshold__override
86
+ forced_start :transaction_tracer => { 'transaction_threshold' => 1}
87
+ assert_equal 1, c['transaction_tracer']['transaction_threshold']
88
+ assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
89
+ end
90
+ private
91
+ def forced_start overrides = {}
92
+ NewRelic::Agent.manual_start overrides
93
+ # This is to force the agent to start again.
94
+ NewRelic::Agent.instance.stubs(:started?).returns(nil)
95
+ NewRelic::Agent.instance.start
96
+ end
97
+ end
@@ -1,9 +1,8 @@
1
- #require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
1
  require File.expand_path(File.join(File.dirname(__FILE__),'../../lib/new_relic/commands/deployments'))
3
2
  require 'rubygems'
4
3
  require 'mocha'
5
4
 
6
- class NewRelic::DeploymentsTests < Test::Unit::TestCase
5
+ class NewRelic::DeploymentsTest < Test::Unit::TestCase
7
6
 
8
7
  def setup
9
8
  NewRelic::Commands::Deployments.class_eval do
@@ -21,12 +20,17 @@ class NewRelic::DeploymentsTests < Test::Unit::TestCase
21
20
  end
22
21
  def test_help
23
22
  begin
24
- NewRelic::Commands::Deployments.new "-?"
23
+ NewRelic::Commands::Deployments.new "-h"
25
24
  fail "should have thrown"
26
25
  rescue NewRelic::Commands::CommandFailure => c
27
26
  assert_match /^Usage/, c.message
28
27
  end
29
28
  end
29
+ def test_bad_command
30
+ assert_raise OptionParser::InvalidOption do
31
+ NewRelic::Commands::Deployments.new ["-foo", "bar"]
32
+ end
33
+ end
30
34
  def test_interactive
31
35
  mock_the_connection
32
36
  @deployment = NewRelic::Commands::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
@@ -58,7 +62,7 @@ class NewRelic::DeploymentsTests < Test::Unit::TestCase
58
62
  @mock_response = mock()
59
63
  @mock_response.expects(:is_a?).with(Net::HTTPSuccess).returns(true)
60
64
  mock_connection.expects(:request).returns(@mock_response)
61
- NewRelic::Config.instance.stubs(:http_connection).returns(mock_connection)
65
+ NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
62
66
  end
63
67
 
64
68
  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 < 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,142 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+
3
+ class MetricParserTest < Test::Unit::TestCase
4
+
5
+ def test_memcache
6
+ m = NewRelic::MetricParser.for_metric_named "MemCache/read"
7
+ assert_equal "MemCache read", m.developer_name
8
+ end
9
+
10
+ def test_view__short
11
+ i = NewRelic::MetricParser.parse("View/.rhtml Processing")
12
+ assert_equal "ERB compilation", i.developer_name
13
+ end
14
+ def test_controller
15
+ ["Controller", "Controller/1/2/3","Controller//!!#!//"].each do | metric_name |
16
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
17
+ assert m.is_controller?
18
+ assert !m.is_view?
19
+ assert !m.is_database?
20
+ assert !m.is_web_service?
21
+ end
22
+
23
+ ["Controller+1/2/3","Lew//!!#!//"].each do | metric_name |
24
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
25
+
26
+ assert !m.is_controller?
27
+ end
28
+ end
29
+
30
+ def test_controller_cpu
31
+ ["Controller/1/2/3","Controller//!!#!//"].each do | metric_name |
32
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
33
+
34
+ assert m.is_controller?
35
+ assert !m.is_view?
36
+ assert !m.is_database?
37
+ assert !m.is_web_service?
38
+ end
39
+
40
+ ["ControllerCPU/1/2/3","ControllerCPU//!!#!//"].each do | metric_name |
41
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
42
+
43
+ assert m.is_controller_cpu?
44
+ assert !m.is_view?
45
+ assert !m.is_controller?
46
+ assert !m.is_database?
47
+ assert !m.is_web_service?
48
+
49
+ assert_not_nil m.base_metric_name
50
+ assert m.base_metric_name.starts_with?('Controller/')
51
+ end
52
+
53
+ end
54
+
55
+ def test_web_service
56
+ ["WebService/x/Controller/", "WebService","WebService/1/2/3","WebService//!!#!//"].each do |metric_name|
57
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
58
+
59
+ assert !m.is_controller?
60
+ assert !m.is_view?
61
+ assert !m.is_database?
62
+ assert m.is_web_service?
63
+ end
64
+
65
+ ["Web/Service","WEBService+1/2/3","Lew//!!#!//"].each do | metric_name |
66
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
67
+
68
+ assert !m.is_web_service?, metric_name
69
+ end
70
+ end
71
+
72
+ def test_database
73
+ ["ActiveRecord","ActiveRecord/1/2/3","ActiveRecord//!!#!//"].each do | metric_name |
74
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
75
+
76
+ assert !m.is_view?
77
+ assert !m.is_controller?
78
+ assert m.is_active_record?, "#{metric_name}: #{m.category}"
79
+ assert !m.is_web_service?
80
+ end
81
+
82
+ ["ActiveRecordxx","ActiveRecord+1/2/3","ActiveRecord#!//"].each do | metric_name |
83
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
84
+
85
+ assert !m.is_database?
86
+ end
87
+ end
88
+ def test_view
89
+ %w[View/posts/post/Rendering View/admin/users/view/Partial View/ERB/Compile].each do | name |
90
+ m = NewRelic::MetricParser.for_metric_named(name)
91
+ assert !m.is_database?
92
+ assert !m.is_controller?
93
+ assert !m.is_web_service?
94
+ assert !m.is_error?
95
+ assert m.is_view?
96
+ end
97
+ end
98
+ def test_view__render
99
+ m = NewRelic::MetricParser.parse "View/blogs/show.html.erb/Rendering"
100
+
101
+ short_name = "show.html.erb Template"
102
+ long_name = "blogs/show.html.erb Template"
103
+ assert_equal short_name, m.pie_chart_label
104
+ assert_equal long_name, m.developer_name
105
+ assert_equal short_name, m.pie_chart_label
106
+ assert_equal "blogs/show.html.erb Template", m.controller_name
107
+ assert_equal "show", m.action_name
108
+ assert_equal "/blogs/show.html.erb", m.url
109
+ end
110
+ def test_view__partial
111
+ m = NewRelic::MetricParser.for_metric_named "View/admin/users/view.html.erb/Partial"
112
+ m.pie_chart_label
113
+ assert_equal "view.html.erb Partial", m.pie_chart_label
114
+ assert_equal "admin/users/view.html.erb Partial", m.developer_name
115
+ assert_equal "admin/users/view.html.erb Partial", m.controller_name
116
+ assert_equal "view", m.action_name
117
+ assert_equal "/admin/users/view.html.erb", m.url
118
+ end
119
+ def test_view__rhtml
120
+ m = NewRelic::MetricParser.for_metric_named "View/admin/users/view.rhtml/Rendering"
121
+ m.pie_chart_label
122
+ assert_equal "view.rhtml Template", m.pie_chart_label
123
+ assert_equal "admin/users/view.rhtml Template", m.developer_name
124
+ assert_equal "admin/users/view.rhtml Template", m.controller_name
125
+ assert_equal "view", m.action_name
126
+ assert_equal "/admin/users/view.rhtml", m.url
127
+ end
128
+ def test_error
129
+ ["Errors","Errors/Type/MyType","Errors/Controller/MyController/"].each do | metric_name |
130
+ m = NewRelic::MetricParser.for_metric_named(metric_name)
131
+
132
+ assert !m.is_database?
133
+ assert !m.is_controller?
134
+ assert !m.is_web_service?
135
+ assert !m.is_view?
136
+ assert m.is_error?
137
+ end
138
+
139
+ m = NewRelic::MetricParser.for_metric_named("Errors/Type/MyType")
140
+ assert_equal m.short_name, 'MyType'
141
+ end
142
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
2
  ##require "new_relic/stats"
3
- class NewRelic::StatsTests < Test::Unit::TestCase
3
+ class NewRelic::StatsTest < Test::Unit::TestCase
4
4
 
5
5
  def test_simple
6
6
  stats = NewRelic::MethodTraceStats.new
@@ -23,6 +23,33 @@ class NewRelic::StatsTests < Test::Unit::TestCase
23
23
  assert !spec1.eql?(spec2)
24
24
  assert !spec2.eql?(NewRelic::MetricSpec.new('Controller', '/dude'))
25
25
  end
26
+
27
+ define_method(:'test_<=>') do
28
+ s1 = NewRelic::MetricSpec.new('ActiveRecord')
29
+ s2 = NewRelic::MetricSpec.new('Controller')
30
+ assert_equal [s1, s2].sort, [s1,s2]
31
+ assert_equal [s2, s1].sort, [s1,s2]
32
+
33
+ s1 = NewRelic::MetricSpec.new('Controller', nil)
34
+ s2 = NewRelic::MetricSpec.new('Controller', 'hap')
35
+ assert_equal [s2, s1].sort, [s1, s2]
36
+ assert_equal [s1, s2].sort, [s1, s2]
37
+
38
+ s1 = NewRelic::MetricSpec.new('Controller', 'hap')
39
+ s2 = NewRelic::MetricSpec.new('Controller', nil)
40
+ assert_equal [s2, s1].sort, [s2, s1]
41
+ assert_equal [s1, s2].sort, [s2, s1]
42
+
43
+ s1 = NewRelic::MetricSpec.new('Controller')
44
+ s2 = NewRelic::MetricSpec.new('Controller')
45
+ assert_equal [s2, s1].sort, [s2, s1] # unchanged due to no sort criteria
46
+ assert_equal [s1, s2].sort, [s1, s2] # unchanged due to no sort criteria
47
+
48
+ s1 = NewRelic::MetricSpec.new('Controller', nil)
49
+ s2 = NewRelic::MetricSpec.new('Controller', nil)
50
+ assert_equal [s2, s1].sort, [s2, s1] # unchanged due to no sort criteria
51
+ assert_equal [s1, s2].sort, [s1, s2] # unchanged due to no sort criteria
52
+ end
26
53
 
27
54
  def test_merge
28
55
  s1 = NewRelic::MethodTraceStats.new
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+ require 'new_relic/agent/samplers/cpu_sampler'
3
+
4
+ class NewRelic::SamplersTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @stats_engine = NewRelic::Agent::StatsEngine.new
8
+ end
9
+ def test_cpu
10
+ s = NewRelic::Agent::Samplers::CpuSampler.new
11
+ # need to sleep because if you go to fast it will skip the points
12
+ s.stats_engine = @stats_engine
13
+ sleep 2
14
+ s.poll
15
+ sleep 2
16
+ s.poll
17
+ assert_equal 2, s.systemtime_stats.call_count
18
+ assert_equal 2, s.usertime_stats.call_count
19
+ assert s.usertime_stats.total_call_time >= 0, "user cpu greater/equal to 0: #{s.usertime_stats.total_call_time}"
20
+ assert s.systemtime_stats.total_call_time >= 0, "system cpu greater/equal to 0: #{s.systemtime_stats.total_call_time}"
21
+ end
22
+ def test_memory__default
23
+ s = NewRelic::Agent::Samplers::MemorySampler.new
24
+ s.stats_engine = @stats_engine
25
+ s.poll
26
+ s.poll
27
+ s.poll
28
+ assert_equal 3, s.stats.call_count
29
+ assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
30
+ end
31
+ def test_memory__linux
32
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'linux'
33
+ s = NewRelic::Agent::Samplers::MemorySampler.new
34
+ s.stats_engine = @stats_engine
35
+ s.poll
36
+ s.poll
37
+ s.poll
38
+ assert_equal 3, s.stats.call_count
39
+ assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
40
+ end
41
+ def test_memory__solaris
42
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'solaris'
43
+ assert_raise RuntimeError, /Unable to run command/ do
44
+ NewRelic::Agent::Samplers::MemorySampler.new
45
+ end
46
+ end
47
+ def test_memory__windows
48
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'win32'
49
+ assert_raise RuntimeError, /Unsupported platform/ do
50
+ NewRelic::Agent::Samplers::MemorySampler.new
51
+ end
52
+ end
53
+ def test_mongrel
54
+ NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.stubs('is_busy?'.to_sym).returns(false)
55
+ mongrel = mock()
56
+ NewRelic::Control.instance.local_env.stubs(:mongrel).returns(mongrel)
57
+ list = mock()
58
+ workers = mock()
59
+ workers.stubs(:list).returns(list)
60
+ list.stubs(:length).returns(3)
61
+ mongrel.expects(:workers).returns(workers).at_least_once
62
+ s = NewRelic::Agent::Samplers::MongrelSampler.new
63
+ s.stats_engine = @stats_engine
64
+ s.poll
65
+ s.poll
66
+ s.poll
67
+ assert_equal 3, s.queue_stats.call_count
68
+ assert_equal 3, s.queue_stats.average_call_time, "mongrel queue length"
69
+ end
70
+
71
+ end