ghazel-rpm_contrib 1.0.13.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,64 @@
1
+ * Version 1.0.13
2
+
3
+ Removed use of 'metaclass' - no longer available from ActiveSupport as of Rails 3
4
+ Contributed by Chris Griego
5
+
6
+ * Version 1.0.12
7
+
8
+ Better support for initialization within a Rails 3 application
9
+ rpm_contrib now depends on newrelic_rpm >= 2.13.1
10
+
11
+ * Version 1.0.11
12
+
13
+ AWS/S3 instrumentation contributed by Brian Doll
14
+ Cassandra instrumentation contributed by Ashley Martens
15
+ Updated Redis instrumentation for 1.x and 2.x contributed by Karl Baum
16
+
17
+ * Version 1.0.10
18
+
19
+ Mongoid support contributed by Karl Baum
20
+
21
+ * Version 1.0.9
22
+
23
+ Fixed dependency specification on newrelic_rpm
24
+
25
+ * Version 1.0.8
26
+
27
+ Redis instrumentation contributed by Ashley Martens
28
+ Authlogic moved into RPM Ruby Agent
29
+
30
+ * Version 1.0.7
31
+
32
+ Resque instrumentation now supports the resque-multi-job-forks plugin
33
+
34
+ * Version 1.0.6
35
+
36
+ Update newrelic dependency: depends on 2.11.1
37
+
38
+ * Version 1.0.5
39
+
40
+ Clear stats in forked resque jobs
41
+
42
+ * Version 1.0.4
43
+
44
+ Resque support
45
+
46
+ * Version 1.0.3
47
+
48
+ MongoDB instrumentation contributed by John Nunemaker
49
+
50
+ * Version 1.0.2
51
+
52
+ Improved Camping support
53
+
54
+ * Version 1.0.1
55
+
56
+ Removed DelayedJob, put back in core agent
57
+
58
+ * Version 1.0.0
59
+
60
+ Initial Release:
61
+ - Camping
62
+ - Authlogic
63
+ - DelayedJob
64
+ - Paperclip
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2010 New Relic, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # The RPM Contrib Gem
2
+
3
+ The `rpm_contrib` gem contains instrumentation for the New Relic RPM agent
4
+ contributed by the community of RPM users. It requires the RPM Agent to run.
5
+
6
+ To use the rpm_contrib gem, install the `rpm_contrib` gem from rubygems.org.
7
+ It will also install the required version of the `newrelic_rpm` gem if it's not
8
+ already installed.
9
+
10
+ For Rails 3.0 and later, add this dependency to your Gemfile:
11
+
12
+ gem 'rpm_contrib'
13
+
14
+ For Rails 2.1 and later, add this dependency to your in your environment.rb:
15
+
16
+ config.gem 'rpm_contrib'
17
+
18
+ For other frameworks, make sure you load rubygems if it isn't already, then just
19
+ require the rpm_contrib gem:
20
+
21
+ require 'rubygems'
22
+ require 'rpm_contrib'
23
+
24
+ When you load the rpm_contrib gem, the `newrelic_rpm` gem will also be
25
+ initialized. No need for a separate require statement for `newrelic_rpm`. The
26
+ `rpm_contrib` gem must be loaded before the `newrelic_rpm` gem initializes.
27
+
28
+ # Supported Frameworks
29
+
30
+ A number of frameworks are supported in the contrib gem. They are all turned on
31
+ by default but you can add settings to your newrelic.yml to disable any of them.
32
+
33
+ ### Camping
34
+
35
+ The gem will detect a Camping app but you need to manually add the
36
+ instrumentation to your configuration file. See RPMContrib::Instrumentation::Camping
37
+ for more information.
38
+
39
+ ### Paperclip
40
+
41
+ No special configuration required for Paperclip visibility. You can disable
42
+ it by setting `disable_paperclip` to true in the newrelic.yml file.
43
+
44
+ ### MongoDB
45
+
46
+ Both MongoMapper and Mongoid are supported. You can disable them both by setting
47
+ 'disable_mongodb' to true in the newrelic.yml file.
48
+
49
+ ### Resque
50
+
51
+ To disable resque, set 'disable_resque' to true in your newrelic.yml file.
52
+
53
+ ### Redis
54
+
55
+ Redis instrumentation will record operations as well as `allWeb` and `allOther`
56
+ summary metrics under the `Database/Redis` metric namespace. This instrumentation
57
+ supports Redis versions 1.x and 2.x. To disable Redis instrumentation, set
58
+ 'disable_redis' to true in your newrelic.yml file.
59
+
60
+ ### AWS/S3
61
+
62
+ Get metrics on how S3 is performing for you in production. To disable AWS/S3, set
63
+ 'disable_aws-s3' to true in your newrelic.yml file. For more information on this
64
+ instrumentation, check out [our blog](http://blog.newrelic.com/2010/07/06/monitoring-aws-s3/).
65
+
66
+ # How to Add Custom Instrumentation
67
+
68
+ We encourage contributions to this project and will provide whatever assistance
69
+ we can to those wishing to develop instrumentation for other open source Ruby
70
+ libraries.
71
+
72
+ When adding instrumentation to this gem, be sure and get familiar with the [RPM
73
+ Agent API](http://newrelic.github.com/rpm/classes/NewRelic/Agent.html) and
74
+ contact support@newrelic.com with any questions.
75
+
76
+ There are several extension points in the agent you can take advantage of with
77
+ this gem.
78
+
79
+ * Custom tracers which measure methods and give visibility to
80
+ otherwise unmeasured libraries.
81
+ * Samplers which sample some value about once a minute.
82
+ * Dispatcher support for web request handlers which would otherwise be undetected.
83
+ In order for the agent to turn on in 'auto' mode it needs to discover a
84
+ web dispatcher, or be [started manually](http://support.newrelic.com/faqs/general/manual-start).
85
+ * Framework support, for alternatives to Rails like Camping or Ramaze
86
+
87
+ ## Custom Tracers
88
+
89
+ Custom tracers for frameworks should be added to the `lib/rpm_contrib/instrumentation`
90
+ directory. These files are loaded at the time the Agent starts. **They will not
91
+ be loaded if the Agent does not start up.**
92
+
93
+ It is important that you wrap any instrumentation with the checks necessary to
94
+ determine if the code being instrumented is loaded. You can't add code to the
95
+ contrib gem that will break when run in any other context besides yours.
96
+
97
+
98
+ For details on how to define custom tracers, refer to the [support documentation
99
+ on adding custom
100
+ tracers](http://support.newrelic.com/faqs/docs/custom-metric-collection). You
101
+ can also get detailed information on the API from the [Agent method tracing
102
+ rdocs](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer.html),
103
+ especially the
104
+ [add_method_tracer](http://newrelic.github.com/rpm/classes/NewRelic/Agent/MethodTracer/ClassMethods.html)
105
+ docs.
106
+
107
+ A good example can be found in `lib/rpm_contrib/instrumentation/paperclip.rb`.
108
+
109
+ ## Samplers
110
+
111
+ You can add samplers which will record metrics approximately once a minute.
112
+ Samplers are useful for capturing generic instrumentation for display in [custom
113
+ views](http://support.newrelic.com/faqs/docs/custom-dashboard-specification).
114
+
115
+ Samplers should extend the
116
+ [`NewRelic::Agent::Sampler`](http://newrelic.github.com/rpm/classes/NewRelic/Agent/Sampler.html)
117
+ class. They should be placed in the `samplers` directory.
118
+
119
+ Refer to examples in the RPM agent to see how to get started.
120
+
121
+ ## Supporting New Dispatchers
122
+
123
+ If you want to add support for a new dispatcher which is not being recognized by
124
+ default by the RPM agent, add code to the `rpm_contrib/detection` directory.
125
+ This code needs to define a module in the `NewRelic::LocalEnvironment` class.
126
+ This module will be accessed at the time environment detection takes place, when
127
+ the agent is initialized.
128
+
129
+ This module should define the method `discover_dispatcher` and return the name
130
+ of the dispatcher if detected, or defer to super. See
131
+ `rpm_contrib/detection/camping.rb` for a good example.
132
+
133
+ ## Supporting New Frameworks
134
+
135
+ Supporting new frameworks can be pretty involved and generally involves both
136
+ adding custom instrumentation as well as framework and dispatcher detection.
137
+
138
+ In addition it will be necessary to define a new control class with the same
139
+ name as the framework. This control class must go in `new_relic/control`.
140
+
141
+ Refer to the camping example in this gem to see how this is done in general.
142
+
143
+ If you decide to tackle any new frameworks, contact support@newrelic.com and
144
+ we'll be happy to help you work through it.
145
+
146
+ # Note on Patches/Pull Requests
147
+
148
+ * Fork the http://www.github.com/newrelic/rpm_contrib project.
149
+ * Add instrumentation files to `lib/rpm_contrib/instrumentation`. These
150
+ files will be loaded when the RPM agent is initialized.
151
+ * Add samplers to `lib/rpm_contrib/samplers`. These classes are
152
+ installed automatically when the RPM agent is initialized.
153
+ * Add tests.
154
+ * Commit, do not mess with the Rakefile, version, or history. (if you
155
+ want to have your own version, that is fine but bump version in a
156
+ commit by itself I can ignore when I pull)
157
+ * Send me a pull request. Bonus points for topic branches.
158
+
159
+ # Further Information
160
+
161
+ Refer to the Agent API Documentation at http://newrelic.github.com/rpm
162
+
163
+ See the support site faqs at http://support.newrelic.com/faqs for additional
164
+ tips and documentation.
165
+
166
+ Contact support@newrelic.com for help.
167
+
168
+ ### Copyright
169
+
170
+ Copyright (c) 2009-2010 New Relic. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ # See http://www.rubygems.org/read/chapter/20
4
+
5
+ def version
6
+ @rpm_contrib_version ||= File.read("CHANGELOG")[/Version ([\d\.]+)$/, 1]
7
+ end
8
+
9
+ RDOC_FILES = FileList['README*','LICENSE','CHANGELOG']
10
+ SUMMARY = "Contributed Instrumentation for New Relic RPM"
11
+ DESCRIPTION = <<-EOF
12
+ Community contributed instrumentation for various frameworks based on
13
+ the New Relic Ruby monitoring gem newrelic_rpm.
14
+ EOF
15
+
16
+ begin
17
+ require 'jeweler'
18
+ Jeweler::Tasks.new do |gem|
19
+ gem.name = "rpm_contrib"
20
+ gem.summary = SUMMARY
21
+ gem.description = DESCRIPTION
22
+ gem.email = "support@newrelic.com"
23
+ gem.homepage = "http://github.com/newrelic/rpm_contrib"
24
+ gem.author = "Bill Kayser"
25
+ gem.add_dependency 'newrelic_rpm', '>=2.13.1'
26
+ gem.version = version
27
+ gem.files = FileList['LICENSE', 'README*', 'lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
28
+ gem.rdoc_options <<
29
+ "--line-numbers" <<
30
+ "--inline-source" <<
31
+ "--title" << SUMMARY <<
32
+ "-m" << "README.md"
33
+ gem.extra_rdoc_files = RDOC_FILES
34
+ end
35
+ Jeweler::GemcutterTasks.new
36
+ rescue LoadError
37
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
38
+ end
39
+
40
+ require 'rake/testtask'
41
+ Rake::TestTask.new(:test) do |test|
42
+ test.libs << 'lib' << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = true
45
+ end
46
+
47
+ begin
48
+ require 'rcov/rcovtask'
49
+ Rcov::RcovTask.new do |test|
50
+ test.libs << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+ rescue LoadError
55
+ task :rcov do
56
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
57
+ end
58
+ end
59
+
60
+ #task :test => :check_dependencies
61
+
62
+ task :default => :test
63
+
64
+ require 'rake/rdoctask'
65
+ Rake::RDocTask.new do |rdoc|
66
+ rdoc.rdoc_dir = 'rdoc'
67
+ rdoc.title = "rpm_contrib #{version}"
68
+ rdoc.main = "README.md"
69
+ rdoc.rdoc_files = FileList['lib/**/*.rb'] + RDOC_FILES
70
+ rdoc.inline_source = true
71
+ end
72
+
73
+ begin
74
+ require 'sdoc_helpers'
75
+ rescue LoadError
76
+ puts "sdoc support not enabled. Please gem install sdoc-helpers."
77
+ end
@@ -0,0 +1,14 @@
1
+ require 'new_relic/control/ruby'
2
+ # This is the framework control object for Camping apps.
3
+ # It is loaded by virtue of detecting 'camping' as the framework
4
+ # in the rpm_contrib/detection/camping.rb file. It gets loaded
5
+ # by the new_relic/control.rb file.
6
+ class NewRelic::Control #:nodoc:
7
+ class Camping < NewRelic::Control::Ruby
8
+ def init_config(options)
9
+ super
10
+ @local_env.dispatcher = 'camping'
11
+ self['app_name'] ||= 'Camping Application'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ module NewRelic #:nodoc:
2
+ # The class defined in the
3
+ # newrelic_rpm[http://newrelic.github.com/rpm] which can be ammended
4
+ # to support new frameworks by defining modules in this namespace.
5
+ class LocalEnvironment #:nodoc:
6
+ module Camping
7
+ def discover_framework
8
+ if defined?(::Camping)
9
+ puts "framework is camping"
10
+ @framework = 'camping'
11
+ else
12
+ super
13
+ end
14
+ end
15
+ def discover_dispatcher
16
+ super
17
+ if defined?(::Camping) && @dispatcher.nil?
18
+ @dispatcher = 'camping'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,15 @@
1
+ # Detect when running under camping and set the framework and dispatcher.
2
+
3
+ module NewRelic
4
+ class LocalEnvironment
5
+ module Resque
6
+ def discover_dispatcher
7
+ super
8
+ if defined?(::Resque::Worker) && @dispatcher.nil?
9
+ @dispatcher = 'resque'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,56 @@
1
+ # Instrumentation for the AWS-S3 gem for New Relic RPM by Brian Doll
2
+ if defined?(::AWS::S3) && !NewRelic::Control.instance['disable_aws-s3']
3
+
4
+ # Instrument connections to the AWS-S3 service
5
+ ::AWS::S3::Connection::Management::ClassMethods.module_eval do
6
+ add_method_tracer :establish_connection!, 'AWS-S3/establish_connection!'
7
+ end
8
+
9
+ # Instrument methods on Bucket
10
+ ::AWS::S3::Bucket.instance_eval do
11
+ class << self
12
+ add_method_tracer :create, 'AWS-S3/Bucket/create'
13
+ add_method_tracer :find, 'AWS-S3/Bucket/find'
14
+ add_method_tracer :objects, 'AWS-S3/Bucket/objects'
15
+ add_method_tracer :delete, 'AWS-S3/Bucket/delete'
16
+ add_method_tracer :list, 'AWS-S3/Bucket/list'
17
+ end
18
+ end
19
+
20
+ # Instrument methods on Bucket instances
21
+ ::AWS::S3::Bucket.class_eval do
22
+ add_method_tracer :[], 'AWS-S3/Bucket/#{self.name}/[]'
23
+ add_method_tracer :new_object,'AWS-S3/Bucket/#{self.name}/new_objects'
24
+ add_method_tracer :objects, 'AWS-S3/Bucket/#{self.name}/objects'
25
+ add_method_tracer :delete, 'AWS-S3/Bucket/#{self.name}/delete'
26
+ add_method_tracer :delete_all,'AWS-S3/Bucket/#{self.name}/delete_all'
27
+ add_method_tracer :update, 'AWS-S3/Bucket/#{self.name}/update'
28
+ end
29
+
30
+ # Instrument methods on S3Object
31
+ ::AWS::S3::S3Object.instance_eval do
32
+ class << self
33
+ add_method_tracer :about, 'AWS-S3/S3Object/about'
34
+ add_method_tracer :copy, 'AWS-S3/S3Object/copy'
35
+ add_method_tracer :delete, 'AWS-S3/S3Object/delete'
36
+ add_method_tracer :rename, 'AWS-S3/S3Object/rename'
37
+ add_method_tracer :store, 'AWS-S3/S3Object/store'
38
+ end
39
+ end
40
+
41
+ # Instrument methods on S3Object instances
42
+ # Metric names are aggregated across all S3Objects since having a metric for
43
+ # every single S3Object instance and method pair would be fairly useless
44
+ ::AWS::S3::S3Object.class_eval do
45
+ add_method_tracer :value, 'AWS-S3/S3Objects/value'
46
+ add_method_tracer :about, 'AWS-S3/S3Objects/about'
47
+ add_method_tracer :metadata, 'AWS-S3/S3Objects/metadata'
48
+ add_method_tracer :store, 'AWS-S3/S3Objects/store'
49
+ add_method_tracer :delete, 'AWS-S3/S3Objects/delete'
50
+ add_method_tracer :copy, 'AWS-S3/S3Objects/copy'
51
+ add_method_tracer :rename, 'AWS-S3/S3Objects/rename'
52
+ add_method_tracer :etag, 'AWS-S3/S3Objects/etag'
53
+ add_method_tracer :owner, 'AWS-S3/S3Objects/owner'
54
+ end
55
+
56
+ end
@@ -0,0 +1,53 @@
1
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
2
+
3
+ module RPMContrib
4
+ module Instrumentation
5
+ # == Instrumentation for Camping
6
+ # To instrument all controllers do the following:
7
+ # 1. Add require 'rpm_contrib' after loading camping.
8
+ # 2. Add an include at the end of your main Camping app module
9
+ # 3. Run the following command to get the NewRelic license key to use: heroku config -all
10
+ # 4. Create a newrelic.yml under the /config folder with the following content:
11
+ #
12
+ # common: &default_settings
13
+ # license_key: 'PASTE THE VALUE OF NEW_RELIC_LICENSE_KEY HERE'
14
+ # app_name: PASTE THE NAME OF YOUR CAMPING APP HERE
15
+ # monitor_mode: true
16
+ #
17
+ # production:
18
+ # <<: *default_settings
19
+ #
20
+ # Camping code example:
21
+ # -------------------------------------------------------------------------------------
22
+ #
23
+ # require "newrelic_rpm"
24
+ #
25
+ # Camping.goes :NewRelicCampingTest
26
+ #
27
+ # module NewRelicCampingTest
28
+ # # your code
29
+ #
30
+ # include NewRelic::Agent::Instrumentation::Camping
31
+ #
32
+ # end
33
+ #
34
+ #
35
+
36
+ module Camping
37
+
38
+ def self.included(mod)
39
+
40
+ # Since the Camping::Base module is essentially copied
41
+ # into the main module (the mod passed in) of a Camping app
42
+ # using the Camping.goes :NewRelicCampingTest syntax
43
+ # we need to evaluate "weld" the NewRelic plugin in the context of the new Base
44
+
45
+ (Kernel.const_get(mod.name)::Base).module_eval do
46
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
47
+ add_transaction_tracer :service
48
+ end
49
+ end
50
+
51
+ end #RPMContrib::Instrumentation::Camping
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ # == Cassandra Instrumentation
2
+ #
3
+
4
+ if defined?(::Cassandra) and not NewRelic::Control.instance['disable_cassandra_instrumentation']
5
+
6
+ ::Cassandra.class_eval do
7
+ add_method_tracer :insert, 'Database/Cassandra/insert'
8
+ add_method_tracer :remove, 'Database/Cassandra/remove'
9
+ add_method_tracer :clear_column_family!, 'Database/Cassandra/clear_column_family!'
10
+ add_method_tracer :clear_keyspace!, 'Database/Cassandra/clear_keyspace!'
11
+ add_method_tracer :count_columns, 'Database/Cassandra/count_columns'
12
+ add_method_tracer :multi_count_columns, 'Database/Cassandra/multi_count_columns'
13
+ add_method_tracer :get_columns, 'Database/Cassandra/get_columns'
14
+ add_method_tracer :multi_get_columns, 'Database/Cassandra/multi_get_columns'
15
+ add_method_tracer :get, 'Database/Cassandra/get'
16
+ add_method_tracer :multi_get, 'Database/Cassandra/multi_get'
17
+ add_method_tracer :exists?, 'Database/Cassandra/exists?'
18
+ add_method_tracer :get_range, 'Database/Cassandra/get_range'
19
+ add_method_tracer :count_range, 'Database/Cassandra/count_range'
20
+ add_method_tracer :batch, 'Database/Cassandra/batch'
21
+ end
22
+
23
+ end
@@ -0,0 +1,44 @@
1
+ if defined?(::MongoMapper) && !NewRelic::Control.instance['disable_mongodb']
2
+
3
+ module RPMContrib::Instrumentation
4
+ # Just drop this little diddy in your app to get some (not perfect) information
5
+ # on query times and such.
6
+ #
7
+ # Currently only MongoMapper is implemented
8
+ module MongoMapper
9
+ def self.included(model)
10
+ model.class_eval do
11
+ class << self
12
+ add_method_tracer :find, 'Database/#{self.name}/find'
13
+ add_method_tracer :find!, 'Database/#{self.name}/find!'
14
+ add_method_tracer :paginate, 'Database/#{self.name}/paginate'
15
+ add_method_tracer :first, 'Database/#{self.name}/first'
16
+ add_method_tracer :last, 'Database/#{self.name}/last'
17
+ add_method_tracer :all, 'Database/#{self.name}/all'
18
+ add_method_tracer :count, 'Database/#{self.name}/count'
19
+ add_method_tracer :create, 'Database/#{self.name}/create'
20
+ add_method_tracer :create!, 'Database/#{self.name}/create!'
21
+ add_method_tracer :update, 'Database/#{self.name}/update'
22
+ add_method_tracer :delete, 'Database/#{self.name}/delete'
23
+ add_method_tracer :delete_all, 'Database/#{self.name}/delete_all'
24
+ add_method_tracer :destroy, 'Database/#{self.name}/destroy'
25
+ add_method_tracer :destroy_all, 'Database/#{self.name}/destroy_all'
26
+ add_method_tracer :exists?, 'Database/#{self.name}/exists?'
27
+ add_method_tracer :find_by_id, 'Database/#{self.name}/find_by_id'
28
+ add_method_tracer :increment, 'Database/#{self.name}/increment'
29
+ add_method_tracer :decrement, 'Database/#{self.name}/decrement'
30
+ add_method_tracer :set, 'Database/#{self.name}/set'
31
+ add_method_tracer :push, 'Database/#{self.name}/push'
32
+ add_method_tracer :push_all, 'Database/#{self.name}/push_all'
33
+ add_method_tracer :push_uniq, 'Database/#{self.name}/push_uniq'
34
+ add_method_tracer :pull, 'Database/#{self.name}/pull'
35
+ add_method_tracer :pull_all, 'Database/#{self.name}/pull_all'
36
+ end
37
+
38
+ add_method_tracer :save, 'Database/#{self.class.name}/save'
39
+ end
40
+ end
41
+ end
42
+ ::MongoMapper::Document.append_inclusions(::RPMContrib::Instrumentation::MongoMapper)
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ if defined?(::Mongoid) && !NewRelic::Control.instance['disable_mongodb']
2
+
3
+ module Mongoid #:nodoc:
4
+ module Document
5
+
6
+ #adding call to super
7
+ class << self
8
+ alias :old_included :included
9
+
10
+ def included(model)
11
+ old_included(model)
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ module RPMContrib::Instrumentation
19
+
20
+ module Mongoid
21
+ def included(model)
22
+ model.class_eval do
23
+ class << self
24
+ add_method_tracer :create, 'Database/#{self.name}/create'
25
+ add_method_tracer :create!, 'Database/#{self.name}/create!'
26
+ add_method_tracer :delete_all, 'Database/#{self.name}/delete_all'
27
+ add_method_tracer :destroy_all, 'Database/#{self.name}/destroy_all'
28
+ add_method_tracer :all, 'Database/#{self.name}/all'
29
+ add_method_tracer :find, 'Database/#{self.name}/find'
30
+ add_method_tracer :first, 'Database/#{self.name}/first'
31
+ add_method_tracer :last, 'Database/#{self.name}/last'
32
+ add_method_tracer :find_or_create_by, 'Database/#{self.name}/find_or_create_by'
33
+ add_method_tracer :find_or_initialize_by, 'Database/#{self.name}/find_or_initialize_by'
34
+ add_method_tracer :min, 'Database/#{self.name}/min'
35
+ add_method_tracer :max, 'Database/#{self.name}/max'
36
+ add_method_tracer :sum, 'Database/#{self.name}/sum'
37
+ end
38
+
39
+ add_method_tracer :update_attributes, 'Database/#{self.class.name}/update_attributes'
40
+ add_method_tracer :update_attributes!, 'Database/#{self.class.name}/update_attributes!'
41
+ add_method_tracer :save, 'Database/#{self.class.name}/save'
42
+ add_method_tracer :save!, 'Database/#{self.class.name}/save!'
43
+ add_method_tracer :delete, 'Database/#{self.class.name}/delete'
44
+ add_method_tracer :destroy, 'Database/#{self.class.name}/destroy'
45
+ end
46
+ super
47
+ end
48
+ end
49
+ ::Mongoid::Document.extend(RPMContrib::Instrumentation::Mongoid)
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ # Paperclip Instrumentation.
2
+
3
+ if defined?(::Paperclip) && !NewRelic::Control.instance['disable_paperclip']
4
+
5
+ ::Paperclip::Attachment.class_eval do
6
+ add_method_tracer :save, 'Paperclip/#{name}/save'
7
+ add_method_tracer :assign, 'Paperclip/#{name}/assign'
8
+ add_method_tracer :post_process, 'Paperclip/#{name}/post_process'
9
+ end
10
+
11
+ ::Paperclip::Storage::Filesystem.class_eval do
12
+ add_method_tracer :flush_deletes, 'Paperclip/Storage/flush_deletes'
13
+ add_method_tracer :flush_writes, 'Paperclip/Storage/flush_writes'
14
+ end
15
+
16
+ ::Paperclip::Storage::S3.class_eval do
17
+ add_method_tracer :flush_deletes, 'Paperclip/Storage/flush_deletes'
18
+ add_method_tracer :flush_writes, 'Paperclip/Storage/flush_writes'
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,33 @@
1
+ # Redis instrumentation contributed by Ashley Martens of ngmoco
2
+ #
3
+
4
+ if defined?(::Redis) and not NewRelic::Control.instance['disable_redis']
5
+
6
+
7
+ Redis::Client.class_eval do
8
+
9
+ include NewRelic::Agent::MethodTracer
10
+
11
+ def self.redis_call_method
12
+ Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
13
+ end
14
+
15
+
16
+ def raw_call_command_with_newrelic_trace *args
17
+ method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
18
+ metrics = ["Database/Redis/#{method_name}",
19
+ (NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction? ? 'Database/Redis/allWeb' : 'Database/Redis/allOther')]
20
+ self.class.trace_execution_scoped(metrics) do
21
+ # NewRelic::Control.instance.log.debug("Instrumenting Redis Call[#{method_name}]: #{args[0].inspect}")
22
+ raw_call_command_without_newrelic_trace(*args)
23
+ end
24
+ end
25
+
26
+ alias_method :raw_call_command_without_newrelic_trace, redis_call_method
27
+ alias_method redis_call_method, :raw_call_command_with_newrelic_trace
28
+
29
+ end
30
+
31
+
32
+
33
+ end
@@ -0,0 +1,34 @@
1
+
2
+ module RPMContrib
3
+ module Instrumentation
4
+ # == Resque Instrumentation
5
+ #
6
+ # Installs a hook to ensure the agent starts manually when the worker
7
+ # starts and also adds the tracer to the process method which executes
8
+ # in the forked task.
9
+ module ResqueInstrumentation
10
+ ::Resque::Job.class_eval do
11
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
12
+
13
+ old_perform_method = instance_method(:perform)
14
+
15
+ define_method(:perform) do
16
+ class_name = (payload_class ||self.class).name
17
+ NewRelic::Agent.reset_stats if NewRelic::Agent.respond_to? :reset_stats
18
+ perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name,
19
+ :category => 'OtherTransaction/ResqueJob') do
20
+ old_perform_method.bind(self).call
21
+ end
22
+
23
+ NewRelic::Agent.shutdown unless defined?(::Resque.before_child_exit)
24
+ end
25
+ end
26
+
27
+ if defined?(::Resque.before_child_exit)
28
+ ::Resque.before_child_exit do |worker|
29
+ NewRelic::Agent.shutdown
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end if defined?(::Resque::Job) and not NewRelic::Control.instance['disable_resque']
@@ -0,0 +1,43 @@
1
+ RPM_CONTRIB_LIB = File.dirname(__FILE__)
2
+
3
+ module RPMContrib
4
+ VERSION = File.read(RPM_CONTRIB_LIB+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1]
5
+
6
+ def self.init_sequence
7
+ Proc.new do
8
+ # Tell the agent to load all the files in the
9
+ # rpm_contrib/instrumentation directory.
10
+ NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb")
11
+
12
+ # Load all the Sampler class definitions. These will register
13
+ # automatically with the agent.
14
+ Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file }
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ # Perform any framework/dispatcher detection before loading the rpm gem.
21
+ raise "The rpm_contrib gem must be loaded before the newrelic_rpm gem." if defined?(::NewRelic)
22
+
23
+ Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/detection/**/*.rb") { |file| require file }
24
+
25
+ require 'newrelic_rpm'
26
+
27
+ if defined? Rails
28
+ # Rails 3.x+
29
+ if Rails.respond_to?(:version) && Rails.version =~ /^3/
30
+ module NewRelic
31
+ class Railtie < Rails::Railtie
32
+ initializer("rpm_contrib.start_plugin", &RPMContrib.init_sequence)
33
+ end
34
+ end
35
+ # Rails 2.x
36
+ elsif defined?(Rails) && Rails.respond_to?(:configuration)
37
+ Rails.configuration.after_initialize &RPMContrib.init_sequence
38
+ else
39
+ raise "The rpm_contrib gem supports Rails 2.2+ only."
40
+ end
41
+ else
42
+ RPMContrib.init_sequence.call
43
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ require File.expand_path("../../lib/rpm_contrib.rb", __FILE__)
8
+
9
+ require 'schema.rb'
data/test/schema.rb ADDED
@@ -0,0 +1,19 @@
1
+ # Use this file to add tables you need to do testing
2
+ # These are created in a sqllite memory DB
3
+
4
+ begin
5
+ require 'sqlite3'
6
+ require 'active_record'
7
+
8
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
9
+ ActiveRecord::Migration.verbose = false
10
+
11
+ ActiveRecord::Schema.define do
12
+
13
+ create_table :stories, :force => true do |table|
14
+ table.string :text
15
+ end
16
+ end
17
+ rescue LoadError
18
+ # Skip AR tests
19
+ end
@@ -0,0 +1,42 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+ begin
3
+ require 'mongoid'
4
+ rescue LoadError
5
+ end
6
+
7
+ require "#{File.dirname(__FILE__)}/../lib/rpm_contrib/instrumentation/mongoid"
8
+
9
+ if defined?(::Mongoid)
10
+
11
+ Mongoid.configure do |config|
12
+ config.master = Mongo::Connection.new.db('animals')
13
+ end
14
+
15
+ class Dog
16
+ include Mongoid::Document
17
+
18
+ field :name
19
+ end
20
+
21
+ class MongoidTest < Test::Unit::TestCase
22
+
23
+ # Called before every test method runs. Can be used
24
+ # to set up fixture information.
25
+ def setup
26
+ # Do nothing
27
+ end
28
+
29
+ # Called after every test method runs. Can be used to tear
30
+ # down fixture information.
31
+
32
+ def teardown
33
+ # Do nothing
34
+ end
35
+
36
+ # Fake test
37
+ def test_fail
38
+ Dog.create!(:name=>'rover')
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,34 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+ begin
3
+ require 'redis'
4
+ require 'ruby-debug'
5
+ rescue LoadError
6
+ end
7
+
8
+ require "#{File.dirname(__FILE__)}/../lib/rpm_contrib/instrumentation/redis"
9
+
10
+ if defined?(::Redis)
11
+
12
+
13
+ class RedisTest < Test::Unit::TestCase
14
+
15
+ # Called before every test method runs. Can be used
16
+ # to set up fixture information.
17
+ def setup
18
+ # Do nothing
19
+ end
20
+
21
+ # Called after every test method runs. Can be used to tear
22
+ # down fixture information.
23
+
24
+ def teardown
25
+ # Do nothing
26
+ end
27
+
28
+ # Fake test
29
+ def test_fail
30
+
31
+
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghazel-rpm_contrib
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.13.1
5
+ platform: ruby
6
+ authors:
7
+ - Bill Kayser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-09-23 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newrelic_rpm
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.13.1
24
+ version:
25
+ description: |
26
+ Community contributed instrumentation for various frameworks based on
27
+ the New Relic Ruby monitoring gem newrelic_rpm.
28
+
29
+ email: support@newrelic.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - CHANGELOG
36
+ - LICENSE
37
+ - README.md
38
+ files:
39
+ - CHANGELOG
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/new_relic/control/camping.rb
44
+ - lib/rpm_contrib.rb
45
+ - lib/rpm_contrib/detection/camping.rb
46
+ - lib/rpm_contrib/detection/resque.rb
47
+ - lib/rpm_contrib/instrumentation/aws/s3.rb
48
+ - lib/rpm_contrib/instrumentation/camping.rb
49
+ - lib/rpm_contrib/instrumentation/cassandra.rb
50
+ - lib/rpm_contrib/instrumentation/mongo_mapper.rb
51
+ - lib/rpm_contrib/instrumentation/mongoid.rb
52
+ - lib/rpm_contrib/instrumentation/paperclip.rb
53
+ - lib/rpm_contrib/instrumentation/redis.rb
54
+ - lib/rpm_contrib/instrumentation/resque.rb
55
+ - test/helper.rb
56
+ - test/schema.rb
57
+ - test/test_mongoid.rb
58
+ - test/test_redis.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/newrelic/rpm_contrib
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ - --line-numbers
67
+ - --inline-source
68
+ - --title
69
+ - Contributed Instrumentation for New Relic RPM
70
+ - -m
71
+ - README.md
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.5
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Contributed Instrumentation for New Relic RPM
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/schema.rb
96
+ - test/test_mongoid.rb
97
+ - test/test_redis.rb