rpm_contrib 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/new_relic/control/camping.rb +12 -0
- data/lib/rpm_contrib.rb +23 -15
- data/lib/rpm_contrib/detection/camping.rb +23 -0
- data/lib/rpm_contrib/instrumentation/camping.rb +17 -38
- data/test/helper.rb +3 -0
- data/test/schema.rb +19 -0
- data/test/test_rpm_contrib.rb +1 -1
- metadata +25 -14
- data/lib/rpm_contrib/instrumentation/delayed_job_instrumentation.rb +0 -45
- data/lib/rpm_contrib/samplers/delayed_job_lock_sampler.rb +0 -28
- data/test/delayed_job_instrumentation/delayed_job_test.rb +0 -108
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ begin
|
|
18
18
|
gem.email = "support@newrelic.com"
|
19
19
|
gem.homepage = "http://github.com/newrelic/rpm_contrib"
|
20
20
|
gem.author = "Bill Kayser"
|
21
|
-
gem.add_dependency 'newrelic_rpm', '>= 2.10.
|
21
|
+
gem.add_dependency 'newrelic_rpm', '>= 2.10.6'
|
22
22
|
gem.version = version
|
23
23
|
gem.files = FileList['LICENSE', 'README*', 'lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
|
24
24
|
end
|
@@ -0,0 +1,12 @@
|
|
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::Camping < NewRelic::Control::Ruby
|
7
|
+
def init_config(options)
|
8
|
+
super
|
9
|
+
@local_env.dispatcher = 'camping'
|
10
|
+
self['app_name'] ||= 'Camping Application'
|
11
|
+
end
|
12
|
+
end
|
data/lib/rpm_contrib.rb
CHANGED
@@ -1,17 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
|
2
|
+
RPM_CONTRIB_LIB = File.dirname(__FILE__)
|
3
|
+
|
4
4
|
module RPMContrib
|
5
|
-
|
6
|
-
lib_root = File.dirname(__FILE__)
|
7
|
-
|
8
|
-
# Tell the agent to load all the files in the rpm_contrib/instrumentation directory.
|
9
|
-
|
10
|
-
NewRelic::Agent.add_instrumentation(lib_root+"/rpm_contrib/instrumentation/**/*.rb")
|
11
|
-
|
12
|
-
# Load all the Sampler class definitions. These will register
|
13
|
-
# automatically with the agent.
|
14
|
-
Dir.glob(lib_root + "/rpm_contrib/samplers/**/*.rb") { |file| require file }
|
15
|
-
|
16
|
-
VERSION = File.read(lib_root+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1]
|
5
|
+
VERSION = File.read(RPM_CONTRIB_LIB+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1]
|
17
6
|
end
|
7
|
+
|
8
|
+
|
9
|
+
# Perform any framework/dispatcher detection before loading the rpm
|
10
|
+
# gem.
|
11
|
+
|
12
|
+
raise "The rpm_contrib gem must be loaded before the newrelic_rpm gem." if defined?(::NewRelic)
|
13
|
+
|
14
|
+
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/detection/**/*.rb") { |file| require file }
|
15
|
+
|
16
|
+
require 'newrelic_rpm'
|
17
|
+
|
18
|
+
# Tell the agent to load all the files in the rpm_contrib/instrumentation directory.
|
19
|
+
|
20
|
+
NewRelic::Agent.add_instrumentation(RPM_CONTRIB_LIB+"/rpm_contrib/instrumentation/**/*.rb")
|
21
|
+
|
22
|
+
# Load all the Sampler class definitions. These will register
|
23
|
+
# automatically with the agent.
|
24
|
+
Dir.glob(RPM_CONTRIB_LIB + "/rpm_contrib/samplers/**/*.rb") { |file| require file }
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Detect when running under camping and set the framework and dispatcher.
|
2
|
+
|
3
|
+
module NewRelic
|
4
|
+
class LocalEnvironment
|
5
|
+
module Camping
|
6
|
+
def discover_framework
|
7
|
+
if defined?(::Camping)
|
8
|
+
puts "framework is camping"
|
9
|
+
@framework = 'camping'
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def discover_dispatcher
|
15
|
+
super
|
16
|
+
if defined?(::Camping) && @dispatcher.nil?
|
17
|
+
@dispatcher = 'camping'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -4,39 +4,33 @@ module RPMContrib
|
|
4
4
|
module Instrumentation
|
5
5
|
# == Instrumentation for Camping
|
6
6
|
# To instrument all controllers do the following:
|
7
|
-
# 1. Add
|
7
|
+
# 1. Add require 'rpm_contrib' after loading camping.
|
8
8
|
# 2. Add an include at the end of your main Camping app module
|
9
|
-
# 3.
|
10
|
-
# 4.
|
11
|
-
# 5. Create a newrelic.yml under the /config folder with the following content:
|
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:
|
12
11
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# enabled: true
|
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
|
18
16
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
17
|
+
# production:
|
18
|
+
# <<: *default_settings
|
19
|
+
#
|
20
|
+
# Camping code example:
|
21
|
+
# -------------------------------------------------------------------------------------
|
22
22
|
#
|
23
|
-
# Camping code example:
|
24
|
-
# --------------------------------------------------------------------------------------
|
25
23
|
# require "newrelic_rpm"
|
26
|
-
# require 'new_relic/agent/agent'
|
27
|
-
# require 'new_relic/agent/instrumentation/controller_instrumentation'
|
28
|
-
# require 'new_relic/agent/instrumentation/camping'
|
29
24
|
#
|
30
25
|
# Camping.goes :NewRelicCampingTest
|
31
26
|
#
|
32
27
|
# module NewRelicCampingTest
|
33
|
-
#
|
28
|
+
# # your code
|
29
|
+
#
|
30
|
+
# include NewRelic::Agent::Instrumentation::Camping
|
34
31
|
#
|
35
|
-
# include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
36
|
-
# include NewRelic::Agent::Instrumentation::Camping
|
37
32
|
# end
|
38
33
|
#
|
39
|
-
# NewRelic::Agent.manual_start
|
40
34
|
#
|
41
35
|
|
42
36
|
module Camping
|
@@ -49,23 +43,8 @@ module RPMContrib
|
|
49
43
|
# we need to evaluate "weld" the NewRelic plugin in the context of the new Base
|
50
44
|
|
51
45
|
(Kernel.const_get(mod.name)::Base).module_eval do
|
52
|
-
|
53
|
-
|
54
|
-
# since the Camping::Base module is being included
|
55
|
-
# in every Camping controller
|
56
|
-
|
57
|
-
def service_with_newrelic(*args)
|
58
|
-
perform_action_with_newrelic_trace(:category => :rack) do
|
59
|
-
service_without_newrelic(*args)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Alias the "standard" service method
|
64
|
-
# so we can provide a level of indirection
|
65
|
-
# to perform the tracing for NewRelic
|
66
|
-
|
67
|
-
alias service_without_newrelic service
|
68
|
-
alias service service_with_newrelic
|
46
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
47
|
+
add_transaction_tracer :service
|
69
48
|
end
|
70
49
|
end
|
71
50
|
|
data/test/helper.rb
CHANGED
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
|
data/test/test_rpm_contrib.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpm_contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Bill Kayser
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-05 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: newrelic_rpm
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 10
|
30
|
+
- 6
|
31
|
+
version: 2.10.6
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
description: " Community contributed instrumentation for various frameworks based on\n the New Relic Ruby monitoring gem newrelic_rpm.\n"
|
26
35
|
email: support@newrelic.com
|
27
36
|
executables: []
|
@@ -36,14 +45,14 @@ files:
|
|
36
45
|
- LICENSE
|
37
46
|
- README.md
|
38
47
|
- Rakefile
|
48
|
+
- lib/new_relic/control/camping.rb
|
39
49
|
- lib/rpm_contrib.rb
|
50
|
+
- lib/rpm_contrib/detection/camping.rb
|
40
51
|
- lib/rpm_contrib/instrumentation/authlogic.rb
|
41
52
|
- lib/rpm_contrib/instrumentation/camping.rb
|
42
|
-
- lib/rpm_contrib/instrumentation/delayed_job_instrumentation.rb
|
43
53
|
- lib/rpm_contrib/instrumentation/paperclip.rb
|
44
|
-
- lib/rpm_contrib/samplers/delayed_job_lock_sampler.rb
|
45
|
-
- test/delayed_job_instrumentation/delayed_job_test.rb
|
46
54
|
- test/helper.rb
|
55
|
+
- test/schema.rb
|
47
56
|
- test/test_rpm_contrib.rb
|
48
57
|
has_rdoc: true
|
49
58
|
homepage: http://github.com/newrelic/rpm_contrib
|
@@ -58,22 +67,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
67
|
requirements:
|
59
68
|
- - ">="
|
60
69
|
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
61
72
|
version: "0"
|
62
|
-
version:
|
63
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
74
|
requirements:
|
65
75
|
- - ">="
|
66
76
|
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
67
79
|
version: "0"
|
68
|
-
version:
|
69
80
|
requirements: []
|
70
81
|
|
71
82
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.6
|
73
84
|
signing_key:
|
74
85
|
specification_version: 3
|
75
86
|
summary: Contributed Instrumentation for New Relic RPM
|
76
87
|
test_files:
|
77
|
-
- test/delayed_job_instrumentation/delayed_job_test.rb
|
78
88
|
- test/helper.rb
|
89
|
+
- test/schema.rb
|
79
90
|
- test/test_rpm_contrib.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module RPMContrib::Instrumentation::DelayedJobInstrumentation
|
2
|
-
extend self
|
3
|
-
Delayed::Job.class_eval do
|
4
|
-
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
5
|
-
if self.instance_methods.include?('name')
|
6
|
-
add_transaction_tracer "invoke_job", :category => :task, :name => '#{self.name}'
|
7
|
-
else
|
8
|
-
add_transaction_tracer "invoke_job", :category => :task
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Delayed::Worker.class_eval do
|
13
|
-
def initialize_with_new_relic(*args)
|
14
|
-
initialize_without_new_relic(*args)
|
15
|
-
NewRelic::.delayed_worker = self
|
16
|
-
end
|
17
|
-
|
18
|
-
alias initialize_without_new_relic initialize
|
19
|
-
alias initialize initialize_with_new_relic
|
20
|
-
end
|
21
|
-
|
22
|
-
def delayed_worker=(w)
|
23
|
-
@delayed_worker = w
|
24
|
-
env = NewRelic::Control.instance.local_env
|
25
|
-
env.dispatcher = :delayed_job
|
26
|
-
env.dispatcher_instance_id = case
|
27
|
-
when @delayed_worker.respond_to?(:name)
|
28
|
-
@delayed_worker.name
|
29
|
-
when @delayed_worker.class.respond_to?(:default_name)
|
30
|
-
@delayed_worker.class.default_name
|
31
|
-
else
|
32
|
-
"host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
|
33
|
-
end
|
34
|
-
|
35
|
-
env.append_environment_value 'Dispatcher', @dispatcher.to_s
|
36
|
-
env.append_environment_value 'Dispatcher instance id', @dispatcher_instance_id
|
37
|
-
|
38
|
-
@delayed_worker
|
39
|
-
end
|
40
|
-
|
41
|
-
def delayed_worker
|
42
|
-
@delayed_worker
|
43
|
-
end
|
44
|
-
|
45
|
-
end if defined?(Delayed::Job)
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module NewRelic::Agent::Samplers
|
2
|
-
class DelayedJobLockSampler < NewRelic::Agent::Sampler
|
3
|
-
def initialize
|
4
|
-
super :delayed_job_lock
|
5
|
-
raise Unsupported, "No delayed job workers running" unless Instrumentation::DelayedJobInstrumentation.delayed_worker
|
6
|
-
end
|
7
|
-
|
8
|
-
def stats
|
9
|
-
stats_engine.get_stats("DJ/Locked Jobs", false)
|
10
|
-
end
|
11
|
-
|
12
|
-
def local_env
|
13
|
-
NewRelic::Control.instance.local_env
|
14
|
-
end
|
15
|
-
|
16
|
-
def worker_name
|
17
|
-
local_env.dispatcher_instance_id
|
18
|
-
end
|
19
|
-
|
20
|
-
def locked_jobs
|
21
|
-
Delayed::Job.count(:conditions => {:locked_by => worker_name})
|
22
|
-
end
|
23
|
-
|
24
|
-
def poll
|
25
|
-
stats.record_data_point locked_jobs
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module DelayedJobInstrumentation
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
|
3
|
-
|
4
|
-
class LongRunningJob
|
5
|
-
def perform
|
6
|
-
sleep 5
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class NamedJob
|
11
|
-
def display_name
|
12
|
-
'some custom name'
|
13
|
-
end
|
14
|
-
def perform
|
15
|
-
true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class DelayedJobTest < Test::Unit::TestCase
|
20
|
-
def local_env
|
21
|
-
NewRelic::Control.instance.local_env
|
22
|
-
end
|
23
|
-
|
24
|
-
def worker_name
|
25
|
-
local_env.dispatcher_instance_id
|
26
|
-
end
|
27
|
-
|
28
|
-
def lock_n_jobs(n=1)
|
29
|
-
n.times do
|
30
|
-
job = Delayed::Job.create
|
31
|
-
job.update_attributes({
|
32
|
-
:locked_at => Time.now,
|
33
|
-
:locked_by => worker_name
|
34
|
-
})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def setup
|
39
|
-
NewRelic::Agent.manual_start
|
40
|
-
@agent = NewRelic::Agent.instance
|
41
|
-
|
42
|
-
@agent.transaction_sampler.harvest
|
43
|
-
@agent.stats_engine.clear_stats
|
44
|
-
end
|
45
|
-
|
46
|
-
def teardown
|
47
|
-
@agent.instance_variable_set("@histogram", NewRelic::Histogram.new)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_job_instrumentation
|
51
|
-
job = Delayed::Job.new(:payload_object => LongRunningJob.new)
|
52
|
-
job_name = "Controller/Task/Delayed::Job/LongRunningJob"
|
53
|
-
|
54
|
-
job.invoke_job
|
55
|
-
job_stats = @agent.stats_engine.get_stats(job_name)
|
56
|
-
|
57
|
-
assert @agent.stats_engine.metrics.include?(job_name)
|
58
|
-
assert_equal 1, job_stats.call_count
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_custom_name
|
62
|
-
job = Delayed::Job.new(:payload_object => NamedJob.new)
|
63
|
-
job_name = "Controller/Task/Delayed::Job/some custom name"
|
64
|
-
|
65
|
-
job.invoke_job
|
66
|
-
job_stats = @agent.stats_engine.get_stats(job_name)
|
67
|
-
|
68
|
-
assert @agent.stats_engine.metrics.include?(job_name)
|
69
|
-
assert_equal 1, job_stats.call_count
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_lock_sampler
|
73
|
-
stats_engine = NewRelic::Agent::StatsEngine.new
|
74
|
-
sampler = NewRelic::Agent::Samplers::DelayedJobLockSampler.new
|
75
|
-
sampler.stats_engine = stats_engine
|
76
|
-
|
77
|
-
lock_n_jobs(1)
|
78
|
-
sampler.poll
|
79
|
-
|
80
|
-
assert_equal 1, sampler.stats.data_point_count
|
81
|
-
assert_equal 1, sampler.stats.min_call_time
|
82
|
-
assert_equal 1, sampler.stats.max_call_time
|
83
|
-
|
84
|
-
lock_n_jobs(4)
|
85
|
-
sampler.poll
|
86
|
-
|
87
|
-
assert_equal 2, sampler.stats.data_point_count
|
88
|
-
assert_equal 1, sampler.stats.min_call_time
|
89
|
-
assert_equal 5, sampler.stats.max_call_time
|
90
|
-
|
91
|
-
lock_n_jobs(5)
|
92
|
-
sampler.poll
|
93
|
-
sampler.poll
|
94
|
-
|
95
|
-
assert_equal 4, sampler.stats.data_point_count
|
96
|
-
assert_equal 1, sampler.stats.min_call_time
|
97
|
-
assert_equal 10, sampler.stats.max_call_time
|
98
|
-
|
99
|
-
Delayed::Job.destroy_all
|
100
|
-
sampler.poll
|
101
|
-
|
102
|
-
assert_equal 5, sampler.stats.data_point_count
|
103
|
-
assert_equal 0, sampler.stats.min_call_time
|
104
|
-
assert_equal 10, sampler.stats.max_call_time
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
end if defined? Delayed::Job
|