Skip to content

Commit

Permalink
Adding in instrumentation, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed Jan 21, 2010
1 parent 3d35021 commit 725bea7
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Version 1.0.0
- Initial Release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009 New Relic
Copyright (c) 2009 New Relic, Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
18 changes: 13 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
require 'rubygems'
require 'rake'
# See http://www.rubygems.org/read/chapter/20

def version
@rpm_contrib_version ||= File.read("CHANGELOG")[/Version ([\d\.]+)$/, 1]
end

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "rpm_contrib"
gem.summary = %Q{Contributed Instrumentation for New Relic RPM}
gem.description = %Q{Community contributed instrumentation for various frameworks based on New Relic Ruby monitoring gem newrelic_rpm.}
gem.description = <<-EOF
Community contributed instrumentation for various frameworks based on
the New Relic Ruby monitoring gem newrelic_rpm.
EOF
gem.email = "support@newrelic.com"
gem.homepage = "http://github.com/newrelic/rpm_contrib"
gem.authors = ["New Relic"]
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
gem.author = "Bill Kayser"
gem.add_dependency 'newrelic_rpm', '>= 2.10.2'
gem.version = version
gem.files = FileList['LICENSE', 'README*', 'lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
end
Jeweler::GemcutterTasks.new
rescue LoadError
Expand Down Expand Up @@ -43,8 +53,6 @@ task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "rpm_contrib #{version}"
rdoc.rdoc_files.include('README*')
Expand Down
8 changes: 8 additions & 0 deletions lib/new_relic/agent/instrumentation/authlogic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if defined? Authlogic::Session::Base
Authlogic::Session::Base.class_eval do
# add_method_tracer :record, 'Authlogic/record'
class << self
add_method_tracer :find, 'Authlogic/find'
end
end
end
45 changes: 45 additions & 0 deletions lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module NewRelic::Agent::Instrumentation::DelayedJobInstrumentation
extend self
Delayed::Job.class_eval do
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
if self.instance_methods.include?('name')
add_transaction_tracer "invoke_job", :category => :task, :name => '#{self.name}'
else
add_transaction_tracer "invoke_job", :category => :task
end
end

Delayed::Worker.class_eval do
def initialize_with_new_relic(*args)
initialize_without_new_relic(*args)
NewRelic::.delayed_worker = self
end

alias initialize_without_new_relic initialize
alias initialize initialize_with_new_relic
end

def delayed_worker=(w)
@delayed_worker = w
env = NewRelic::Control.instance.local_env
env.dispatcher = :delayed_job
env.dispatcher_instance_id = case
when @delayed_worker.respond_to?(:name)
@delayed_worker.name
when @delayed_worker.class.respond_to?(:default_name)
@delayed_worker.class.default_name
else
"host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
end

env.append_environment_value 'Dispatcher', @dispatcher.to_s
env.append_environment_value 'Dispatcher instance id', @dispatcher_instance_id

@delayed_worker
end

def delayed_worker
@delayed_worker
end

end if defined?(Delayed::Job)
28 changes: 28 additions & 0 deletions lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module NewRelic::Agent::Samplers
class DelayedJobLockSampler < NewRelic::Agent::Sampler
def initialize
super :delayed_job_lock
raise Unsupported, "No delayed job workers running" unless Instrumentation::DelayedJobInstrumentation.delayed_worker
end

def stats
stats_engine.get_stats("DJ/Locked Jobs", false)
end

def local_env
NewRelic::Control.instance.local_env
end

def worker_name
local_env.dispatcher_instance_id
end

def locked_jobs
Delayed::Job.count(:conditions => {:locked_by => worker_name})
end

def poll
stats.record_data_point locked_jobs
end
end
end
4 changes: 4 additions & 0 deletions lib/rpm_contrib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'newrelic_rpm'
module RPMContrib
VERSION = File.read(File.dirname(__FILE__)+"/../CHANGELOG")[/Version ([\d\.]+)$/, 1]
end
52 changes: 52 additions & 0 deletions rpm_contrib.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

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

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Bill Kayser"]
s.date = %q{2010-01-20}
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"
]
s.files = [
"LICENSE",
"README.rdoc",
"Rakefile",
"lib/rpm_contrib.rb",
"test/helper.rb",
"test/test_rpm_contrib.rb"
]
s.homepage = %q{http://github.com/newrelic/rpm_contrib}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{Contributed Instrumentation for New Relic RPM}
s.test_files = [
"test/helper.rb",
"test/test_rpm_contrib.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<newrelic_rpm>, [">= 2.10.2"])
else
s.add_dependency(%q<newrelic_rpm>, [">= 2.10.2"])
end
else
s.add_dependency(%q<newrelic_rpm>, [">= 2.10.2"])
end
end

0 comments on commit 725bea7

Please sign in to comment.