Skip to content

Commit

Permalink
import development from SVN
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggederest committed Sep 7, 2010
1 parent 5060d8f commit 944dc0a
Show file tree
Hide file tree
Showing 84 changed files with 1,167 additions and 1,148 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'rake/testtask'

GEM_NAME = "newrelic_rpm"
GEM_VERSION = NewRelic::VERSION::STRING
AUTHOR = "Bill Kayser"
AUTHORS = "Bill Kayser", "Justin George"
EMAIL = "[email protected]"
HOMEPAGE = "http://www.github.com/newrelic/rpm"
SUMMARY = "New Relic Ruby Performance Monitoring Agent"
Expand Down Expand Up @@ -44,7 +44,7 @@ begin
gem.summary = SUMMARY
gem.email = EMAIL
gem.homepage = HOMEPAGE
gem.author = AUTHOR
gem.authors = AUTHORS
gem.version = GEM_VERSION
gem.files = FileList['**/*']
gem.test_files = [] # You can't really run the tests unless the gem is installed.
Expand Down
100 changes: 50 additions & 50 deletions lib/new_relic/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
#
# == Getting Started
# For instructions on installation and setup, see
# the README[link:./files/README_rdoc.html] file.
# the README[link:./files/README_rdoc.html] file.
#
# == Using with Rack/Metal
#
# To instrument Rack middlwares or Metal apps, refer to the docs in
# To instrument Rack middlwares or Metal apps, refer to the docs in
# NewRelic::Agent::Instrumentation::Rack.
#
# == Agent API
#
# For details on the Agent API, refer to NewRelic::Agent.
#
# == Customizing RPM
#
#
# For detailed information on customizing the RPM Agent
# please visit our {support and documentation site}[http://support.newrelic.com].
#
module NewRelic
# == Agent APIs
# This module contains the public API methods for the Agent.
#
# For adding custom instrumentation to method invocations, refer to
# For adding custom instrumentation to method invocations, refer to
# the docs in the class NewRelic::Agent::MethodTracer.
#
# For information on how to customize the controller
Expand Down Expand Up @@ -71,7 +71,7 @@ module Agent
require 'new_relic/noticed_error'
require 'new_relic/histogram'
require 'new_relic/timer_lib'

require 'new_relic/agent/chained_call'
require 'new_relic/agent/agent'
require 'new_relic/agent/shim_agent'
Expand All @@ -84,49 +84,49 @@ module Agent
require 'new_relic/agent/sampler'

require 'new_relic/agent/instrumentation/controller_instrumentation'

require 'new_relic/agent/samplers/cpu_sampler'
require 'new_relic/agent/samplers/memory_sampler'
require 'new_relic/agent/samplers/object_sampler'
require 'new_relic/agent/samplers/delayed_job_lock_sampler'
require 'set'
require 'thread'
require 'resolv'

# An exception that is thrown by the server if the agent license is invalid.
class LicenseException < StandardError; end

# An exception that forces an agent to stop reporting until its mongrel is restarted.
class ForceDisconnectException < StandardError; end

# An exception that forces an agent to restart.
class ForceRestartException < StandardError; end

# Used to blow out of a periodic task without logging a an error, such as for routine
# failures.
class ServerConnectionException < 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 < ServerConnectionException; end

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

class BackgroundLoadingError < StandardError; end

@agent = nil

# The singleton Agent instance. Used internally.
def agent #:nodoc:
raise "Plugin not initialized!" if @agent.nil?
@agent
end

def agent= new_instance #:nodoc:
@agent = new_instance
end

alias instance agent #:nodoc:

# Get or create a statistics gatherer that will aggregate numerical data
Expand All @@ -140,18 +140,18 @@ def agent= new_instance #:nodoc:
def get_stats(metric_name, use_scope=false)
@agent.stats_engine.get_stats(metric_name, use_scope)
end
alias get_stats_no_scope get_stats

alias get_stats_no_scope get_stats

# Get the logger for the agent. Available after the agent has initialized.
# This sends output to the agent log file.
def logger
NewRelic::Control.instance.log
end

# Call this to manually start the Agent in situations where the Agent does
# not auto-start.
#
#
# When the app environment loads, so does the Agent. However, the
# Agent will only connect to RPM if a web front-end is found. If
# you want to selectively monitor ruby processes that don't use
Expand All @@ -168,33 +168,33 @@ def manual_start(options={})
raise unless Hash === options
NewRelic::Control.instance.init_plugin({ :agent_enabled => true, :sync_startup => true }.merge(options))
end

# Register this method as a callback for processes that fork
# jobs.
# jobs.
#
# If the master/parent connects to the agent prior to forking the
# agent in the forked process will use that agent_run. Otherwise
# the forked process will establish a new connection with the
# server.
#
#
# Use this especially when you fork the process to run background
# jobs or other work. If you are doing this with a web dispatcher
# that forks worker processes then you will need to force the
# agent to reconnect, which it won't do by default. Passenger and
# Unicorn are already handled, nothing special needed for them.
#
# Options:
# * <tt>:force_reconnect => true</tt> to force the spawned process to
# * <tt>:force_reconnect => true</tt> to force the spawned process to
# establish a new connection, such as when forking a long running process.
# The default is false--it will only connect to the server if the parent
# had not connected.
# * <tt>:keep_retrying => false</tt> if we try to initiate a new
# * <tt>:keep_retrying => false</tt> if we try to initiate a new
# connection, this tells me to only try it once so this method returns
# quickly if there is some kind of latency with the server.
def after_fork(options={})
agent.after_fork(options)
end

# Clear out any unsent metric data.
def reset_stats
agent.reset_stats
Expand All @@ -204,7 +204,7 @@ def reset_stats
# and kills the background thread.
def shutdown
agent.shutdown
end
end

# Add instrumentation files to the agent. The argument should be
# a glob matching ruby scripts which will be executed at the time
Expand All @@ -229,21 +229,21 @@ def add_instrumentation file_pattern
# NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
# my_obfuscator(sql)
# end
#
#
def set_sql_obfuscator(type = :replace, &block)
agent.set_sql_obfuscator type, &block
end


# This method sets the state of sql recording in the transaction
# sampler feature. Within the given block, no sql will be recorded
#
# usage:
#
# NewRelic::Agent.disable_sql_recording do
# ...
# ...
# end
#
#
def disable_sql_recording
state = agent.set_record_sql(false)
begin
Expand All @@ -252,9 +252,9 @@ def disable_sql_recording
agent.set_record_sql(state)
end
end

# This method disables the recording of transaction traces in the given
# block. See also #disable_all_tracing
# block. See also #disable_all_tracing
def disable_transaction_tracing
state = agent.set_record_tt(false)
begin
Expand All @@ -263,7 +263,7 @@ def disable_transaction_tracing
agent.set_record_tt(state)
end
end

# Cancel the collection of the current transaction in progress, if
# any. Only affects the transaction started on this thread once
# it has started and before it has completed.
Expand All @@ -273,7 +273,7 @@ def abort_transaction!
NewRelic::Agent::Instrumentation::MetricFrame.abort_transaction!
end
end

# Yield to the block without collecting any metrics or traces in
# any of the subsequent calls. If executed recursively, will keep
# track of the first entry point and turn on tracing again after
Expand All @@ -285,28 +285,28 @@ def disable_all_tracing
ensure
agent.pop_trace_execution_flag
end

# Check to see if we are capturing metrics currently on this thread.
def is_execution_traced?
Thread.current[:newrelic_untraced].nil? || Thread.current[:newrelic_untraced].last != false
Thread.current[:newrelic_untraced].nil? || Thread.current[:newrelic_untraced].last != false
end

# Set a filter to be applied to errors that RPM will track. The
# block should evalute to the exception to track (which could be
# different from the original exception) or nil to ignore this
# exception.
#
# The block is yielded to with the exception to filter.
#
# The block is yielded to with the exception to filter.
#
# Return the new block or the existing filter Proc if no block is passed.
#
def ignore_error_filter(&block)
agent.error_collector.ignore_error_filter(&block)
end

# Record the given error in RPM. It will be passed through the
# #ignore_error_filter if there is one.
#
#
# * <tt>exception</tt> is the exception which will be recorded. May also be
# an error message.
# Options:
Expand All @@ -328,11 +328,11 @@ def notice_error(exception, options={})
def add_custom_parameters(params)
NewRelic::Agent::Instrumentation::MetricFrame.add_custom_parameters(params)
end

# The #add_request_parameters method is aliased to #add_custom_parameters
# and is now deprecated.
alias add_request_parameters add_custom_parameters #:nodoc:

# Yield to a block that is run with a database metric name
# context. This means the Database instrumentation will use this
# for the metric name if it does not otherwise know about a model.
Expand All @@ -348,9 +348,9 @@ def with_database_metric_name(model, method, &block)
yield
end
end
# Record a web transaction from an external source. This will
# process the response time, error, and score an apdex value.

# Record a web transaction from an external source. This will
# process the response time, error, and score an apdex value.
#
# First argument is a float value, time in seconds. Option
# keys are strings.
Expand All @@ -363,7 +363,7 @@ def with_database_metric_name(model, method, &block)
# provided.
#
# == Error options
# Provide one of the following:
# Provide one of the following:
# * <tt>'is_error' => true</tt> if an unknown error occurred
# * <tt>'error_message' => msg</tt> if an error message is available
# * <tt>'exception' => exception</tt> if a ruby exception is recorded
Expand All @@ -378,5 +378,5 @@ def with_database_metric_name(model, method, &block)
def record_transaction(response_sec, options = {})
agent.record_transaction(response_sec, options)
end
end
end
end
end
Loading

0 comments on commit 944dc0a

Please sign in to comment.