techarch-newrelic_rpm 2.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +335 -0
- data/LICENSE +37 -0
- data/Manifest +159 -0
- data/README.md +138 -0
- data/Rakefile +22 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic_cmd +4 -0
- data/cert/cacert.pem +34 -0
- data/init.rb +38 -0
- data/install.rb +45 -0
- data/lib/new_relic/agent.rb +281 -0
- data/lib/new_relic/agent/agent.rb +636 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/collection_helper.rb +66 -0
- data/lib/new_relic/agent/error_collector.rb +121 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +88 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +437 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +167 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +24 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +13 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
- data/lib/new_relic/agent/instrumentation/net.rb +23 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +108 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +41 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +27 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +39 -0
- data/lib/new_relic/agent/method_tracer.rb +349 -0
- data/lib/new_relic/agent/patch_const_missing.rb +125 -0
- data/lib/new_relic/agent/sampler.rb +12 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +49 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +138 -0
- data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
- data/lib/new_relic/agent/shim_agent.rb +21 -0
- data/lib/new_relic/agent/stats_engine.rb +22 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +111 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +71 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +152 -0
- data/lib/new_relic/agent/transaction_sampler.rb +310 -0
- data/lib/new_relic/agent/worker_loop.rb +118 -0
- data/lib/new_relic/commands/deployments.rb +145 -0
- data/lib/new_relic/commands/new_relic_commands.rb +30 -0
- data/lib/new_relic/control.rb +473 -0
- data/lib/new_relic/control/external.rb +13 -0
- data/lib/new_relic/control/merb.rb +22 -0
- data/lib/new_relic/control/rails.rb +145 -0
- data/lib/new_relic/control/ruby.rb +36 -0
- data/lib/new_relic/control/sinatra.rb +14 -0
- data/lib/new_relic/histogram.rb +89 -0
- data/lib/new_relic/local_environment.rb +328 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -0
- data/lib/new_relic/metric_parser.rb +124 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +25 -0
- data/lib/new_relic/metric_parser/controller.rb +54 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/external.rb +50 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_spec.rb +52 -0
- data/lib/new_relic/metrics.rb +7 -0
- data/lib/new_relic/noticed_error.rb +23 -0
- data/lib/new_relic/rack/metric_app.rb +56 -0
- data/lib/new_relic/rack/newrelic.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +25 -0
- data/lib/new_relic/rack_app.rb +5 -0
- data/lib/new_relic/recipes.rb +82 -0
- data/lib/new_relic/stats.rb +361 -0
- data/lib/new_relic/transaction_analysis.rb +121 -0
- data/lib/new_relic/transaction_sample.rb +666 -0
- data/lib/new_relic/version.rb +54 -0
- data/lib/new_relic_api.rb +313 -0
- data/lib/newrelic_rpm.rb +40 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +13 -0
- data/newrelic.yml +227 -0
- data/recipes/newrelic.rb +6 -0
- data/techarch-newrelic_rpm.gemspec +32 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +46 -0
- data/test/config/test_control.rb +39 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +264 -0
- data/test/new_relic/agent/agent_controller_test.rb +107 -0
- data/test/new_relic/agent/agent_test.rb +119 -0
- data/test/new_relic/agent/agent_test_controller.rb +44 -0
- data/test/new_relic/agent/classloader_patch_test.rb +56 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/dispatcher_instrumentation_test.rb +76 -0
- data/test/new_relic/agent/error_collector_test.rb +172 -0
- data/test/new_relic/agent/method_tracer_test.rb +340 -0
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +63 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +81 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +126 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sample_test.rb +186 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
- data/test/new_relic/agent/worker_loop_test.rb +103 -0
- data/test/new_relic/control_test.rb +113 -0
- data/test/new_relic/deployments_api_test.rb +68 -0
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +172 -0
- data/test/new_relic/metric_spec_test.rb +177 -0
- data/test/new_relic/shim_agent_test.rb +9 -0
- data/test/new_relic/stats_test.rb +291 -0
- data/test/new_relic/version_number_test.rb +74 -0
- data/test/test_helper.rb +38 -0
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/newrelic_helper_test.rb +53 -0
- data/ui/controllers/newrelic_controller.rb +220 -0
- data/ui/helpers/google_pie_chart.rb +55 -0
- data/ui/helpers/newrelic_helper.rb +317 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +19 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +42 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/images/textmate.png +0 -0
- data/ui/views/newrelic/index.rhtml +57 -0
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +484 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +330 -0
@@ -0,0 +1,113 @@
|
|
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_monitor_mode
|
13
|
+
assert ! @c.monitor_mode?
|
14
|
+
@c['enabled'] = nil
|
15
|
+
assert !@c.monitor_mode?
|
16
|
+
@c['enabled'] = false
|
17
|
+
assert ! @c.monitor_mode?
|
18
|
+
@c['enabled'] = true
|
19
|
+
assert @c.monitor_mode?
|
20
|
+
@c['monitor_mode'] = nil
|
21
|
+
assert !@c.monitor_mode?
|
22
|
+
@c['monitor_mode'] = false
|
23
|
+
assert !@c.monitor_mode?
|
24
|
+
@c['monitor_mode'] = true
|
25
|
+
assert @c.monitor_mode?
|
26
|
+
ensure
|
27
|
+
@c['enabled'] = false
|
28
|
+
@c['monitor_mode'] = false
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_test_config
|
32
|
+
assert_equal :rails, c.app
|
33
|
+
assert_equal :test, c.framework
|
34
|
+
assert_match /test/i, c.dispatcher_instance_id
|
35
|
+
assert_equal nil, c.dispatcher
|
36
|
+
|
37
|
+
assert_equal false, c['enabled']
|
38
|
+
c.local_env
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_root
|
42
|
+
assert File.directory?(NewRelic::Control.newrelic_root), NewRelic::Control.newrelic_root
|
43
|
+
assert File.directory?(File.join(NewRelic::Control.newrelic_root, "lib")), NewRelic::Control.newrelic_root + "/lib"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_info
|
47
|
+
props = NewRelic::Control.instance.local_env.snapshot
|
48
|
+
list = props.assoc('Plugin List').last.map(&:to_s).sort
|
49
|
+
assert_not_nil list # can't really guess what might be in here.
|
50
|
+
assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_resolve_ip
|
54
|
+
assert_equal nil, c.send(:convert_to_ip_address, 'localhost')
|
55
|
+
assert_equal nil, c.send(:convert_to_ip_address, 'q1239988737.us')
|
56
|
+
# This might fail if you don't have a valid, accessible, DNS server
|
57
|
+
assert_equal '65.74.177.194', c.send(:convert_to_ip_address, 'rpm.newrelic.com')
|
58
|
+
end
|
59
|
+
def test_config_yaml_erb
|
60
|
+
assert_equal 'heyheyhey', c['erb_value']
|
61
|
+
assert_equal '', c['message']
|
62
|
+
assert_equal '', c['license_key']
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_config_booleans
|
66
|
+
assert_equal c['tval'], true
|
67
|
+
assert_equal c['fval'], false
|
68
|
+
assert_nil c['not_in_yaml_val']
|
69
|
+
assert_equal c['yval'], true
|
70
|
+
assert_equal c['sval'], 'sure'
|
71
|
+
end
|
72
|
+
def test_config_apdex
|
73
|
+
assert_equal 1.1, c.apdex_t
|
74
|
+
end
|
75
|
+
def test_transaction_threshold
|
76
|
+
assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
77
|
+
assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
78
|
+
end
|
79
|
+
def test_log_file_name
|
80
|
+
assert_match /newrelic_agent.log$/, c.instance_variable_get('@log_file')
|
81
|
+
end
|
82
|
+
def test_environment_info
|
83
|
+
NewRelic::Control.instance.send :append_environment_info
|
84
|
+
snapshot = NewRelic::Control.instance.local_env.snapshot
|
85
|
+
assert snapshot.assoc('Plugin List').last.map(&:to_s).include?('newrelic_rpm'), snapshot.inspect
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_transaction_threshold__apdex
|
89
|
+
forced_start
|
90
|
+
assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
91
|
+
assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_transaction_threshold__default
|
95
|
+
|
96
|
+
forced_start :transaction_tracer => {}
|
97
|
+
assert_nil c['transaction_tracer']['transaction_threshold']
|
98
|
+
assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_transaction_threshold__override
|
102
|
+
forced_start :transaction_tracer => { 'transaction_threshold' => 1}
|
103
|
+
assert_equal 1, c['transaction_tracer']['transaction_threshold']
|
104
|
+
assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
105
|
+
end
|
106
|
+
private
|
107
|
+
def forced_start overrides = {}
|
108
|
+
NewRelic::Agent.manual_start overrides
|
109
|
+
# This is to force the agent to start again.
|
110
|
+
NewRelic::Agent.instance.stubs(:started?).returns(nil)
|
111
|
+
NewRelic::Agent.instance.start
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'../../lib/new_relic/commands/deployments'))
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
class NewRelic::DeploymentsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
NewRelic::Commands::Deployments.class_eval do
|
9
|
+
attr_accessor :messages, :exit_status, :errors, :revision
|
10
|
+
def err(message); @errors = @errors ? @errors + message : message; end
|
11
|
+
def info(message); @messages = @messages ? @messages + message : message; end
|
12
|
+
def just_exit(status=0); @exit_status ||= status; end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def teardown
|
16
|
+
return unless @deployment
|
17
|
+
puts @deployment.errors
|
18
|
+
puts @deployment.messages
|
19
|
+
puts @deployment.exit_status
|
20
|
+
end
|
21
|
+
def test_help
|
22
|
+
begin
|
23
|
+
NewRelic::Commands::Deployments.new "-h"
|
24
|
+
fail "should have thrown"
|
25
|
+
rescue NewRelic::Commands::CommandFailure => c
|
26
|
+
assert_match /^Usage/, c.message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
def test_bad_command
|
30
|
+
assert_raise OptionParser::InvalidOption do
|
31
|
+
NewRelic::Commands::Deployments.new ["-foo", "bar"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def test_interactive
|
35
|
+
mock_the_connection
|
36
|
+
@deployment = NewRelic::Commands::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
|
37
|
+
assert_nil @deployment.exit_status
|
38
|
+
assert_nil @deployment.errors
|
39
|
+
assert_equal '3838', @deployment.revision
|
40
|
+
@deployment.run
|
41
|
+
@deployment = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_command_line_run
|
45
|
+
mock_the_connection
|
46
|
+
# @mock_response.expects(:body).returns("<xml>deployment</xml>")
|
47
|
+
@deployment = NewRelic::Commands::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
|
48
|
+
assert_nil @deployment.exit_status
|
49
|
+
assert_nil @deployment.errors
|
50
|
+
assert_equal '3838', @deployment.revision
|
51
|
+
@deployment.run
|
52
|
+
|
53
|
+
# This should pass because it's a bogus deployment
|
54
|
+
#assert_equal 1, @deployment.exit_status
|
55
|
+
#assert_match /Unable to upload/, @deployment.errors
|
56
|
+
|
57
|
+
@deployment = nil
|
58
|
+
end
|
59
|
+
private
|
60
|
+
def mock_the_connection
|
61
|
+
mock_connection = mock()
|
62
|
+
@mock_response = mock()
|
63
|
+
@mock_response.expects(:is_a?).with(Net::HTTPSuccess).returns(true)
|
64
|
+
mock_connection.expects(:request).returns(@mock_response)
|
65
|
+
NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
|
66
|
+
end
|
67
|
+
|
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,172 @@
|
|
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
|
+
def test_external
|
143
|
+
m = NewRelic::MetricParser.for_metric_named("External/all")
|
144
|
+
assert m.all?
|
145
|
+
assert !m.hosts_all?
|
146
|
+
assert_equal "All External", m.developer_name
|
147
|
+
assert_equal "calls to external systems", m.tooltip_name
|
148
|
+
assert_equal "External Services", m.legend_name
|
149
|
+
assert_nil m.operation
|
150
|
+
assert_nil m.library
|
151
|
+
|
152
|
+
m = NewRelic::MetricParser.for_metric_named("External/venus/all")
|
153
|
+
assert !m.all?
|
154
|
+
assert m.hosts_all?
|
155
|
+
assert_equal "venus", m.developer_name
|
156
|
+
assert_equal "calls to venus", m.tooltip_name
|
157
|
+
assert_equal "All venus calls", m.legend_name
|
158
|
+
assert_nil m.operation
|
159
|
+
assert_equal 'all', m.library
|
160
|
+
|
161
|
+
m = NewRelic::MetricParser.for_metric_named("External/venus/Net::Http/get")
|
162
|
+
assert !m.all?
|
163
|
+
assert !m.hosts_all?
|
164
|
+
assert_equal "Net::Http[venus]: get", m.developer_name
|
165
|
+
assert_equal "calls to Net::Http[venus]: get", m.tooltip_name
|
166
|
+
assert_equal "Net::Http[venus]: get", m.legend_name
|
167
|
+
assert_equal 'get', m.operation
|
168
|
+
assert_equal 'Net::Http', m.library
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
##require "new_relic/stats"
|
3
|
+
class NewRelic::MetricSpecTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_simple
|
6
|
+
stats = NewRelic::MethodTraceStats.new
|
7
|
+
validate stats, 0, 0, 0, 0
|
8
|
+
|
9
|
+
assert_equal stats.call_count,0
|
10
|
+
stats.trace_call 10
|
11
|
+
stats.trace_call 20
|
12
|
+
stats.trace_call 30
|
13
|
+
|
14
|
+
validate stats, 3, (10+20+30), 10, 30
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_equal
|
18
|
+
spec1 = NewRelic::MetricSpec.new('Controller')
|
19
|
+
spec2 = NewRelic::MetricSpec.new('Controller', nil)
|
20
|
+
|
21
|
+
assert spec1.eql?(NewRelic::MetricSpec.new('Controller'))
|
22
|
+
assert spec2.eql?(NewRelic::MetricSpec.new('Controller', nil))
|
23
|
+
assert spec1.eql?(spec2)
|
24
|
+
assert !spec2.eql?(NewRelic::MetricSpec.new('Controller', '/dude'))
|
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
|
53
|
+
|
54
|
+
def test_merge
|
55
|
+
s1 = NewRelic::MethodTraceStats.new
|
56
|
+
s2 = NewRelic::MethodTraceStats.new
|
57
|
+
|
58
|
+
s1.trace_call 10
|
59
|
+
s2.trace_call 20
|
60
|
+
s2.freeze
|
61
|
+
|
62
|
+
validate s2, 1, 20, 20, 20
|
63
|
+
s3 = s1.merge s2
|
64
|
+
validate s3, 2, (10+20), 10, 20
|
65
|
+
validate s1, 1, 10, 10, 10
|
66
|
+
validate s2, 1, 20, 20, 20
|
67
|
+
|
68
|
+
s1.merge! s2
|
69
|
+
validate s1, 2, (10+20), 10, 20
|
70
|
+
validate s2, 1, 20, 20, 20
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_merge_with_exclusive
|
74
|
+
s1 = NewRelic::MethodTraceStats.new
|
75
|
+
|
76
|
+
s2 = NewRelic::MethodTraceStats.new
|
77
|
+
|
78
|
+
s1.trace_call 10, 5
|
79
|
+
s2.trace_call 20, 10
|
80
|
+
s2.freeze
|
81
|
+
|
82
|
+
validate s2, 1, 20, 20, 20, 10
|
83
|
+
s3 = s1.merge s2
|
84
|
+
validate s3, 2, (10+20), 10, 20, (10+5)
|
85
|
+
validate s1, 1, 10, 10, 10, 5
|
86
|
+
validate s2, 1, 20, 20, 20, 10
|
87
|
+
|
88
|
+
s1.merge! s2
|
89
|
+
validate s1, 2, (10+20), 10, 20, (5+10)
|
90
|
+
validate s2, 1, 20, 20, 20, 10
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_merge_array
|
94
|
+
s1 = NewRelic::MethodTraceStats.new
|
95
|
+
merges = []
|
96
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
97
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
98
|
+
merges << (NewRelic::MethodTraceStats.new.trace_call 1)
|
99
|
+
|
100
|
+
s1.merge! merges
|
101
|
+
validate s1, 3, 3, 1, 1
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_freeze
|
105
|
+
s1 = NewRelic::MethodTraceStats.new
|
106
|
+
|
107
|
+
s1.trace_call 10
|
108
|
+
s1.freeze
|
109
|
+
|
110
|
+
begin
|
111
|
+
# the following should throw an exception because s1 is frozen
|
112
|
+
s1.trace_call 20
|
113
|
+
assert false
|
114
|
+
rescue StandardError
|
115
|
+
assert s1.frozen?
|
116
|
+
validate s1, 1, 10, 10, 10
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_std_dev
|
121
|
+
s = NewRelic::MethodTraceStats.new
|
122
|
+
|
123
|
+
s.trace_call 10
|
124
|
+
s.trace_call 10
|
125
|
+
s.trace_call 10
|
126
|
+
s.trace_call 10
|
127
|
+
s.trace_call 10
|
128
|
+
s.trace_call 10
|
129
|
+
assert s.standard_deviation == 0
|
130
|
+
|
131
|
+
s = NewRelic::MethodTraceStats.new
|
132
|
+
s.trace_call 4
|
133
|
+
s.trace_call 7
|
134
|
+
s.trace_call 13
|
135
|
+
s.trace_call 16
|
136
|
+
s.trace_call 8
|
137
|
+
s.trace_call 4
|
138
|
+
assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
|
139
|
+
|
140
|
+
s.trace_call 9
|
141
|
+
s.trace_call 3
|
142
|
+
s.trace_call 1000
|
143
|
+
s.trace_call 4
|
144
|
+
|
145
|
+
# calculated stdev (population, not sample) from a spreadsheet.
|
146
|
+
assert_in_delta(s.standard_deviation, 297.76, 0.01)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_std_dev_merge
|
150
|
+
s1 = NewRelic::MethodTraceStats.new
|
151
|
+
s1.trace_call 4
|
152
|
+
s1.trace_call 7
|
153
|
+
|
154
|
+
s2 = NewRelic::MethodTraceStats.new
|
155
|
+
s2.trace_call 13
|
156
|
+
s2.trace_call 16
|
157
|
+
|
158
|
+
s3 = s1.merge(s2)
|
159
|
+
|
160
|
+
assert(s1.sum_of_squares, 4*4 + 7*7)
|
161
|
+
assert_in_delta(s1.standard_deviation, 1.5, 0.01)
|
162
|
+
|
163
|
+
assert_in_delta(s2.standard_deviation, 1.5, 0.01)
|
164
|
+
assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
|
165
|
+
assert_in_delta(s3.standard_deviation, 4.743, 0.01)
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
def validate (stats, count, total, min, max, exclusive = nil)
|
170
|
+
assert_equal stats.call_count, count
|
171
|
+
assert_equal stats.total_call_time, total
|
172
|
+
assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
|
173
|
+
assert_equal stats.min_call_time, min
|
174
|
+
assert_equal stats.max_call_time, max
|
175
|
+
assert_equal stats.total_exclusive_time, exclusive if exclusive
|
176
|
+
end
|
177
|
+
end
|