Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Add redis instrumentation contributed by ngmoco
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed May 4, 2010
1 parent 0d78e93 commit 2e8f0a2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
* Version 1.0.8

Redis instrumentation contributed by Ashley Martens
Authlogic moved into RPM Ruby Agent

* Version 1.0.7
Expand Down
96 changes: 52 additions & 44 deletions README.md
@@ -1,34 +1,30 @@
# The RPM Contrib Gem

The `rpm_contrib` gem contains instrumentation for the New Relic RPM
agent contributed by the community of RPM users. It requires the RPM
Agent to run.
The `rpm_contrib` gem contains instrumentation for the New Relic RPM agent
contributed by the community of RPM users. It requires the RPM Agent to run.

To use the contrib gem, install the `rpm_contrib` gem from gemcutter.
It will also install the required version of the `newrelic_rpm` gem if
it's not already installed.
To use the contrib gem, install the `rpm_contrib` gem from gemcutter. It will
also install the required version of the `newrelic_rpm` gem if it's not already
installed.

For Rails 2.1 and later, add this dependency to your in your
environment.rb:
For Rails 2.1 and later, add this dependency to your in your environment.rb:

config.gem 'rpm_contrib'

For other frameworks, make sure you load rubygems if it isn't already,
then just require the contrib gem:
For other frameworks, make sure you load rubygems if it isn't already, then just
require the contrib gem:

require 'rubygems'
require 'rpm_contrib'

When you load the rpm_contrib gem, the `newrelic_rpm` gem will also be
initialized. No need for a separate require statement for
`newrelic_rpm`. The `rpm_contrib` gem must be loaded before the
`newrelic_rpm` gem initializes.
initialized. No need for a separate require statement for `newrelic_rpm`. The
`rpm_contrib` gem must be loaded before the `newrelic_rpm` gem initializes.

# Supported Frameworks

A number of frameworks are supported in the contrib gem. They are all
turned on by default but you can add settings to your newrelic.yml to
disable any of them.
A number of frameworks are supported in the contrib gem. They are all turned on
by default but you can add settings to your newrelic.yml to disable any of them.

### Camping

Expand All @@ -52,19 +48,27 @@ To disable resque, add this to your newrelic.yml:

disable_resque: true

### Redis

Redis instrumentation will record operations as well as `allWeb` and `allOther`
summary metrics under the `Database/Redis` metric namespace.

To disable Redis instrumentation, add this to your newrelic.yml:

disable_redis: true

# How to Add Custom Instrumentation

We encourage contributions to this project and will provide whatever
assistance we can to those wishing to develop instrumentation for
other open source Ruby libraries.
We encourage contributions to this project and will provide whatever assistance
we can to those wishing to develop instrumentation for other open source Ruby
libraries.

When adding instrumentation to this gem, be sure and get familiar with the
[RPM Agent API](http://newrelic.github.com/rpm/classes/NewRelic/Agent.html)
and contact support@newrelic.com with any questions.
When adding instrumentation to this gem, be sure and get familiar with the [RPM
Agent API](http://newrelic.github.com/rpm/classes/NewRelic/Agent.html) and
contact support@newrelic.com with any questions.

There are several extension points in the agent you can take advantage of
with this gem.
There are several extension points in the agent you can take advantage of with
this gem.

* Custom tracers which measure methods and give visibility to
otherwise unmeasured libraries.
Expand All @@ -80,41 +84,45 @@ Custom tracers for frameworks should be added to the `lib/rpm_contrib/instrument
directory. These files are loaded at the time the Agent starts. **They will not
be loaded if the Agent does not start up.**

It is important that you wrap any instrumentation with the checks necessary
to determine if the code being instrumented is loaded. You can't add code to the
It is important that you wrap any instrumentation with the checks necessary to
determine if the code being instrumented is loaded. You can't add code to the
contrib gem that will break when run in any other context besides yours.


For details on how to define custom tracers, refer to the [support documentation on adding
custom tracers](http://support.newrelic.com/faqs/docs/custom-metric-collection). You
can also get detailed information on the API from the
[Agent method tracing rdocs](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer.html),
especially the [add_method_tracer](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer/ClassMethods.html)
For details on how to define custom tracers, refer to the [support documentation
on adding custom
tracers](http://support.newrelic.com/faqs/docs/custom-metric-collection). You
can also get detailed information on the API from the [Agent method tracing
rdocs](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer.html),
especially the
[add_method_tracer](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer/ClassMethods.html)
docs.

A good example can be found in `lib/rpm_contrib/instrumentation/paperclip.rb`.

## Samplers

You can add samplers which will record metrics approximately once a minute. Samplers
are useful for capturing generic instrumentation for display in
[custom views](http://support.newrelic.com/faqs/docs/custom-dashboard-specification).
You can add samplers which will record metrics approximately once a minute.
Samplers are useful for capturing generic instrumentation for display in [custom
views](http://support.newrelic.com/faqs/docs/custom-dashboard-specification).

Samplers should extend the [`NewRelic::Agent::Sampler`](http://newrelic.github.com/rpm/classes/NewRelic/Agent/Sampler.html)
Samplers should extend the
[`NewRelic::Agent::Sampler`](http://newrelic.github.com/rpm/classes/NewRelic/Agent/Sampler.html)
class. They should be placed in the `samplers` directory.

Refer to examples in the RPM agent to see how to get started.

## Supporting New Dispatchers

If you want to add support for a new dispatcher which is not being recognized by default
by the RPM agent, add code to the `rpm_contrib/detection` directory. This code needs
to define a module in the `NewRelic::LocalEnvironment` class. This module will be
accessed at the time environment detection takes place, when the agent is initialized.
If you want to add support for a new dispatcher which is not being recognized by
default by the RPM agent, add code to the `rpm_contrib/detection` directory.
This code needs to define a module in the `NewRelic::LocalEnvironment` class.
This module will be accessed at the time environment detection takes place, when
the agent is initialized.

This module should define the method `discover_dispatcher` and return the name of the
dispatcher if detected, or defer to super. See `rpm_contrib/detection/camping.rb`
for a good example.
This module should define the method `discover_dispatcher` and return the name
of the dispatcher if detected, or defer to super. See
`rpm_contrib/detection/camping.rb` for a good example.

## Supporting New Frameworks

Expand Down Expand Up @@ -146,8 +154,8 @@ we'll be happy to help you work through it.

Refer to the Agent API Documentation at http://newrelic.github.com/rpm

See the support site faqs at http://support.newrelic.com/faqs for
additional tips and documentation.
See the support site faqs at http://support.newrelic.com/faqs for additional
tips and documentation.

Contact support@newrelic.com for help.

Expand Down
12 changes: 7 additions & 5 deletions lib/rpm_contrib/instrumentation/redis.rb
@@ -1,23 +1,25 @@
# == Redis Instrumentation
# Redis instrumentation contributed by Ashley Martens of ngmoco
#

if defined?(::Redis) and not NewRelic::Control.instance['disable_redis_instrumentation']
if defined?(::Redis) and not NewRelic::Control.instance['disable_redis']

::Redis.class_eval do

include NewRelic::Agent::MethodTracer

def raw_call_command_with_newrelic_trace *args
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
metrics = ["Redis/#{method_name}",
(NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction? ? 'Redis/allWeb' : 'Redis/allOther')]
metrics = ["Database/Redis/#{method_name}",
(NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction? ? 'Database/Redis/allWeb' : 'Database/Redis/allOther')]
self.class.trace_execution_scoped(metrics) do
# NewRelic::Control.instance.log.debug("Instrumenting Redis Call[#{method_name}]: #{args[0].inspect}")
raw_call_command_without_newrelic_trace(*args)
end
end

alias_method_chain :raw_call_command, :newrelic_trace
# alias_method_chain :raw_call_command, :newrelic_trace
alias raw_call_command_without_newrelic_trace raw_call_command
alias raw_call_command raw_call_command_with_newrelic_trace

end

Expand Down
19 changes: 10 additions & 9 deletions rpm_contrib.gemspec
Expand Up @@ -5,39 +5,40 @@

Gem::Specification.new do |s|
s.name = %q{rpm_contrib}
s.version = "1.0.7"
s.version = "1.0.8"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Bill Kayser"]
s.date = %q{2010-04-14}
s.description = %q{ Community contributed instrumentation for various frameworks based on
the New Relic Ruby monitoring gem newrelic_rpm.
s.date = %q{2010-05-04}
s.description = %q{Community contributed instrumentation for various frameworks based on
the New Relic Ruby monitoring gem newrelic_rpm.
}
s.email = %q{support@newrelic.com}
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
"CHANGELOG",
"LICENSE",
"README.md"
]
s.files = [
"CHANGELOG",
"LICENSE",
"README.rdoc",
"README.md",
"Rakefile",
"lib/new_relic/control/camping.rb",
"lib/rpm_contrib.rb",
"lib/rpm_contrib/detection/camping.rb",
"lib/rpm_contrib/detection/resque.rb",
"lib/rpm_contrib/instrumentation/authlogic.rb",
"lib/rpm_contrib/instrumentation/camping.rb",
"lib/rpm_contrib/instrumentation/mongodb.rb",
"lib/rpm_contrib/instrumentation/paperclip.rb",
"lib/rpm_contrib/instrumentation/redis.rb",
"lib/rpm_contrib/instrumentation/resque.rb",
"test/helper.rb",
"test/schema.rb",
"test/test_rpm_contrib.rb"
]
s.homepage = %q{http://github.com/newrelic/rpm_contrib}
s.rdoc_options = ["--charset=UTF-8"]
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source", "--title", "Contributed Instrumentation for New Relic RPM", "-m", "README.md"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.summary = %q{Contributed Instrumentation for New Relic RPM}
Expand Down

0 comments on commit 2e8f0a2

Please sign in to comment.