factorylabs-newrelic_rpm 2.10.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/CHANGELOG +354 -0
  2. data/LICENSE +37 -0
  3. data/README-2.10.2.2 +10 -0
  4. data/README.md +138 -0
  5. data/bin/mongrel_rpm +33 -0
  6. data/bin/newrelic_cmd +4 -0
  7. data/cert/cacert.pem +34 -0
  8. data/install.rb +45 -0
  9. data/lib/new_relic/agent.rb +315 -0
  10. data/lib/new_relic/agent/agent.rb +647 -0
  11. data/lib/new_relic/agent/busy_calculator.rb +86 -0
  12. data/lib/new_relic/agent/chained_call.rb +13 -0
  13. data/lib/new_relic/agent/collection_helper.rb +66 -0
  14. data/lib/new_relic/agent/error_collector.rb +117 -0
  15. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  16. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +91 -0
  17. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +389 -0
  19. data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
  20. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +12 -0
  21. data/lib/new_relic/agent/instrumentation/memcache.rb +24 -0
  22. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  23. data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
  24. data/lib/new_relic/agent/instrumentation/metric_frame.rb +199 -0
  25. data/lib/new_relic/agent/instrumentation/net.rb +21 -0
  26. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +109 -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/sinatra.rb +39 -0
  32. data/lib/new_relic/agent/method_tracer.rb +348 -0
  33. data/lib/new_relic/agent/patch_const_missing.rb +125 -0
  34. data/lib/new_relic/agent/sampler.rb +46 -0
  35. data/lib/new_relic/agent/samplers/cpu_sampler.rb +50 -0
  36. data/lib/new_relic/agent/samplers/memory_sampler.rb +141 -0
  37. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +23 -0
  38. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  39. data/lib/new_relic/agent/shim_agent.rb +21 -0
  40. data/lib/new_relic/agent/stats_engine.rb +22 -0
  41. data/lib/new_relic/agent/stats_engine/metric_stats.rb +116 -0
  42. data/lib/new_relic/agent/stats_engine/samplers.rb +74 -0
  43. data/lib/new_relic/agent/stats_engine/transactions.rb +154 -0
  44. data/lib/new_relic/agent/transaction_sampler.rb +315 -0
  45. data/lib/new_relic/agent/worker_loop.rb +118 -0
  46. data/lib/new_relic/commands/deployments.rb +145 -0
  47. data/lib/new_relic/commands/new_relic_commands.rb +30 -0
  48. data/lib/new_relic/control.rb +484 -0
  49. data/lib/new_relic/control/external.rb +13 -0
  50. data/lib/new_relic/control/merb.rb +24 -0
  51. data/lib/new_relic/control/rails.rb +151 -0
  52. data/lib/new_relic/control/ruby.rb +36 -0
  53. data/lib/new_relic/control/sinatra.rb +14 -0
  54. data/lib/new_relic/histogram.rb +89 -0
  55. data/lib/new_relic/local_environment.rb +299 -0
  56. data/lib/new_relic/merbtasks.rb +6 -0
  57. data/lib/new_relic/metric_data.rb +42 -0
  58. data/lib/new_relic/metric_parser.rb +124 -0
  59. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  60. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  61. data/lib/new_relic/metric_parser/active_record.rb +25 -0
  62. data/lib/new_relic/metric_parser/controller.rb +54 -0
  63. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  64. data/lib/new_relic/metric_parser/errors.rb +6 -0
  65. data/lib/new_relic/metric_parser/external.rb +50 -0
  66. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  67. data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
  68. data/lib/new_relic/metric_parser/view.rb +61 -0
  69. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  70. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  71. data/lib/new_relic/metric_spec.rb +67 -0
  72. data/lib/new_relic/metrics.rb +7 -0
  73. data/lib/new_relic/noticed_error.rb +23 -0
  74. data/lib/new_relic/rack/metric_app.rb +56 -0
  75. data/lib/new_relic/rack/mongrel_rpm.ru +25 -0
  76. data/lib/new_relic/rack/newrelic.yml +26 -0
  77. data/lib/new_relic/rack_app.rb +5 -0
  78. data/lib/new_relic/recipes.rb +82 -0
  79. data/lib/new_relic/stats.rb +362 -0
  80. data/lib/new_relic/transaction_analysis.rb +121 -0
  81. data/lib/new_relic/transaction_sample.rb +671 -0
  82. data/lib/new_relic/version.rb +54 -0
  83. data/lib/new_relic_api.rb +276 -0
  84. data/lib/newrelic_rpm.rb +45 -0
  85. data/lib/tasks/all.rb +4 -0
  86. data/lib/tasks/install.rake +7 -0
  87. data/lib/tasks/tests.rake +15 -0
  88. data/newrelic.yml +227 -0
  89. data/newrelic_rpm.gemspec +214 -0
  90. data/recipes/newrelic.rb +6 -0
  91. data/test/active_record_fixtures.rb +55 -0
  92. data/test/config/newrelic.yml +46 -0
  93. data/test/config/test_control.rb +38 -0
  94. data/test/new_relic/agent/active_record_instrumentation_test.rb +268 -0
  95. data/test/new_relic/agent/agent_controller_test.rb +254 -0
  96. data/test/new_relic/agent/agent_test_controller.rb +78 -0
  97. data/test/new_relic/agent/busy_calculator_test.rb +79 -0
  98. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  99. data/test/new_relic/agent/collection_helper_test.rb +125 -0
  100. data/test/new_relic/agent/error_collector_test.rb +173 -0
  101. data/test/new_relic/agent/method_tracer_test.rb +340 -0
  102. data/test/new_relic/agent/metric_data_test.rb +56 -0
  103. data/test/new_relic/agent/mock_ar_connection.rb +40 -0
  104. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  105. data/test/new_relic/agent/net_instrumentation_test.rb +63 -0
  106. data/test/new_relic/agent/rpm_agent_test.rb +125 -0
  107. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  108. data/test/new_relic/agent/stats_engine/samplers_test.rb +88 -0
  109. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
  110. data/test/new_relic/agent/task_instrumentation_test.rb +177 -0
  111. data/test/new_relic/agent/testable_agent.rb +13 -0
  112. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  113. data/test/new_relic/agent/transaction_sample_test.rb +186 -0
  114. data/test/new_relic/agent/transaction_sampler_test.rb +404 -0
  115. data/test/new_relic/agent/worker_loop_test.rb +103 -0
  116. data/test/new_relic/control_test.rb +110 -0
  117. data/test/new_relic/delayed_job_test.rb +108 -0
  118. data/test/new_relic/deployments_api_test.rb +68 -0
  119. data/test/new_relic/environment_test.rb +75 -0
  120. data/test/new_relic/metric_parser_test.rb +172 -0
  121. data/test/new_relic/metric_spec_test.rb +177 -0
  122. data/test/new_relic/shim_agent_test.rb +9 -0
  123. data/test/new_relic/stats_test.rb +291 -0
  124. data/test/new_relic/version_number_test.rb +76 -0
  125. data/test/test_helper.rb +53 -0
  126. data/test/ui/newrelic_controller_test.rb +14 -0
  127. data/test/ui/newrelic_helper_test.rb +53 -0
  128. data/ui/controllers/newrelic_controller.rb +220 -0
  129. data/ui/helpers/google_pie_chart.rb +49 -0
  130. data/ui/helpers/newrelic_helper.rb +320 -0
  131. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  132. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  133. data/ui/views/newrelic/_sample.rhtml +19 -0
  134. data/ui/views/newrelic/_segment.rhtml +28 -0
  135. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  136. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  137. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  138. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  139. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  140. data/ui/views/newrelic/_sql_row.rhtml +11 -0
  141. data/ui/views/newrelic/_stack_trace.rhtml +30 -0
  142. data/ui/views/newrelic/_table.rhtml +12 -0
  143. data/ui/views/newrelic/explain_sql.rhtml +42 -0
  144. data/ui/views/newrelic/images/arrow-close.png +0 -0
  145. data/ui/views/newrelic/images/arrow-open.png +0 -0
  146. data/ui/views/newrelic/images/blue_bar.gif +0 -0
  147. data/ui/views/newrelic/images/file_icon.png +0 -0
  148. data/ui/views/newrelic/images/gray_bar.gif +0 -0
  149. data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
  150. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  151. data/ui/views/newrelic/images/textmate.png +0 -0
  152. data/ui/views/newrelic/index.rhtml +57 -0
  153. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  154. data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
  155. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  156. data/ui/views/newrelic/show_sample.rhtml +80 -0
  157. data/ui/views/newrelic/show_source.rhtml +3 -0
  158. data/ui/views/newrelic/stylesheets/style.css +484 -0
  159. data/ui/views/newrelic/threads.rhtml +52 -0
  160. metadata +238 -0
@@ -0,0 +1,125 @@
1
+ # This class is for debugging purposes only.
2
+ # It inserts instrumentation into class loading to verify
3
+ # that no classes are being loaded on the new relic thread,
4
+ # which can cause problems in the class loader code.
5
+ # It is only loaded by agent.rb when a particular newrelic.yml
6
+ # option is set.
7
+
8
+ module ClassLoadingWatcher # :nodoc: all
9
+
10
+ extend self
11
+ @@background_thread = nil
12
+ @@flag_const_missing = nil
13
+
14
+ def background_thread
15
+ @@background_thread
16
+ end
17
+ def flag_const_missing
18
+ @@flag_const_missing
19
+ end
20
+ def flag_const_missing=(val)
21
+ @@flag_const_missing = val
22
+ end
23
+
24
+ def background_thread=(thread)
25
+ @@background_thread = thread
26
+
27
+ # these tests verify that check is working
28
+ =begin
29
+ @@background_thread = nil
30
+ bad = ConstMissingInForegroundThread rescue nil
31
+ @@background_thread = thread
32
+ bad = ConstMissingInBackgroundThread rescue nil
33
+ require 'new_relic/agent/patch_const_missing'
34
+ load 'new_relic/agent/patch_const_missing.rb'
35
+ =end
36
+ end
37
+ module SanityCheck
38
+ def nr_check_for_classloading(*args)
39
+
40
+ if Thread.current == ClassLoadingWatcher.background_thread
41
+ nr_error "Agent background thread shouldn't be loading classes (#{args.inspect})"
42
+ end
43
+ end
44
+ #
45
+ def nr_check_for_constmissing(*args)
46
+ if ClassLoadingWatcher.flag_const_missing
47
+ nr_error "Classes in Agent should not be loaded via const_missing (#{args.inspect})"
48
+ end
49
+ end
50
+ private
51
+ def nr_error(msg)
52
+ exception = NewRelic::Agent::BackgroundLoadingError.new(msg)
53
+ backtrace = caller
54
+ backtrace.shift
55
+ exception.set_backtrace(backtrace)
56
+ NewRelic::Agent.instance.error_collector.notice_error(exception, nil)
57
+ msg << "\n" << backtrace.join("\n")
58
+ NewRelic::Control.instance.log.error msg
59
+ end
60
+ end
61
+ def enable_warning
62
+ Object.class_eval do
63
+ if !defined?(non_new_relic_require)
64
+ alias_method :non_new_relic_require, :require
65
+ alias_method :require, :new_relic_require
66
+ end
67
+
68
+ if !defined?(non_new_relic_load)
69
+ alias_method :non_new_relic_load, :load
70
+ alias_method :load, :new_relic_load
71
+ end
72
+ end
73
+ Module.class_eval do
74
+ if !defined?(non_new_relic_const_missing)
75
+ alias_method :non_new_relic_const_missing, :const_missing
76
+ alias_method :const_missing, :new_relic_const_missing
77
+ end
78
+ end
79
+ end
80
+
81
+ def disable_warning
82
+ Object.class_eval do
83
+ if defined?(non_new_relic_require)
84
+ alias_method :require, :non_new_relic_require
85
+ undef non_new_relic_require
86
+ end
87
+
88
+ if defined?(non_new_relic_load)
89
+ alias_method :load, :non_new_relic_load
90
+ undef non_new_relic_load
91
+ end
92
+ end
93
+ Module.class_eval do
94
+ if defined?(non_new_relic_const_missing)
95
+ alias_method :const_missing, :non_new_relic_const_missing
96
+ undef non_new_relic_const_missing
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ class Object # :nodoc:
103
+ include ClassLoadingWatcher::SanityCheck
104
+
105
+ def new_relic_require(*args)
106
+ nr_check_for_classloading("Object require", *args)
107
+ non_new_relic_require(*args)
108
+ end
109
+
110
+ def new_relic_load(*args)
111
+ nr_check_for_classloading("Object load", *args)
112
+ non_new_relic_load(*args)
113
+ end
114
+ end
115
+
116
+
117
+ class Module # :nodoc:
118
+ include ClassLoadingWatcher::SanityCheck
119
+
120
+ def new_relic_const_missing(*args)
121
+ nr_check_for_constmissing("Module #{self.name} const_missing", *args)
122
+ nr_check_for_classloading("Module #{self.name} const_missing", *args)
123
+ non_new_relic_const_missing(*args)
124
+ end
125
+ end
@@ -0,0 +1,46 @@
1
+ # A Sampler is used to capture meaningful metrics in a background thread
2
+ # periodically. They will either be invoked once a minute just before the
3
+ # data is sent to the agent (default) or every 10 seconds, when #use_harvest_sampler?
4
+ # returns false.
5
+ #
6
+ # Samplers can be added to New Relic by subclassing NewRelic::Agent::Sampler.
7
+ # Instances are created when the agent is enabled and installed. Subclasses
8
+ # are registered for instantiation automatically.
9
+ class NewRelic::Agent::Sampler
10
+
11
+ # Exception denotes a sampler is not available and it will not be registered.
12
+ class Unsupported < StandardError; end
13
+
14
+ attr_accessor :stats_engine
15
+ attr_reader :id
16
+ @sampler_classes = []
17
+
18
+ def self.inherited(subclass)
19
+ @sampler_classes << subclass
20
+ end
21
+
22
+ # Override with check. Called before instantiating.
23
+ def self.supported_on_this_platform?
24
+ true
25
+ end
26
+
27
+ # Override to use the periodic sampler instead of running the sampler on the
28
+ # minute during harvests.
29
+ def self.use_harvest_sampler?
30
+ true
31
+ end
32
+
33
+ def self.sampler_classes
34
+ @sampler_classes
35
+ end
36
+
37
+ def initialize(id)
38
+ @id = id
39
+ end
40
+
41
+ def poll
42
+ raise "Implement in the subclass"
43
+ end
44
+
45
+
46
+ end
@@ -0,0 +1,50 @@
1
+ module NewRelic::Agent::Samplers
2
+ class CpuSampler < NewRelic::Agent::Sampler
3
+ attr_reader :last_time
4
+ def initialize
5
+ super :cpu
6
+ poll
7
+ end
8
+
9
+ def user_util_stats
10
+ stats_engine.get_stats_no_scope("CPU/User/Utilization")
11
+ end
12
+ def system_util_stats
13
+ stats_engine.get_stats_no_scope("CPU/System/Utilization")
14
+ end
15
+ def usertime_stats
16
+ stats_engine.get_stats_no_scope("CPU/User Time")
17
+ end
18
+ def systemtime_stats
19
+ stats_engine.get_stats_no_scope("CPU/System Time")
20
+ end
21
+
22
+ def self.supported_on_this_platform?
23
+ not defined?(JRuby)
24
+ end
25
+
26
+ def poll
27
+ now = Time.now
28
+ t = Process.times
29
+ if @last_time
30
+ elapsed = now - @last_time
31
+ return if elapsed < 1 # Causing some kind of math underflow
32
+ num_processors = NewRelic::Control.instance.local_env.processors || 1
33
+ usertime = t.utime - @last_utime
34
+ systemtime = t.stime - @last_stime
35
+
36
+ systemtime_stats.record_data_point(systemtime) if systemtime >= 0
37
+ usertime_stats.record_data_point(usertime) if usertime >= 0
38
+
39
+ # Calculate the true utilization by taking cpu times and dividing by
40
+ # elapsed time X num_processors.
41
+ user_util_stats.record_data_point usertime / (elapsed * num_processors)
42
+ system_util_stats.record_data_point systemtime / (elapsed * num_processors)
43
+ end
44
+ @last_utime = t.utime
45
+ @last_stime = t.stime
46
+ @last_time = now
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,141 @@
1
+ module NewRelic::Agent::Samplers
2
+
3
+ class MemorySampler < NewRelic::Agent::Sampler
4
+ attr_accessor :sampler
5
+
6
+ def initialize
7
+ super :memory
8
+ # macos, linux, solaris
9
+ if defined? JRuby
10
+ @sampler = JavaHeapSampler.new
11
+ elsif platform =~ /linux/
12
+ @sampler = ProcStatus.new
13
+ if !@sampler.can_run?
14
+ NewRelic::Agent.instance.log.warn "Error attempting to use /proc/#{$$}/status file for reading memory. Using ps command instead."
15
+ @sampler = ShellPS.new("ps -o rsz")
16
+ else
17
+ NewRelic::Agent.instance.log.info "Using /proc/#{$$}/status for reading process memory."
18
+ end
19
+ elsif platform =~ /darwin9/ # 10.5
20
+ @sampler = ShellPS.new("ps -o rsz")
21
+ elsif platform =~ /darwin10/ # 10.6
22
+ @sampler = ShellPS.new("ps -o rss")
23
+ elsif platform =~ /freebsd/
24
+ @sampler = ShellPS.new("ps -o rss")
25
+ elsif platform =~ /solaris/
26
+ @sampler = ShellPS.new("/usr/bin/ps -o rss -p")
27
+ end
28
+
29
+ raise Unsupported, "Unsupported platform for getting memory: #{platform}" if @sampler.nil?
30
+ raise Unsupported, "Unable to run #{@sampler}" unless @sampler.can_run?
31
+ end
32
+ def self.supported_on_this_platform?
33
+ defined?(JRuby) or platform =~ /linux|darwin9|darwin10|freebsd|solaris/
34
+ end
35
+
36
+ def self.use_harvest_sampler?
37
+ false
38
+ end
39
+
40
+ def self.platform
41
+ if RUBY_PLATFORM =~ /java/
42
+ %x[uname -s].downcase
43
+ else
44
+ RUBY_PLATFORM.downcase
45
+ end
46
+ end
47
+ def platform
48
+ NewRelic::Agent::Samplers::MemorySampler.platform
49
+ end
50
+
51
+ def stats
52
+ stats_engine.get_stats("Memory/Physical", false)
53
+ end
54
+ def poll
55
+ sample = @sampler.get_sample
56
+ stats.record_data_point sample if sample
57
+ stats
58
+ end
59
+ class Base
60
+ def can_run?
61
+ return false if @broken
62
+ m = get_memory rescue nil
63
+ m && m > 0
64
+ end
65
+ def get_sample
66
+ return nil if @broken
67
+ begin
68
+ m = get_memory
69
+ if m.nil?
70
+ NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. Disabling memory sampler."
71
+ @broken = true
72
+ end
73
+ return m
74
+ rescue => e
75
+ NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. (#{e})"
76
+ NewRelic::Agent.instance.log.debug e.backtrace.join("\n ")
77
+ NewRelic::Agent.instance.log.error "Disabling memory sampler."
78
+ @broken = true
79
+ return nil
80
+ end
81
+ end
82
+ end
83
+
84
+ class JavaHeapSampler < Base
85
+
86
+ def get_memory
87
+ raise "Can't sample Java heap unless running in JRuby" unless defined? JRuby
88
+ java.lang.Runtime.getRuntime.totalMemory / (1024 * 1024).to_f rescue nil
89
+ end
90
+ def to_s
91
+ "JRuby Java heap sampler"
92
+ end
93
+ end
94
+
95
+ class ShellPS < Base
96
+ def initialize(command)
97
+ super()
98
+ @command = command
99
+ end
100
+ # Returns the amount of resident memory this process is using in MB
101
+ #
102
+ def get_memory
103
+ process = $$
104
+ memory = `#{@command} #{process}`.split("\n")[1].to_f / 1024.0 rescue nil
105
+ # if for some reason the ps command doesn't work on the resident os,
106
+ # then don't execute it any more.
107
+ raise "Faulty command: `#{@command} #{process}`" if memory.nil? || memory <= 0
108
+ memory
109
+ end
110
+ def to_s
111
+ "shell command sampler: #{@command}"
112
+ end
113
+ end
114
+
115
+ # ProcStatus
116
+ #
117
+ # A class that samples memory by reading the file /proc/$$/status, which is specific to linux
118
+ #
119
+ class ProcStatus < Base
120
+
121
+ # Returns the amount of resident memory this process is using in MB
122
+ #
123
+ def get_memory
124
+ File.open(proc_status_file, "r") do |f|
125
+ while !f.eof?
126
+ if f.readline =~ /RSS:\s*(\d+) kB/i
127
+ return $1.to_f / 1024.0
128
+ end
129
+ end
130
+ end
131
+ raise "Unable to find RSS in #{proc_status_file}"
132
+ end
133
+ def proc_status_file
134
+ "/proc/#{$$}/status"
135
+ end
136
+ def to_s
137
+ "proc status file sampler: #{proc_status_file}"
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,23 @@
1
+ module NewRelic::Agent::Samplers
2
+ # NewRelic Instrumentation for Mongrel - tracks the queue length of the mongrel server.
3
+ class MongrelSampler < NewRelic::Agent::Sampler
4
+ def initialize
5
+ super :mongrel
6
+ raise Unsupported, "Mongrel not running" unless NewRelic::Control.instance.local_env.mongrel
7
+ end
8
+ def queue_stats
9
+ stats_engine.get_stats("Mongrel/Queue Length", false)
10
+ end
11
+ def poll
12
+ mongrel = NewRelic::Control.instance.local_env.mongrel
13
+ if mongrel
14
+ # The mongrel workers list includes workers actively processing requests
15
+ # so you need to subtract what appears to be the active workers from the total
16
+ # number of workers to get the queue size.
17
+ qsize = mongrel.workers.list.length - NewRelic::Agent::BusyCalculator.busy_count
18
+ qsize = 0 if qsize < 0
19
+ queue_stats.record_data_point qsize
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module NewRelic
2
+ module Agent
3
+ module Samplers
4
+ class ObjectSampler < NewRelic::Agent::Sampler
5
+
6
+ def initialize
7
+ super :objects
8
+ end
9
+
10
+ def stats
11
+ stats_engine.get_stats_no_scope("GC/objects")
12
+ end
13
+
14
+ def self.supported_on_this_platform?
15
+ defined?(ObjectSpace) && ObjectSpace.respond_to?(:live_objects)
16
+ end
17
+
18
+ def poll
19
+ stats.record_data_point(ObjectSpace.live_objects)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # This agent is loaded by the plug when the plug-in is disabled
2
+ # It recreates just enough of the API to not break any clients that
3
+ # invoke the Agent.
4
+ class NewRelic::Agent::ShimAgent < NewRelic::Agent::Agent
5
+ def self.instance
6
+ @instance ||= self.new
7
+ end
8
+ def initialize
9
+ super
10
+ @histogram.extend NewRelic::Histogram::Shim
11
+ @stats_engine.extend NewRelic::Agent::StatsEngine::Shim
12
+ @stats_engine.extend NewRelic::Agent::StatsEngine::Transactions::Shim
13
+ @transaction_sampler.extend NewRelic::Agent::TransactionSampler::Shim
14
+ @error_collector.extend NewRelic::Agent::ErrorCollector::Shim
15
+ end
16
+ def ensure_worker_thread_started; end
17
+ def start *args; end
18
+ def shutdown; end
19
+ def push_trace_execution_flag(*args); end
20
+ def pop_trace_execution_flag(*args); end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'new_relic/agent/stats_engine/metric_stats'
2
+ require 'new_relic/agent/stats_engine/samplers'
3
+ require 'new_relic/agent/stats_engine/transactions'
4
+
5
+ module NewRelic::Agent
6
+ class StatsEngine
7
+ include MetricStats
8
+ include Samplers
9
+ include Transactions
10
+
11
+ def initialize
12
+ # Makes the unit tests happy
13
+ Thread::current[:newrelic_scope_stack] = nil
14
+ spawn_sampler_thread
15
+ end
16
+
17
+ def log
18
+ NewRelic::Control.instance.log
19
+ end
20
+
21
+ end
22
+ end