newrelic-redis 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/README.txt +58 -0
- data/Rakefile +25 -0
- data/lib/newrelic-redis.rb +1 -0
- data/lib/newrelic_redis/instrumentation.rb +72 -0
- data/lib/newrelic_redis/version.rb +3 -0
- data/newrelic-redis.gemspec +42 -0
- data/test/test_newrelic_redis.rb +58 -0
- metadata +138 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= newrelic-redis
|
2
|
+
|
3
|
+
* http://github.com/evanphx/newrelic-redis
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Redis instrumentation for Newrelic.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Allows transactions to show time spent inside redis requests
|
12
|
+
* Supports normal and pipelined commands
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
Just add the gem to your project!
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
* redis-rb
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
* gem install newrelic-redis
|
25
|
+
|
26
|
+
== DEVELOPERS:
|
27
|
+
|
28
|
+
After checking out the source, run:
|
29
|
+
|
30
|
+
$ rake newb
|
31
|
+
|
32
|
+
This task will install any missing dependencies, run the tests/specs,
|
33
|
+
and generate the RDoc.
|
34
|
+
|
35
|
+
== LICENSE:
|
36
|
+
|
37
|
+
(The MIT License)
|
38
|
+
|
39
|
+
Copyright (c) 2012 Evan Phoenix
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
42
|
+
a copy of this software and associated documentation files (the
|
43
|
+
'Software'), to deal in the Software without restriction, including
|
44
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
45
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
46
|
+
permit persons to whom the Software is furnished to do so, subject to
|
47
|
+
the following conditions:
|
48
|
+
|
49
|
+
The above copyright notice and this permission notice shall be
|
50
|
+
included in all copies or substantial portions of the Software.
|
51
|
+
|
52
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
53
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
54
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
55
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
56
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
57
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
58
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.plugin :bundler
|
7
|
+
Hoe.plugin :gemspec
|
8
|
+
Hoe.plugin :git
|
9
|
+
|
10
|
+
HOE = Hoe.spec 'newrelic-redis' do
|
11
|
+
developer 'Evan Phoenix', 'evan@phx.io'
|
12
|
+
|
13
|
+
dependency "redis", "< 3.0"
|
14
|
+
dependency "newrelic_rpm", "~> 3.0"
|
15
|
+
end
|
16
|
+
|
17
|
+
file "#{HOE.spec.name}.gemspec" => ['Rakefile'] do |t|
|
18
|
+
puts "Generating #{t.name}"
|
19
|
+
File.open(t.name, 'wb') { |f| f.write HOE.spec.to_ruby }
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Generate or update the standalone gemspec file for the project"
|
23
|
+
task :gemspec => ["#{HOE.spec.name}.gemspec"]
|
24
|
+
|
25
|
+
# vim: syntax=ruby
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'newrelic_redis/instrumentation'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'new_relic/agent/method_tracer'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
# Redis instrumentation.
|
5
|
+
# Originally contributed by Ashley Martens of ngmoco
|
6
|
+
# Rewritten, reorganized, and repackaged by Evan Phoenix
|
7
|
+
|
8
|
+
# defined?(::Redis) && !NewRelic::Control.instance['disable_redis']
|
9
|
+
|
10
|
+
NewRelic::Agent.logger.debug 'Installing Redis instrumentation'
|
11
|
+
|
12
|
+
::Redis::Client.class_eval do
|
13
|
+
|
14
|
+
include NewRelic::Agent::MethodTracer
|
15
|
+
|
16
|
+
# Support older versions of Redis::Client that used the method
|
17
|
+
# +raw_call_command+.
|
18
|
+
|
19
|
+
call_method =
|
20
|
+
::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
|
21
|
+
|
22
|
+
def call_with_newrelic_trace(*args)
|
23
|
+
if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
|
24
|
+
total_metric = 'Database/Redis/allWeb'
|
25
|
+
else
|
26
|
+
total_metric = 'Database/Redis/allOther'
|
27
|
+
end
|
28
|
+
|
29
|
+
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
|
30
|
+
metrics = ["Database/Redis/#{method_name.to_s.upcase}", total_metric]
|
31
|
+
|
32
|
+
self.class.trace_execution_scoped(metrics) do
|
33
|
+
call_without_newrelic_trace(*args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :call_without_newrelic_trace, call_method
|
38
|
+
alias_method call_method, :call_with_newrelic_trace
|
39
|
+
|
40
|
+
# Older versions of Redis handle pipelining completely differently.
|
41
|
+
# Don't bother supporting them for now.
|
42
|
+
#
|
43
|
+
if public_method_defined? :call_pipelined
|
44
|
+
def call_pipelined_with_newrelic_trace(commands, options={})
|
45
|
+
if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
|
46
|
+
total_metric = 'Database/Redis/allWeb'
|
47
|
+
else
|
48
|
+
total_metric = 'Database/Redis/allOther'
|
49
|
+
end
|
50
|
+
|
51
|
+
# Report each command as a metric under pipelined, so the user
|
52
|
+
# can at least see what all the commands were. This prevents
|
53
|
+
# metric namespace explosion.
|
54
|
+
|
55
|
+
metrics = [total_metric, "Database/Redis/Pipelined"]
|
56
|
+
|
57
|
+
commands.each do |c|
|
58
|
+
name = c.kind_of?(Array) ? c[0] : c
|
59
|
+
metrics << "Database/Redis/Pipelined/#{name.to_s.upcase}"
|
60
|
+
end
|
61
|
+
|
62
|
+
self.class.trace_execution_scoped(metrics) do
|
63
|
+
call_pipelined_without_newrelic_trace commands, options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
alias_method :call_pipelined_without_newrelic_trace, :call_pipelined
|
69
|
+
alias_method :call_pipelined, :call_pipelined_with_newrelic_trace
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "newrelic-redis"
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Evan Phoenix"]
|
9
|
+
s.date = "2012-03-09"
|
10
|
+
s.description = "Redis instrumentation for Newrelic."
|
11
|
+
s.email = ["evan@phx.io"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
13
|
+
s.files = [".autotest", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/newrelic_redis.rb", "lib/newrelic_redis/instrumentation.rb", "lib/newrelic_redis/version.rb", "test/test_newrelic_redis.rb", ".gemtest"]
|
14
|
+
s.homepage = "http://github.com/evanphx/newrelic-redis"
|
15
|
+
s.rdoc_options = ["--main", "README.txt"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "newrelic-redis"
|
18
|
+
s.rubygems_version = "1.8.17"
|
19
|
+
s.summary = "Redis instrumentation for Newrelic."
|
20
|
+
s.test_files = ["test/test_newrelic_redis.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<redis>, ["< 3.0"])
|
27
|
+
s.add_runtime_dependency(%q<newrelic_rpm>, ["~> 3.0"])
|
28
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
|
29
|
+
s.add_development_dependency(%q<hoe>, ["~> 2.16"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<redis>, ["< 3.0"])
|
32
|
+
s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
|
33
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
34
|
+
s.add_dependency(%q<hoe>, ["~> 2.16"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<redis>, ["< 3.0"])
|
38
|
+
s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
|
39
|
+
s.add_dependency(%q<rdoc>, ["~> 3.10"])
|
40
|
+
s.add_dependency(%q<hoe>, ["~> 2.16"])
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
require 'newrelic_redis/instrumentation'
|
5
|
+
|
6
|
+
class TestNewRelicRedis < Test::Unit::TestCase
|
7
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
8
|
+
|
9
|
+
module StubProcess
|
10
|
+
def establish_connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def read(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def process(*args)
|
17
|
+
@process_args = args
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :process_args
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
NewRelic::Agent.manual_start
|
26
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
27
|
+
@engine.clear_stats
|
28
|
+
|
29
|
+
@redis = Redis.new :path => "/tmp/redis"
|
30
|
+
@client = @redis.client
|
31
|
+
class << @client
|
32
|
+
include StubProcess
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_metrics(*m)
|
37
|
+
assert_equal m.sort, @engine.metrics.sort
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_call
|
41
|
+
@redis.hgetall "foo"
|
42
|
+
assert_equal [[[:hgetall, "foo"]]], @client.process_args
|
43
|
+
assert_metrics "Database/Redis/HGETALL", "Database/Redis/allOther"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_call_pipelined
|
47
|
+
@redis.pipelined do
|
48
|
+
@redis.hgetall "foo"
|
49
|
+
@redis.inc "bar"
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal [[[:hgetall, "foo"], [:inc, "bar"]]], @client.process_args
|
53
|
+
assert_metrics "Database/Redis/Pipelined/HGETALL",
|
54
|
+
"Database/Redis/Pipelined/INC",
|
55
|
+
"Database/Redis/Pipelined",
|
56
|
+
"Database/Redis/allOther"
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Evan Phoenix
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: redis
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - <
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: "3.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: newrelic_rpm
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
version: "3.0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rdoc
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 19
|
59
|
+
segments:
|
60
|
+
- 3
|
61
|
+
- 10
|
62
|
+
version: "3.10"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: hoe
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 35
|
74
|
+
segments:
|
75
|
+
- 2
|
76
|
+
- 16
|
77
|
+
version: "2.16"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
description: Redis instrumentation for Newrelic.
|
81
|
+
email:
|
82
|
+
- evan@phx.io
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- History.txt
|
89
|
+
- Manifest.txt
|
90
|
+
- README.txt
|
91
|
+
files:
|
92
|
+
- .autotest
|
93
|
+
- History.txt
|
94
|
+
- Manifest.txt
|
95
|
+
- README.txt
|
96
|
+
- Rakefile
|
97
|
+
- lib/newrelic-redis.rb
|
98
|
+
- lib/newrelic_redis/instrumentation.rb
|
99
|
+
- lib/newrelic_redis/version.rb
|
100
|
+
- newrelic-redis.gemspec
|
101
|
+
- test/test_newrelic_redis.rb
|
102
|
+
- .gemtest
|
103
|
+
homepage: http://github.com/evanphx/newrelic-redis
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --main
|
109
|
+
- README.txt
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
requirements: []
|
131
|
+
|
132
|
+
rubyforge_project: newrelic-redis
|
133
|
+
rubygems_version: 1.8.17
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Redis instrumentation for Newrelic.
|
137
|
+
test_files:
|
138
|
+
- test/test_newrelic_redis.rb
|