honkster-newrelic_rpm 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +462 -0
- data/LICENSE +37 -0
- data/README.rdoc +172 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +34 -0
- data/install.rb +9 -0
- data/lib/new_relic/agent.rb +382 -0
- data/lib/new_relic/agent/agent.rb +741 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +131 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +409 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +58 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +319 -0
- data/lib/new_relic/agent/instrumentation/net.rb +17 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
- data/lib/new_relic/agent/method_tracer.rb +350 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
- data/lib/new_relic/agent/shim_agent.rb +25 -0
- data/lib/new_relic/agent/stats_engine.rb +24 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +83 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
- data/lib/new_relic/agent/transaction_sampler.rb +330 -0
- data/lib/new_relic/agent/worker_loop.rb +81 -0
- data/lib/new_relic/collection_helper.rb +71 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +81 -0
- data/lib/new_relic/control.rb +203 -0
- data/lib/new_relic/control/configuration.rb +149 -0
- data/lib/new_relic/control/frameworks/external.rb +13 -0
- data/lib/new_relic/control/frameworks/merb.rb +24 -0
- data/lib/new_relic/control/frameworks/rails.rb +126 -0
- data/lib/new_relic/control/frameworks/rails3.rb +60 -0
- data/lib/new_relic/control/frameworks/ruby.rb +36 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +18 -0
- data/lib/new_relic/control/instrumentation.rb +95 -0
- data/lib/new_relic/control/logging_methods.rb +74 -0
- data/lib/new_relic/control/profiling.rb +24 -0
- data/lib/new_relic/control/server_methods.rb +88 -0
- data/lib/new_relic/delayed_job_injection.rb +27 -0
- data/lib/new_relic/histogram.rb +91 -0
- data/lib/new_relic/local_environment.rb +333 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -0
- data/lib/new_relic/metric_parser.rb +136 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +28 -0
- data/lib/new_relic/metric_parser/apdex.rb +88 -0
- data/lib/new_relic/metric_parser/controller.rb +62 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/external.rb +50 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
- data/lib/new_relic/metric_parser/other_transaction.rb +36 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_spec.rb +67 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/developer_mode.rb +257 -0
- data/lib/new_relic/rack/metric_app.rb +64 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +26 -0
- data/lib/new_relic/rack/newrelic.yml +27 -0
- data/lib/new_relic/rack_app.rb +6 -0
- data/lib/new_relic/recipes.rb +82 -0
- data/lib/new_relic/stats.rb +368 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +119 -0
- data/lib/new_relic/transaction_sample.rb +586 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/new_relic_api.rb +276 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +15 -0
- data/newrelic.yml +246 -0
- data/newrelic_rpm.gemspec +254 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +36 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +286 -0
- data/test/new_relic/agent/agent_controller_test.rb +294 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/error_collector_test.rb +163 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
- data/test/new_relic/agent/method_tracer_test.rb +340 -0
- data/test/new_relic/agent/metric_data_test.rb +53 -0
- data/test/new_relic/agent/metric_frame_test.rb +51 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
- data/test/new_relic/agent/rpm_agent_test.rb +142 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +188 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sample_test.rb +192 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/control_test.rb +127 -0
- data/test/new_relic/deployments_api_test.rb +69 -0
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +226 -0
- data/test/new_relic/metric_spec_test.rb +177 -0
- data/test/new_relic/rack/episodes_test.rb +318 -0
- data/test/new_relic/shim_agent_test.rb +9 -0
- data/test/new_relic/stats_test.rb +312 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_contexts.rb +28 -0
- data/test/test_helper.rb +72 -0
- data/ui/helpers/developer_mode_helper.rb +359 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +29 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +484 -0
- data/ui/views/newrelic/index.rhtml +59 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +79 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +307 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# test to make sure the MetricData class can serialize to json
|
6
|
+
def test_json
|
7
|
+
spec = NewRelic::MetricSpec.new("controller", "metric#find")
|
8
|
+
|
9
|
+
import = ::ActiveSupport::JSON.decode(spec.to_json)
|
10
|
+
|
11
|
+
compare_spec(spec, import)
|
12
|
+
|
13
|
+
stats = NewRelic::MethodTraceStats.new
|
14
|
+
|
15
|
+
import = ::ActiveSupport::JSON.decode(stats.to_json)
|
16
|
+
|
17
|
+
compare_stat(stats, import)
|
18
|
+
|
19
|
+
metric_data = NewRelic::MetricData.new(spec, stats, 10)
|
20
|
+
|
21
|
+
import = ::ActiveSupport::JSON.decode(metric_data.to_json)
|
22
|
+
|
23
|
+
compare_metric_data(metric_data, import)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def compare_spec(spec, import)
|
30
|
+
assert_equal 2, import.length
|
31
|
+
assert_equal spec.name, import['name']
|
32
|
+
assert_equal spec.scope, import['scope']
|
33
|
+
end
|
34
|
+
|
35
|
+
def compare_stat(stats, import)
|
36
|
+
assert_equal 6, import.length
|
37
|
+
assert_equal stats.total_call_time, import['total_call_time']
|
38
|
+
assert_equal stats.max_call_time, import['max_call_time']
|
39
|
+
assert_equal stats.min_call_time, import['min_call_time']
|
40
|
+
assert_equal stats.sum_of_squares, import['sum_of_squares']
|
41
|
+
assert_equal stats.call_count, import['call_count']
|
42
|
+
assert_equal stats.total_exclusive_time, import['total_exclusive_time']
|
43
|
+
end
|
44
|
+
|
45
|
+
def compare_metric_data(metric_data, import)
|
46
|
+
assert_equal 3, import.length
|
47
|
+
assert_equal metric_data.metric_id, import['metric_id']
|
48
|
+
compare_spec(metric_data.metric_spec, import['metric_spec']) unless metric_data.metric_id
|
49
|
+
compare_stat(metric_data.stats, import['stats'])
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
3
|
+
|
4
|
+
class NewRelic::Agent::MetricFrameTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_reader :f
|
7
|
+
def setup
|
8
|
+
@f = NewRelic::Agent::Instrumentation::MetricFrame.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_request_parsing__none
|
12
|
+
assert_nil f.uri
|
13
|
+
assert_nil f.referer
|
14
|
+
end
|
15
|
+
def test_request_parsing__path
|
16
|
+
request = stub(:path => '/path?hello=bob#none')
|
17
|
+
f.request = request
|
18
|
+
assert_equal "/path", f.uri
|
19
|
+
end
|
20
|
+
def test_request_parsing__fullpath
|
21
|
+
request = stub(:fullpath => '/path?hello=bob#none')
|
22
|
+
f.request = request
|
23
|
+
assert_equal "/path", f.uri
|
24
|
+
end
|
25
|
+
def test_request_parsing__referer
|
26
|
+
request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
|
27
|
+
f.request = request
|
28
|
+
assert_nil f.uri
|
29
|
+
assert_equal "https://www.yahoo.com:8080/path/hello", f.referer
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_request_parsing__uri
|
33
|
+
request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
|
34
|
+
f.request = request
|
35
|
+
assert_equal "/path", f.uri
|
36
|
+
assert_equal "/path/hello", f.referer
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_request_parsing__hostname_only
|
40
|
+
request = stub(:uri => 'http://creature.com')
|
41
|
+
f.request = request
|
42
|
+
assert_equal "/", f.uri
|
43
|
+
assert_nil f.referer
|
44
|
+
end
|
45
|
+
def test_request_parsing__slash
|
46
|
+
request = stub(:uri => 'http://creature.com/')
|
47
|
+
f.request = request
|
48
|
+
assert_equal "/", f.uri
|
49
|
+
assert_nil f.referer
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
class NewRelic::Agent::MockScopeListener
|
3
|
+
|
4
|
+
attr_reader :scope
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@scope = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def notice_first_scope_push(time)
|
11
|
+
end
|
12
|
+
|
13
|
+
def notice_push_scope(scope, time)
|
14
|
+
@scope[scope] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def notice_pop_scope(scope, time)
|
18
|
+
end
|
19
|
+
|
20
|
+
def notice_scope_empty(time)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
|
4
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
5
|
+
def setup
|
6
|
+
NewRelic::Agent.manual_start
|
7
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
8
|
+
@engine.clear_stats
|
9
|
+
end
|
10
|
+
def test_get
|
11
|
+
url = URI.parse('http://www.google.com/index.html')
|
12
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
13
|
+
http.get('/index.html')
|
14
|
+
}
|
15
|
+
assert_match /<head>/, res.body
|
16
|
+
assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
|
17
|
+
@engine.metrics.sort
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_background
|
21
|
+
perform_action_with_newrelic_trace("task", :category => :task) do
|
22
|
+
url = URI.parse('http://www.google.com/index.html')
|
23
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
24
|
+
http.get('/index.html')
|
25
|
+
}
|
26
|
+
assert_match /<head>/, res.body
|
27
|
+
end
|
28
|
+
assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
|
29
|
+
%w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
|
30
|
+
External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task].sort
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_transactional
|
34
|
+
perform_action_with_newrelic_trace("task") do
|
35
|
+
url = URI.parse('http://www.google.com/index.html')
|
36
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
37
|
+
http.get('/index.html')
|
38
|
+
}
|
39
|
+
assert_match /<head>/, res.body
|
40
|
+
end
|
41
|
+
assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
|
42
|
+
%w[External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
|
43
|
+
External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::NetInstrumentationTest/task].sort
|
44
|
+
end
|
45
|
+
def test_get__simple
|
46
|
+
Net::HTTP.get URI.parse('http://www.google.com/index.html')
|
47
|
+
assert_equal @engine.metrics.sort,
|
48
|
+
%w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
|
49
|
+
end
|
50
|
+
def test_ignore
|
51
|
+
NewRelic::Agent.disable_all_tracing do
|
52
|
+
url = URI.parse('http://www.google.com/index.html')
|
53
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
54
|
+
http.post('/index.html','data')
|
55
|
+
}
|
56
|
+
end
|
57
|
+
assert_equal 0, @engine.metrics.size
|
58
|
+
end
|
59
|
+
def test_head
|
60
|
+
url = URI.parse('http://www.google.com/index.html')
|
61
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
62
|
+
http.head('/index.html')
|
63
|
+
}
|
64
|
+
assert_equal %w[External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
|
65
|
+
@engine.metrics.sort
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_post
|
69
|
+
url = URI.parse('http://www.google.com/index.html')
|
70
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
71
|
+
http.post('/index.html','data')
|
72
|
+
}
|
73
|
+
assert_equal %w[External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
|
74
|
+
@engine.metrics.sort
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
ENV['SKIP_RAILS'] = 'true'
|
2
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
3
|
+
|
4
|
+
class RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
|
5
|
+
extend TestContexts
|
6
|
+
|
7
|
+
attr_reader :agent
|
8
|
+
|
9
|
+
with_running_agent do
|
10
|
+
# Fake out the agent to think mongrel is running
|
11
|
+
|
12
|
+
should "agent_setup" do
|
13
|
+
assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
|
14
|
+
assert_raise RuntimeError do
|
15
|
+
NewRelic::Control.instance.init_plugin :agent_enabled => false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "public_apis" do
|
20
|
+
assert_raise RuntimeError do
|
21
|
+
NewRelic::Agent.set_sql_obfuscator(:unknown) do |sql|
|
22
|
+
puts sql
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ignore_called = false
|
27
|
+
NewRelic::Agent.ignore_error_filter do |e|
|
28
|
+
ignore_called = true
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
NewRelic::Agent.notice_error(StandardError.new("message"), :request_params => {:x => "y"})
|
32
|
+
assert ignore_called
|
33
|
+
NewRelic::Agent.instance.error_collector.instance_variable_set '@ignore_filter', nil
|
34
|
+
end
|
35
|
+
|
36
|
+
should "startup_shutdown" do
|
37
|
+
@agent = NewRelic::Agent::ShimAgent.instance
|
38
|
+
@agent.shutdown
|
39
|
+
assert (not @agent.started?)
|
40
|
+
@agent.start
|
41
|
+
assert !@agent.started?
|
42
|
+
# this installs the real agent:
|
43
|
+
NewRelic::Agent.manual_start
|
44
|
+
@agent = NewRelic::Agent.instance
|
45
|
+
assert @agent != NewRelic::Agent::ShimAgent.instance
|
46
|
+
assert @agent.started?
|
47
|
+
@agent.shutdown
|
48
|
+
assert !@agent.started?
|
49
|
+
@agent.start
|
50
|
+
assert @agent.started?
|
51
|
+
end
|
52
|
+
|
53
|
+
should "manual_start" do
|
54
|
+
NewRelic::Agent.instance.expects(:connect).once
|
55
|
+
NewRelic::Agent.instance.expects(:start_worker_thread).once
|
56
|
+
NewRelic::Agent.instance.instance_variable_set '@started', nil
|
57
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "post_fork_handler" do
|
61
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
62
|
+
NewRelic::Agent.after_fork
|
63
|
+
NewRelic::Agent.after_fork
|
64
|
+
end
|
65
|
+
should "manual_overrides" do
|
66
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
67
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
68
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
69
|
+
end
|
70
|
+
|
71
|
+
should "restart" do
|
72
|
+
NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
|
73
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
74
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
75
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
76
|
+
end
|
77
|
+
|
78
|
+
should "send_timeslice_data" do
|
79
|
+
@agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
|
80
|
+
@agent.send :harvest_and_send_timeslice_data
|
81
|
+
assert_equal 3, @agent.metric_ids.size
|
82
|
+
assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
|
83
|
+
end
|
84
|
+
should "set_record_sql" do
|
85
|
+
@agent.set_record_sql(false)
|
86
|
+
assert !Thread::current[:record_sql]
|
87
|
+
NewRelic::Agent.disable_sql_recording do
|
88
|
+
assert_equal false, Thread::current[:record_sql]
|
89
|
+
NewRelic::Agent.disable_sql_recording do
|
90
|
+
assert_equal false, Thread::current[:record_sql]
|
91
|
+
end
|
92
|
+
assert_equal false, Thread::current[:record_sql]
|
93
|
+
end
|
94
|
+
assert !Thread::current[:record_sql], Thread::current[:record_sql]
|
95
|
+
@agent.set_record_sql(nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
should "version" do
|
99
|
+
assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
|
100
|
+
end
|
101
|
+
|
102
|
+
should "invoke_remote__ignore_non_200_results" do
|
103
|
+
NewRelic::Agent::Agent.class_eval do
|
104
|
+
public :invoke_remote
|
105
|
+
end
|
106
|
+
response_mock = mock()
|
107
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
108
|
+
response_mock.stubs(:message).returns("bogus error")
|
109
|
+
|
110
|
+
for code in %w[500 504 400 302 503] do
|
111
|
+
assert_raise NewRelic::Agent::ServerConnectionException, "Ignore #{code}" do
|
112
|
+
response_mock.stubs(:code).returns(code)
|
113
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
should "invoke_remote__throw_other_errors" do
|
118
|
+
NewRelic::Agent::Agent.class_eval do
|
119
|
+
public :invoke_remote
|
120
|
+
end
|
121
|
+
response_mock = Net::HTTPSuccess.new nil, nil, nil
|
122
|
+
response_mock.stubs(:body).returns("")
|
123
|
+
Marshal.stubs(:load).raises(RuntimeError, "marshal issue")
|
124
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
125
|
+
assert_raise RuntimeError do
|
126
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0xFEFE
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "with transaction api" do
|
131
|
+
should "reject empty arguments" do
|
132
|
+
assert_raises RuntimeError do
|
133
|
+
NewRelic::Agent.record_transaction 0.5
|
134
|
+
end
|
135
|
+
end
|
136
|
+
should "record a transaction" do
|
137
|
+
NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
|
3
|
+
|
4
|
+
class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
NewRelic::Agent.manual_start
|
7
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
8
|
+
rescue => e
|
9
|
+
puts e
|
10
|
+
puts e.backtrace.join("\n")
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
@engine.harvest_timeslice_data({},{})
|
14
|
+
end
|
15
|
+
def test_get_no_scope
|
16
|
+
s1 = @engine.get_stats "a"
|
17
|
+
s2 = @engine.get_stats "a"
|
18
|
+
s3 = @engine.get_stats "b"
|
19
|
+
|
20
|
+
assert_not_nil s1
|
21
|
+
assert_not_nil s2
|
22
|
+
assert_not_nil s3
|
23
|
+
|
24
|
+
assert s1 == s2
|
25
|
+
assert s1 != s3
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_harvest
|
29
|
+
s1 = @engine.get_stats "a"
|
30
|
+
s2 = @engine.get_stats "c"
|
31
|
+
|
32
|
+
s1.trace_call 10
|
33
|
+
s2.trace_call 1
|
34
|
+
s2.trace_call 3
|
35
|
+
|
36
|
+
assert @engine.get_stats("a").call_count == 1
|
37
|
+
assert @engine.get_stats("a").total_call_time == 10
|
38
|
+
|
39
|
+
assert @engine.get_stats("c").call_count == 2
|
40
|
+
assert @engine.get_stats("c").total_call_time == 4
|
41
|
+
|
42
|
+
metric_data = @engine.harvest_timeslice_data({}, {}).values
|
43
|
+
|
44
|
+
# after harvest, all the metrics should be reset
|
45
|
+
assert @engine.get_stats("a").call_count == 0
|
46
|
+
assert @engine.get_stats("a").total_call_time == 0
|
47
|
+
|
48
|
+
assert @engine.get_stats("c").call_count == 0
|
49
|
+
assert @engine.get_stats("c").total_call_time == 0
|
50
|
+
|
51
|
+
metric_data = metric_data.reverse if metric_data[0].metric_spec.name != "a"
|
52
|
+
|
53
|
+
assert metric_data[0].metric_spec.name == "a"
|
54
|
+
|
55
|
+
assert metric_data[0].stats.call_count == 1
|
56
|
+
assert metric_data[0].stats.total_call_time == 10
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_harvest_with_merge
|
60
|
+
s = @engine.get_stats "a"
|
61
|
+
s.trace_call 1
|
62
|
+
|
63
|
+
assert @engine.get_stats("a").call_count == 1
|
64
|
+
|
65
|
+
harvest = @engine.harvest_timeslice_data({}, {})
|
66
|
+
assert s.call_count == 0
|
67
|
+
s.trace_call 2
|
68
|
+
assert s.call_count == 1
|
69
|
+
|
70
|
+
# this calk should merge the contents of the previous harvest,
|
71
|
+
# so the stats for metric "a" should have 2 data points
|
72
|
+
harvest = @engine.harvest_timeslice_data(harvest, {})
|
73
|
+
stats = harvest.fetch(NewRelic::MetricSpec.new("a")).stats
|
74
|
+
assert stats.call_count == 2
|
75
|
+
assert stats.total_call_time == 3
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/samplers/cpu_sampler'
|
3
|
+
|
4
|
+
class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@stats_engine = NewRelic::Agent::StatsEngine.new
|
8
|
+
NewRelic::Agent.instance.stubs(:stats_engine).returns(@stats_engine)
|
9
|
+
end
|
10
|
+
def test_cpu
|
11
|
+
s = NewRelic::Agent::Samplers::CpuSampler.new
|
12
|
+
# need to sleep because if you go to fast it will skip the points
|
13
|
+
s.stats_engine = @stats_engine
|
14
|
+
sleep 2
|
15
|
+
s.poll
|
16
|
+
sleep 2
|
17
|
+
s.poll
|
18
|
+
assert_equal 2, s.systemtime_stats.call_count
|
19
|
+
assert_equal 2, s.usertime_stats.call_count
|
20
|
+
assert s.usertime_stats.total_call_time >= 0, "user cpu greater/equal to 0: #{s.usertime_stats.total_call_time}"
|
21
|
+
assert s.systemtime_stats.total_call_time >= 0, "system cpu greater/equal to 0: #{s.systemtime_stats.total_call_time}"
|
22
|
+
end
|
23
|
+
def test_memory__default
|
24
|
+
s = NewRelic::Agent::Samplers::MemorySampler.new
|
25
|
+
s.stats_engine = @stats_engine
|
26
|
+
s.poll
|
27
|
+
s.poll
|
28
|
+
s.poll
|
29
|
+
assert_equal 3, s.stats.call_count
|
30
|
+
assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
|
31
|
+
end
|
32
|
+
def test_memory__linux
|
33
|
+
return if RUBY_PLATFORM =~ /darwin/
|
34
|
+
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'linux'
|
35
|
+
s = NewRelic::Agent::Samplers::MemorySampler.new
|
36
|
+
s.stats_engine = @stats_engine
|
37
|
+
s.poll
|
38
|
+
s.poll
|
39
|
+
s.poll
|
40
|
+
assert_equal 3, s.stats.call_count
|
41
|
+
assert s.stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{s.stats.total_call_time}"
|
42
|
+
end
|
43
|
+
def test_memory__solaris
|
44
|
+
return if defined? JRuby
|
45
|
+
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'solaris'
|
46
|
+
NewRelic::Agent::Samplers::MemorySampler::ShellPS.any_instance.stubs(:get_memory).returns 999
|
47
|
+
s = NewRelic::Agent::Samplers::MemorySampler.new
|
48
|
+
s.stats_engine = @stats_engine
|
49
|
+
s.poll
|
50
|
+
assert_equal 1, s.stats.call_count
|
51
|
+
assert_equal 999, s.stats.total_call_time
|
52
|
+
end
|
53
|
+
def test_memory__windows
|
54
|
+
return if defined? JRuby
|
55
|
+
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'win32'
|
56
|
+
assert_raise NewRelic::Agent::Sampler::Unsupported do
|
57
|
+
NewRelic::Agent::Samplers::MemorySampler.new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
def test_load_samplers
|
61
|
+
@stats_engine.expects(:add_harvest_sampler).once unless defined? JRuby
|
62
|
+
@stats_engine.expects(:add_sampler).never
|
63
|
+
NewRelic::Control.instance.load_samplers
|
64
|
+
sampler_count = 4
|
65
|
+
assert_equal sampler_count, NewRelic::Agent::Sampler.sampler_classes.size, NewRelic::Agent::Sampler.sampler_classes.inspect
|
66
|
+
end
|
67
|
+
def test_memory__is_supported
|
68
|
+
NewRelic::Agent::Samplers::MemorySampler.stubs(:platform).returns 'windows'
|
69
|
+
assert !NewRelic::Agent::Samplers::MemorySampler.supported_on_this_platform? || defined? JRuby
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|