Navigation Menu

Skip to content

Commit

Permalink
Revert the revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed Jul 7, 2009
1 parent 7f00852 commit fee28b2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 47 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG
@@ -1,4 +1,8 @@
v2.9.2
v2.9.3.
* Fix startup failure in Windows due to memory sampler
* Add JRuby environment information

v2.9.2.
* change default apdex_t to 0.5 seconds
* fix bug in deployments introduced by multi_homed setting
* support overriding the log in the agent api
Expand Down
4 changes: 4 additions & 0 deletions lib/new_relic/agent.rb
Expand Up @@ -81,6 +81,10 @@ class ForceDisconnectException < StandardError; end
# failures.
class IgnoreSilentlyException < StandardError; end

# Used for when a transaction trace or error report has too much
# data, so we reset the queue to clear the extra-large item
class PostTooBigException < IgnoreSilentlyException; end

# Reserved for future use. Meant to represent a problem on the server side.
class ServerError < StandardError; end

Expand Down
96 changes: 55 additions & 41 deletions lib/new_relic/agent/agent.rb
Expand Up @@ -5,15 +5,17 @@
require 'zlib'
require 'stringio'

# The NewRelic Agent collects performance data from ruby applications in realtime as the
# application runs, and periodically sends that data to the NewRelic server.
# The NewRelic Agent collects performance data from ruby applications
# in realtime as the application runs, and periodically sends that
# data to the NewRelic server.
module NewRelic::Agent

# The Agent is a singleton that is instantiated when the plugin is activated.

# The Agent is a singleton that is instantiated when the plugin is
# activated.
class Agent

# Specifies the version of the agent's communication protocol
# with the NewRelic hosted site.
# Specifies the version of the agent's communication protocol with
# the NewRelic hosted site.

PROTOCOL_VERSION = 5

Expand All @@ -34,7 +36,8 @@ def manual_start(ignored=nil, also_ignored=nil)
end

# this method makes sure that the agent is running. it's important
# for passenger where processes are forked and the agent is dormant
# for passenger where processes are forked and the agent is
# dormant
#
def ensure_worker_thread_started
return unless control.agent_enabled? && control.monitor_mode? && !@invalid_license
Expand All @@ -45,7 +48,7 @@ def ensure_worker_thread_started
end

# True if the worker thread has been started. Doesn't necessarily
# mean we are connected
# mean we are connected
def running?
control.agent_enabled? && control.monitor_mode? && @worker_loop && @worker_loop.pid == $$
end
Expand All @@ -63,7 +66,8 @@ def shutdown

log.debug "Starting Agent shutdown"

# if litespeed, then ignore all future SIGUSR1 - it's litespeed trying to shut us down
# if litespeed, then ignore all future SIGUSR1 - it's
# litespeed trying to shut us down

if control.dispatcher == :litespeed
Signal.trap("SIGUSR1", "IGNORE")
Expand Down Expand Up @@ -129,10 +133,11 @@ def set_sql_obfuscator(type, &block)
def log
NewRelic::Control.instance.log
end

# Start up the agent. This verifies that the agent_enabled? is true
# and initializes the sampler based on the current controluration settings.
# Then it will fire up the background thread for sending data to the server if applicable.

# Start up the agent. This verifies that the agent_enabled? is
# true and initializes the sampler based on the current
# controluration settings. Then it will fire up the background
# thread for sending data to the server if applicable.
def start
if started?
control.log! "Agent Started Already!", :error
Expand All @@ -155,8 +160,10 @@ def start

@record_sql = sampler_config.fetch('record_sql', :obfuscated).to_sym

# use transaction_threshold: 4.0 to force the TT collection threshold to 4 seconds
# use transaction_threshold: apdex_f to use your apdex t value multiplied by 4
# use transaction_threshold: 4.0 to force the TT collection
# threshold to 4 seconds
# use transaction_threshold: apdex_f to use your apdex t value
# multiplied by 4
# undefined transaction_threshold defaults to 2.0
apdex_f = 4 * NewRelic::Control.instance['apdex_t'].to_f
@slowest_transaction_threshold = sampler_config.fetch('transaction_threshold', 2.0)
Expand Down Expand Up @@ -188,8 +195,9 @@ def start
control.log! "Invalid license key: #{control.license_key}", :error
else
launch_worker_thread
# When the VM shuts down, attempt to send a message to the server that
# this agent run is stopping, assuming it has successfully connected
# When the VM shuts down, attempt to send a message to the
# server that this agent run is stopping, assuming it has
# successfully connected
at_exit { shutdown }
end
end
Expand All @@ -202,19 +210,20 @@ def collector
@collector ||= control.server
end

# Connect to the server, and run the worker loop forever. Will not return.
# Connect to the server, and run the worker loop forever.
# Will not return.
def run_worker_loop

# connect to the server. this will keep retrying until successful or
# it determines the license is bad.
# connect to the server. this will keep retrying until
# successful or it determines the license is bad.
connect

# We may not be connected now but keep going for dev mode
if @connected
begin
# determine the reporting period (server based)
# note if the agent attempts to report more frequently than the specified
# report data, then it will be ignored.
# determine the reporting period (server based)
# note if the agent attempts to report more frequently than
# the specified report data, then it will be ignored.

control.log! "Reporting performance data every #{@report_period} seconds."
@worker_loop.add_task(@report_period) do
Expand Down Expand Up @@ -271,9 +280,11 @@ def launch_worker_thread
end
@worker_thread['newrelic_label'] = 'Worker Loop'

# This code should be activated to check that no dependency loading is occuring in the background thread
# by stopping the foreground thread after the background thread is created. Turn on dependency loading logging
# and make sure that no loading occurs.
# This code should be activated to check that no dependency
# loading is occuring in the background thread by stopping the
# foreground thread after the background thread is created. Turn
# on dependency loading logging and make sure that no loading
# occurs.
#
# control.log! "FINISHED AGENT INIT"
# while true
Expand Down Expand Up @@ -302,12 +313,11 @@ def initialize
@last_harvest_time = Time.now
end

# Connect to the server and validate the license.
# If successful, @connected has true when finished.
# If not successful, you can keep calling this.
# Return false if we could not establish a connection with the
# server and we should not retry, such as if there's
# a bad license key.
# Connect to the server and validate the license. If successful,
# @connected has true when finished. If not successful, you can
# keep calling this. Return false if we could not establish a
# connection with the server and we should not retry, such as if
# there's a bad license key.
def connect
# wait a few seconds for the web server to boot, necessary in development
connect_retry_period = 5
Expand All @@ -331,7 +341,8 @@ def connect
control.log! "Connected to NewRelic Service at #{@collector}"
log.debug "Agent ID = #{@agent_id}."

# Ask the server for permission to send transaction samples. determined by subscription license.
# Ask the server for permission to send transaction samples.
# determined by subscription license.
@should_send_samples = invoke_remote :should_collect_samples, @agent_id

if @should_send_samples
Expand Down Expand Up @@ -446,13 +457,15 @@ def harvest_and_send_slowest_sample
log.debug "#{now}: sent slowest sample (#{@agent_id}) in #{Time.now - now} seconds"
end

# if we succeed sending this sample, then we don't need to keep the slowest sample
# around - it has been sent already and we can collect the next one
# if we succeed sending this sample, then we don't need to keep
# the slowest sample around - it has been sent already and we
# can collect the next one
@traces = nil

# note - exceptions are logged in invoke_remote. If an exception is encountered here,
# then the slowest sample of is determined of the entire period since the last
# reported sample.
# note - exceptions are logged in invoke_remote. If an
# exception is encountered here, then the slowest sample of is
# determined of the entire period since the last reported
# sample.
end

def harvest_and_send_errors
Expand Down Expand Up @@ -522,9 +535,10 @@ def invoke_remote(method, *args)
end
rescue ForceDisconnectException => e
log.error "RPM forced this agent to disconnect (#{e.message})\n" \
"Restart this process to resume monitoring via rpm.newrelic.com."
# when a disconnect is requested, stop the current thread, which is the worker thread that
# gathers data and talks to the server.
"Restart this process to resume monitoring via rpm.newrelic.com."
# when a disconnect is requested, stop the current thread, which
# is the worker thread that gathers data and talks to the
# server.
@connected = false
Thread.exit
rescue SystemCallError, SocketError => e
Expand Down
6 changes: 5 additions & 1 deletion lib/new_relic/control.rb
Expand Up @@ -291,7 +291,11 @@ def load_samplers
agent = NewRelic::Agent.instance
agent.stats_engine.add_sampler NewRelic::Agent::Samplers::MongrelSampler.new if local_env.mongrel
agent.stats_engine.add_harvest_sampler NewRelic::Agent::Samplers::CpuSampler.new unless defined? Java
agent.stats_engine.add_sampler NewRelic::Agent::Samplers::MemorySampler.new
begin
agent.stats_engine.add_sampler NewRelic::Agent::Samplers::MemorySampler.new
rescue RuntimeError => e
log.error "Cannot add memory sampling: #{e}"
end
end

protected
Expand Down
4 changes: 4 additions & 0 deletions lib/new_relic/local_environment.rb
Expand Up @@ -75,6 +75,10 @@ def gather_environment_info
append_environment_value('Ruby version'){ RUBY_VERSION }
append_environment_value('Ruby platform') { RUBY_PLATFORM }
append_environment_value('Ruby patchlevel') { RUBY_PATCHLEVEL }
if defined? Java
append_environment_value('JRuby version') { JRUBY_VERSION }
append_environment_value('Java VM version') { ENV_JAVA['java.vm.version']}
end
append_environment_value('OS version') { `uname -v` }
append_environment_value('OS') { `uname -s` } ||
append_environment_value('OS') { ENV['OS'] }
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/version.rb
Expand Up @@ -3,7 +3,7 @@ module NewRelic
module VERSION #:nodoc:
MAJOR = 2
MINOR = 9
TINY = 2
TINY = 3
STRING = [MAJOR, MINOR, TINY].join('.')
end

Expand Down
5 changes: 2 additions & 3 deletions ui/views/layouts/newrelic_default.rhtml
Expand Up @@ -39,10 +39,9 @@
</div>
<div id='footer'>
<img width="100%" height="4" src="<%= url_for(:controller => :newrelic, :action => :image, :file => 'blue_bar.gif', :content_type => 'image/gif') %>" alt="spacer"/>
<p>Crazy about Rails? Want to be a part of one of the fastest growing companies
in the Rails community? <a href="http://www.newrelic.com/jobs.html" title="Learn more about what we're looking for.">We're Hiring! &raquo;</a><br />
<p>We're hiring! Check out our <%=link_to "job postings", 'http://www.newrelic.com/jobs.html' %></p>
<a href="/newrelic">Home</a> | <a href="&#109;&#97;&#105;&#108;&#116;&#111;:&#x73;&#x75;&#x70;&#112;&#111;&#x72;&#116;&#x40;&#x6E;&#x65;&#119;&#114;&#x65;&#x6C;&#105;&#x63;&#x2E;&#99;&#x6F;&#109;?subject=&#70;&#101;&#x65;&#x64;&#x62;&#x61;&#x63;&#107;" title="">&#x46;&#x65;&#101;&#x64;&#98;&#97;&#x63;&#x6B;</a><br />
Monitor your Rails Application in Production. <a href="http://www.newrelic.com/dev-upgrade.html">Learn more. &raquo;</a><br />
&copy; 2008 New Relic. All rights reserved.</p>
&copy; 2008 - <%= Time.now.strftime('%Y') %> New Relic. All rights reserved.</p>
</div>
</body>

0 comments on commit fee28b2

Please sign in to comment.