public
Description: The kick ass (non-commercial) home for musicians and their music
Homepage: http://alonetone.com
Clone URL: git://github.com/sudara/alonetone.git
new relic update
sudara (author)
Sat Oct 04 17:41:12 -0700 2008
commit  46be70d438449abd1f1cf6214e27ddce8c10b652
tree    c6a9a6fb19eec7bc2327d1d986425676ecc686d1
parent  242d524b921fa29a77795e70f7d47a7155e891df
...
1
2
 
3
4
5
...
7
8
9
10
 
11
12
 
13
14
15
...
21
22
23
24
 
25
26
27
...
34
35
36
 
 
 
37
38
39
40
41
42
43
 
 
 
 
 
 
 
44
45
46
47
48
49
50
51
52
53
54
...
61
62
63
64
65
 
 
 
 
 
 
 
 
 
66
67
68
69
70
71
 
 
72
73
 
74
75
76
...
1
2
3
4
5
6
...
8
9
10
 
11
12
 
13
14
15
16
...
22
23
24
 
25
26
27
28
...
35
36
37
38
39
40
41
42
43
44
45
46
 
47
48
49
50
51
52
53
54
55
56
57
 
 
 
 
58
59
60
...
67
68
69
 
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
84
85
86
 
87
88
89
90
0
@@ -1,5 +1,6 @@
0
 require 'yaml'
0
 require 'newrelic/agent/method_tracer'
0
+require 'newrelic/local_environment'
0
 
0
 def to_stderr(s)
0
   STDERR.puts "** [NewRelic] " + s
0
@@ -7,9 +8,9 @@ end
0
 
0
 # Initializer for the NewRelic Agent
0
 config_filename = File.join(File.dirname(__FILE__), '..','..','..','config','newrelic.yml')
0
-begin catch (:disabled) do
0
+begin catch(:disabled) do
0
   begin
0
- newrelic_config_file = File.read(config_filename)
0
+ newrelic_config_file = File.read(File.expand_path(config_filename))
0
   rescue => e
0
     to_stderr e
0
     to_stderr "Could not read configuration file #{config_filename}."
0
@@ -21,7 +22,7 @@ begin catch (:disabled) do
0
   begin
0
     newrelic_agent_config = YAML.load(newrelic_config_file)[RAILS_ENV] || {}
0
   rescue Exception => e
0
- to_stderr "Error parsing #{config_filename}"
0
+ to_stderr "Error parsing #{newrelic_config_file}"
0
     to_stderr "#{e}"
0
     to_stderr "Agent is disabled."
0
     throw :disabled
0
@@ -34,21 +35,26 @@ begin catch (:disabled) do
0
   
0
   # Check to see if the agent should be enabled or not
0
 
0
+ # This determines the environment we are running in
0
+ env = NewRelic::LocalEnvironment.new
0
+
0
   # note if the agent is not turned on via the enabled flag in the
0
   # configuration file, the application will be untouched, and it will
0
   # behave exaclty as if the agent were never installed in the first place.
0
 
0
   ::RPM_TRACERS_ENABLED = ::RPM_DEVELOPER || ::RPM_AGENT_ENABLED
0
 
0
- if !::RPM_TRACERS_ENABLED || ENV['NEWRELIC_ENABLE'] && ENV['NEWRELIC_ENABLE'] =~ /false|off|no/i
0
+ # START THE AGENT
0
+ # We install the shim agent unless the tracers are enabled, the plugin
0
+ # env setting is not false, and the agent started okay.
0
+ if ::RPM_TRACERS_ENABLED && !(ENV['NEWRELIC_ENABLE'].to_s =~ /false|off|no/i)
0
+ require 'newrelic/agent'
0
+ NewRelic::Agent::Agent.instance.start(env.environment, env.identifier)
0
+ else
0
     require 'newrelic/shim_agent'
0
     throw :disabled
0
   end
0
   
0
- require 'newrelic/agent'
0
-
0
- agent = NewRelic::Agent.instance
0
- agent.start(newrelic_agent_config)
0
   
0
   # When (and only when) RPM is running in developer mode, a few pages
0
   # are added to your application that present performance information
0
@@ -61,16 +67,24 @@ begin catch (:disabled) do
0
     helper_path = File.join(File.dirname(__FILE__), 'ui', 'helpers')
0
     $LOAD_PATH << controller_path
0
     $LOAD_PATH << helper_path
0
- Dependencies.load_paths << controller_path
0
- Dependencies.load_paths << helper_path
0
+
0
+ # Rails Edge
0
+ if defined? ActiveSupport::Dependencies
0
+ ActiveSupport::Dependencies.load_paths << controller_path
0
+ ActiveSupport::Dependencies.load_paths << helper_path
0
+ else
0
+ Dependencies.load_paths << controller_path
0
+ Dependencies.load_paths << helper_path
0
+ end
0
     config.controller_paths << controller_path
0
     require 'newrelic_routing'
0
     
0
     # inform user that the dev edition is available if we are running inside
0
     # a webserver process
0
- if agent.local_port
0
+ if env.identifier
0
+ port = env.identifier =~ /^\d+/ ? ":#{port}" : ""
0
       to_stderr "NewRelic Agent (Developer Mode) enabled."
0
- to_stderr "To view performance information, go to http://localhost:#{agent.local_port}/newrelic"
0
+ to_stderr "To view performance information, go to http://localhost#{port}/newrelic"
0
     end
0
   end
0
 end
...
4
5
6
 
7
8
9
...
20
21
22
 
 
23
24
25
...
57
58
59
60
61
 
 
62
63
64
...
103
104
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
107
108
...
124
125
126
 
 
127
128
129
...
131
132
133
134
135
136
137
138
 
139
 
 
 
 
 
140
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
147
148
149
150
151
152
 
 
 
 
 
 
 
 
153
154
155
156
157
158
159
 
160
161
162
...
168
169
170
 
 
 
 
171
172
173
174
175
 
 
 
 
 
 
 
176
177
178
...
181
182
183
184
 
185
186
187
...
197
198
199
 
 
 
 
 
200
201
202
...
204
205
206
207
 
208
209
210
211
212
 
 
 
213
214
215
216
217
218
 
 
 
 
 
 
 
 
 
219
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
222
223
224
225
...
232
233
234
 
 
 
 
 
 
 
235
236
237
...
244
245
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
248
 
249
250
251
252
253
254
255
256
257
258
259
260
261
 
 
262
263
264
265
266
267
268
269
 
 
 
 
 
 
270
271
272
273
274
275
...
290
291
292
293
 
294
295
296
297
298
299
300
301
302
 
 
 
 
303
304
305
...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
 
374
375
376
377
378
379
380
381
382
 
383
384
385
...
390
391
392
393
 
394
395
396
...
400
401
402
 
403
404
405
...
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
 
519
520
521
...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
 
 
 
 
 
 
 
 
 
 
 
 
 
620
621
622
...
658
659
660
661
 
 
 
 
 
662
663
664
...
668
669
670
 
 
 
671
672
673
...
691
692
693
694
 
695
696
697
698
 
699
700
701
...
4
5
6
7
8
9
10
...
21
22
23
24
25
26
27
28
...
60
61
62
 
 
63
64
65
66
67
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
146
147
148
149
150
151
152
153
...
155
156
157
 
158
159
160
 
161
162
163
164
165
166
167
168
169
 
 
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
 
 
 
 
 
187
188
189
190
191
192
193
194
195
196
197
198
199
200
 
201
202
203
204
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
...
234
235
236
 
237
238
239
240
...
250
251
252
253
254
255
256
257
258
259
260
...
262
263
264
 
265
266
267
268
269
 
270
271
272
273
274
 
 
 
 
275
276
277
278
279
280
281
282
283
284
 
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
 
304
305
306
...
313
314
315
316
317
318
319
320
321
322
323
324
325
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
 
365
366
367
368
369
370
371
372
373
374
375
 
 
 
 
 
376
377
378
379
380
381
382
383
 
384
385
386
...
401
402
403
 
404
405
406
407
408
409
 
 
 
 
410
411
412
413
414
415
416
...
451
452
453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
455
456
457
458
459
460
 
461
 
462
463
464
465
...
470
471
472
 
473
474
475
476
...
480
481
482
483
484
485
486
...
518
519
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
523
524
525
526
 
 
527
 
528
529
530
531
...
614
615
616
 
 
 
 
 
 
 
 
 
 
 
 
 
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
668
669
670
 
671
672
673
674
675
676
677
678
...
682
683
684
685
686
687
688
689
690
...
708
709
710
 
711
712
713
714
 
715
716
717
718
0
@@ -4,6 +4,7 @@ require 'logger'
0
 require 'singleton'
0
 require 'zlib'
0
 
0
+require 'newrelic/version'
0
 require 'newrelic/stats'
0
 require 'newrelic/agent/worker_loop'
0
 
0
@@ -20,6 +21,8 @@ module NewRelic::Agent
0
   
0
   # an exception that forces an agent to stop reporting until its mongrel is restarted
0
   class ForceDisconnectException < Exception; end
0
+
0
+ class IgnoreSilentlyException < StandardError; end
0
   
0
   # add some convenience methods for easy access to the Agent singleton.
0
   # the following static methods all point to the same Agent instance:
0
@@ -57,8 +60,8 @@ module NewRelic::Agent
0
     # environment - the name of the environment. used for logging only
0
     # port - the name of this instance. shows up in the RPM UI screens. can be any String
0
     #
0
- def manual_start(environment, port)
0
- agent.manual_start(environment, port)
0
+ def manual_start(environment, identifier)
0
+ agent.manual_start(environment, identifier)
0
     end
0
     
0
     # This method sets the block sent to this method as a sql obfuscator.
0
@@ -103,6 +106,25 @@ module NewRelic::Agent
0
       agent.transaction_sampler.add_request_parameters(params)
0
     end
0
     
0
+ # This method disables the recording of transaction traces in the given
0
+ # block.
0
+ def disable_transaction_tracing
0
+ state = agent.set_record_tt(false)
0
+ begin
0
+ yield
0
+ ensure
0
+ agent.set_record_tt(state)
0
+ end
0
+ end
0
+
0
+ # This method allows a filter to be applied to errors that RPM will track.
0
+ # The block should return the exception to track (which could be different from
0
+ # the original exception) or nil to ignore this exception
0
+ #
0
+ def ignore_error_filter(&block)
0
+ agent.error_collector.ignore_error_filter &block
0
+ end
0
+
0
   end
0
   
0
   
0
@@ -124,6 +146,8 @@ module NewRelic::Agent
0
     DEFAULT_HOST = 'localhost'
0
     DEFAULT_PORT = 3000
0
     
0
+ # Config hash
0
+ attr_accessor :config
0
     attr_reader :obfuscator
0
     attr_reader :stats_engine
0
     attr_reader :transaction_sampler
0
@@ -131,32 +155,50 @@ module NewRelic::Agent
0
     attr_reader :worker_loop
0
     attr_reader :log
0
     attr_reader :license_key
0
- attr_reader :config
0
     attr_reader :remote_host
0
     attr_reader :remote_port
0
     attr_reader :record_sql
0
- attr_reader :local_port
0
+ attr_reader :identifier
0
     
0
+ # This method is deprecated. Use start.
0
+ def manual_start(environment, identifier)
0
+ start(environment, identifier, true)
0
+ end
0
+
0
     # Start up the agent, which will connect to the newrelic server and start
0
     # reporting performance information. Typically this is done from the
0
- # environment configuration file
0
- def start(config)
0
+ # environment configuration file.
0
+ # environment identifies the host environment, like mongrel, thin, or take.
0
+ # identifier is an identifier which uniquely identifies the process hosting
0
+ # the agent. It should be ideally something like a server port, like 3000,
0
+ # a handler thread name, or a script name. It should not be a PID because
0
+ # that will change
0
+ # from invocation to invocation. For something like rake, you could use
0
+ # the task name.
0
+ # Return false if the agent was not started
0
+ def start(environment, identifier, force=false)
0
+
0
+ @config ||= ::NR_CONFIG_FILE
0
+
0
       if @started
0
         log! "Agent Started Already!"
0
         raise "Duplicate attempt to start the NewRelic agent"
0
       end
0
-
0
- @config = config
0
-
0
- @local_port = determine_environment_and_port
0
- start_reporting if @local_port
0
+ @environment = environment
0
+ @identifier = identifier && identifier.to_s
0
+ if @identifier
0
+ start_reporting(force)
0
+ return true
0
+ else
0
+ return false
0
+ end
0
     end
0
     
0
     # this method makes sure that the agent is running. it's important
0
     # for passenger where processes are forked and the agent is dormant
0
     #
0
     def ensure_started
0
- return unless @prod_mode_enabled
0
+ return unless @prod_mode_enabled && !@invalid_license
0
       if @worker_thread.nil? || !@worker_thread.alive?
0
         launch_worker_thread
0
         @stats_engine.spawn_sampler_thread
0
@@ -168,11 +210,22 @@ module NewRelic::Agent
0
 
0
       setup_log
0
       
0
+ if @environment == :passenger
0
+ log.warn "Phusion Passenger has been detected. Some RPM memory statistics may have inaccuracies due to short process lifespans"
0
+ end
0
+
0
       @worker_loop = WorkerLoop.new(@log)
0
       @started = true
0
       
0
       @license_key = config.fetch('license_key', nil)
0
       
0
+ ignore_errors = config.fetch('ignore_errors', "")
0
+ ignore_errors = ignore_errors.split(",")
0
+ ignore_errors.each { |error| error.strip! }
0
+
0
+ @error_collector.ignore(ignore_errors)
0
+ @capture_params = config.fetch('capture_params', false)
0
+
0
       sampler_config = config.fetch('transaction_tracer', {})
0
       
0
       @use_transaction_sampler = sampler_config.fetch('enabled', false)
0
@@ -181,7 +234,7 @@ module NewRelic::Agent
0
       @explain_threshold = sampler_config.fetch('explain_threshold', '0.5').to_f
0
       @explain_enabled = sampler_config.fetch('explain_enabled', true)
0
       
0
- log.info "Transaction tracer enabled: #{@use_transaction_sampler}"
0
+ log.info "Transaction tracing is enabled in the agent" if @use_transaction_sampler
0
       log.warn "Agent is configured to send raw SQL to RPM service" if @record_sql == :raw
0
       
0
       @use_ssl = config.fetch('ssl', false)
0
@@ -197,6 +250,11 @@ module NewRelic::Agent
0
 
0
       @prod_mode_enabled = force_enable || config['enabled']
0
       
0
+ # Initialize transaction sampler
0
+ @transaction_sampler.capture_params = @capture_params
0
+ @error_collector.capture_params = @capture_params
0
+
0
+
0
       # make sure the license key exists and is likely to be really a license key
0
       # by checking it's string length (license keys are 40 character strings.)
0
       if @prod_mode_enabled && (!@license_key || @license_key.length != 40)
0
@@ -204,22 +262,45 @@ module NewRelic::Agent
0
         return
0
       end
0
 
0
- instrument_rails if force_enable || ::RPM_TRACERS_ENABLED
0
+ instrument_rails
0
       
0
       if @prod_mode_enabled
0
         load_samplers
0
         launch_worker_thread
0
- install_at_exit_handler
0
+ # When the VM shuts down, attempt to send a message to the server that
0
+ # this agent run is stopping, assuming it has successfully connected
0
+ at_exit { shutdown }
0
       end
0
     end
0
-
0
- def manual_start(environment, port)
0
- @environment = environment
0
- @local_port = port
0
+
0
+ # Attempt a graceful shutdown of the agent.
0
+ def shutdown
0
+ return if ! @started
0
+ @worker_loop.stop
0
+
0
+ log.debug "Starting Agent shutdown"
0
+
0
+ # if litespeed, then ignore all future SIGUSR1 - it's litespeed trying to shut us down
0
       
0
- start_reporting true
0
+ if @environment == :litespeed
0
+ Signal.trap("SIGUSR1", "IGNORE")
0
+ Signal.trap("SIGTERM", "IGNORE")
0
+ end
0
+
0
+ begin
0
+
0
+ # only call graceful_disconnect if we successfully stop the worker thread (since a transaction may be in flight)
0
+ if @worker_thread.join(30)
0
+ graceful_disconnect
0
+ else
0
+ log.debug "ERROR - could not stop worker thread"
0
+ end
0
+ rescue Exception => e
0
+ log.debug e
0
+ log.debug e.backtrace.join("\n")
0
+ end
0
+ @started = nil
0
     end
0
-
0
     
0
     def start_transaction
0
       @stats_engine.start_transaction
0
@@ -232,6 +313,13 @@ module NewRelic::Agent
0
       prev || true
0
     end
0
     
0
+ def set_record_tt(should_record)
0
+ prev = Thread::current[:record_tt]
0
+ Thread::current[:record_tt] = should_record
0
+
0
+ prev || true
0
+ end
0
+
0
     def set_sql_obfuscator(type, &block)
0
       if type == :before
0
         @obfuscator = ChainedCall.new(block, @obfuscator)
0
@@ -244,32 +332,55 @@ module NewRelic::Agent
0
       end
0
     end
0
 
0
+ # Collect the Rails::Info into an associative array as well as the list of plugins
0
+ def gather_info
0
+ i = []
0
+ begin
0
+ require 'builtin/rails_info/rails/info'
0
+ i += Rails::Info.properties
0
+ rescue Exception => e
0
+ log.debug "Unable to get the Rails info: #{e.inspect}"
0
+ log.debug e.backtrace.join("\n")
0
+ end
0
+ # Would like to get this from config, but how?
0
+ plugins = Dir[File.join(File.expand_path(__FILE__+"/../../../../.."),"/*")].collect { |p| File.basename p }
0
+ i << ['Plugin List', plugins]
0
+
0
+ # Look for a capistrano file indicating the current revision:
0
+ rev_file = File.expand_path(File.join(RAILS_ROOT, "REVISION"))
0
+ if File.readable?(rev_file) && File.size(rev_file) < 64
0
+ File.open(rev_file) { | file | i << ['Revision', file.read] } rescue nil
0
+ end
0
+ i
0
+ end
0
     
0
     private
0
+
0
     def initialize
0
       @connected = false
0
       @launch_time = Time.now
0
       
0
       @metric_ids = {}
0
       @environment = :unknown
0
- @initalized_pid = $$
0
       
0
       @stats_engine = StatsEngine.new
0
       @transaction_sampler = TransactionSampler.new(self)
0
       @error_collector = ErrorCollector.new(self)
0
       
0
       @request_timeout = 15 * 60
0
+
0
+ @invalid_license = false
0
     end
0
     
0
     def setup_log
0
- if @local_port
0
- log_file = "#{RAILS_ROOT}/log/newrelic_agent.#{@local_port}.log"
0
- else
0
- log_file = "#{RAILS_ROOT}/log/newrelic_agent.log"
0
- end
0
+ log_path = ::RAILS_DEFAULT_LOGGER.instance_eval do
0
+ File.dirname(@log.path) rescue File.dirname(@logdev.filename)
0
+ end rescue "#{RAILS_ROOT}/log"
0
+ log_path = File.expand_path(log_path)
0
+ identifier_part = identifier && identifier[/[\.\w]*$/]
0
+ log_file = "#{RAILS_ROOT}/log/newrelic_agent.#{identifier_part ? identifier_part + "." : "" }log"
0
       
0
       @log = Logger.new log_file
0
- @log.level = Logger::INFO
0
       
0
       # change the format just for our logger
0
       
0
@@ -290,16 +401,16 @@ module NewRelic::Agent
0
       end
0
       
0
       log! "New Relic RPM Agent Initialized: pid = #{$$}"
0
- to_stderr "Agent Log is found in #{log_file}"
0
+ log! "Agent Log is found in #{log_file}"
0
       log.info "Runtime environment: #{@environment.to_s.titleize}"
0
     end
0
     
0
     
0
     def launch_worker_thread
0
-
0
- # we don't launch the worker_thread for passenger due to the way it spawns processes
0
-
0
- return if (@environment == :passenger && @initalized_pid == $$)
0
+ if (@environment == :passenger && $0 =~ /ApplicationSpawner/)
0
+ log.info "Process is passenger spawner - don't connect to RPM service"
0
+ return
0
+ end
0
       
0
       @worker_thread = Thread.new do
0
         @worker_thread_started = true
0
@@ -340,46 +451,15 @@ module NewRelic::Agent
0
     end
0
     
0
     
0
- def install_at_exit_handler
0
- # When the VM shuts down, attempt to send a message to the server that
0
- # this agent run is stopping, assuming it has successfully connected
0
- at_exit do
0
- @worker_loop.stop
0
-
0
- log.debug "Starting Agent shutdown"
0
-
0
- # if litespeed, then ignore all future SIGUSR1 - it's litespeed trying to shut us down
0
-
0
- if @environment == :litespeed
0
- Signal.trap("SIGUSR1", "IGNORE")
0
- Signal.trap("SIGTERM", "IGNORE")
0
- end
0
-
0
- begin
0
-
0
- # only call graceful_disconnect if we successfully stop the worker thread (since a transaction may be in flight)
0
- if @worker_thread.join(30)
0
- graceful_disconnect
0
- else
0
- log.debug "ERROR - could not stop worker thread"
0
- end
0
- rescue Exception => e
0
- log.debug e
0
- log.debug e.backtrace.join("\n")
0
- end
0
- end
0
- end
0
-
0
-
0
+
0
     def connect
0
       @connect_retry_period ||= 5
0
       @connect_attempts ||= 0
0
       
0
       # wait a few seconds for the web server to boot
0
       sleep @connect_retry_period.to_i
0
-
0
       @agent_id = invoke_remote :launch, @local_host,
0
- @local_port, determine_home_directory, $$, @launch_time.to_f
0
+ @identifier, determine_home_directory, $$, @launch_time.to_f, NewRelic::VERSION::STRING, gather_info
0
       
0
       log! "Connected to NewRelic Service at #{@remote_host}:#{@remote_port}."
0
       log.debug "Agent ID = #{@agent_id}."
0
@@ -390,7 +470,7 @@ module NewRelic::Agent
0
       # Ask for mermission to collect error data
0
       @should_send_errors = invoke_remote :should_collect_errors, @agent_id
0
       
0
- log! "Transaction tracer enabled from RPM service: #{@should_send_samples}"
0
+ log! "Transaction traces will be sent to the RPM service" if @use_transaction_sampler && @should_send_samples
0
       
0
       @connected = true
0
       @last_harvest_time = Time.now
0
@@ -400,6 +480,7 @@ module NewRelic::Agent
0
       log! e.message, :error
0
       log! "Visit NewRelic.com to obtain a valid license key, or to upgrade your account."
0
       log! "Turning New Relic Agent off."
0
+ @invalid_license = true
0
       return false
0
       
0
     rescue Timeout::Error, StandardError => e
0
@@ -437,85 +518,14 @@ module NewRelic::Agent
0
     def determine_host
0
       Socket.gethostname
0
     end
0
-
0
- # determine the environment we are running in (one of :webrick,
0
- # :mongrel, :thin, or :unknown) and if the process is listening
0
- # on a port, return the port # that we are listening on. When
0
- # this returns nil for the port, then the agent will not run.
0
- def determine_environment_and_port
0
- # Note: log won't be available yet.
0
- port = nil
0
- @environment = :unknown
0
-
0
- begin
0
- # OPTIONS is set by script/server
0
- port = OPTIONS.fetch :port, DEFAULT_PORT
0
- @environment = :webrick
0
- return port
0
- rescue NameError
0
- end # continue on if this didn't succeed...
0
 
0
- # this case covers starting by mongrel_rails
0
- if defined? Mongrel::HttpServer
0
- ObjectSpace.each_object(Mongrel::HttpServer) do |mongrel|
0
- @environment = :mongrel
0
- return mongrel.port
0
- end
0
- end
0
-
0
- if defined? Thin::Server
0
- # This case covers the thin web server
0
- # Same issue as above- we assume only one instance per process
0
- ObjectSpace.each_object(Thin::Server) do |thin_server|
0
- @environment = :thin
0
- backend = thin_server.backend
0
- # We need a way to uniquely identify and distinguish agents. The port
0
- # works for this. When using sockets, use the socket file name.
0
- if backend.respond_to? :port
0
- return backend.port
0
- elsif backend.respond_to? :socket
0
- return backend.socket
0
- end
0
- end # each thin instance
0
- end
0
-
0
- if RUBY_PLATFORM =~ /java/
0
- # Check for JRuby environment. Not sure how this works in different appservers
0
- require 'java'
0
- require 'jruby'
0
- @environment = :jruby
0
- return java.lang.System.identityHashCode(JRuby.runtime)
0
- end
0
-
0
- if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/
0
- @environment = :litespeed
0
- return 'litespeed'
0
- end
0
-
0
- if defined? Passenger::AbstractServer
0
- @environment = :passenger
0
- return 'passenger'
0
- end
0
-
0
- if config['monitor_daemons']
0
- @environment = :daemon
0
- # return the base part of the file name
0
- return File.basename($0).split(".").first
0
- end
0
-
0
- # if no real environment was found
0
- return nil
0
- end
0
-
0
     def determine_home_directory
0
       File.expand_path(RAILS_ROOT)
0
     end
0
     
0
     def instrument_rails
0
- @instrumented ||= false
0
-
0
       return if @instrumented
0
-
0
+
0
       @instrumented = true
0
       
0
       Module.method_tracer_log = log
0
@@ -604,19 +614,19 @@ module NewRelic::Agent
0
         @unsent_errors = []
0
       end
0
     end
0
-
0
- def handle_messages(messages)
0
- messages.each do |message|
0
- begin
0
- message = Marshal.load(message)
0
- message.execute(self)
0
- log.debug("Received Message: #{message.to_yaml}")
0
- rescue => e
0
- log.error "Error handling message: #{e}"
0
- log.debug e.backtrace.join("\n")
0
- end
0
- end