metro_relic 0.0.1
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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/lib/metro_relic.rb +94 -0
- data/lib/metro_relic/version.rb +3 -0
- data/metro_relic.gemspec +27 -0
- data/spec/fixtures/metro.config +2 -0
- data/spec/lib/metro_relic_spec.rb +33 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzY5YTY3Y2M1N2YyMWQ0MzU1M2EwNDdkYzA1YTJhN2FhMDliMDIzNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmVmYTdlM2U0MGYyZDU4NTJhNTk2Y2Y5YWYwYmU2NTEzNjMxZmNkZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NGJmNzg5NzdkMGFhODI1NjQ3Y2Y1NDAyZDY0ZWM2NThlYTcxZjBhZjcwNTU4
|
10
|
+
Mjc4ZjVmNjVkOTZlZThmNjFjYTg5OGU0NjRhY2E3N2Q5OGYyYTczOGUyMmU1
|
11
|
+
N2ExNDQ5YjRkODVlNjU3YjliYjliODM0Zjg5Nzg0YTY0NmJjODA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzgwOWEwNzhhYzg4MTUzMTE3NTYyMzcwY2NhOTQ1NWZhNzVjODc3MjIzOTk2
|
14
|
+
NjMxMzFhMzRjMWI5ZGRmZWNjMWI2YTcxMjNjZGU4NjEwZjhjYzlkOWQ3NWVm
|
15
|
+
NzRmN2U0MzllZjA4NTk2MDZmM2U3MzAyZDRkMDVlMjQ1YjFiOTE=
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Hashrocket Workstation
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MetroRelic
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'metro_relic'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install metro_relic
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/metro_relic.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require "metro_relic/version"
|
2
|
+
require 'newrelic_rpm'
|
3
|
+
|
4
|
+
module MetroRelic
|
5
|
+
class Logger
|
6
|
+
def log(message)
|
7
|
+
puts(message)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module MetroRelic
|
13
|
+
class RailsLogger
|
14
|
+
def log(message)
|
15
|
+
Rails.logger.warn(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module MetroRelic
|
21
|
+
class Tracer
|
22
|
+
attr_reader :method
|
23
|
+
|
24
|
+
def initialize(method)
|
25
|
+
@method = method
|
26
|
+
end
|
27
|
+
|
28
|
+
def trace!
|
29
|
+
if instance_method?
|
30
|
+
klass.send(:include, NewRelic::Agent::MethodTracer)
|
31
|
+
klass.add_method_tracer(name, metric)
|
32
|
+
elsif class_method?
|
33
|
+
klass.singleton_class.send(:include, NewRelic::Agent::MethodTracer)
|
34
|
+
klass.singleton_class.add_method_tracer(name, metric)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def metric
|
41
|
+
"Custom/MetroRelic/#{method}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def klass
|
45
|
+
@klass ||= Object.const_get(method.split(/(?=\#|\.)/)[0])
|
46
|
+
end
|
47
|
+
|
48
|
+
def raw_name
|
49
|
+
@raw_name ||= method.split(/(?=\#|\.)/)[1]
|
50
|
+
end
|
51
|
+
|
52
|
+
def name
|
53
|
+
@name ||= raw_name[1..-1].to_sym
|
54
|
+
end
|
55
|
+
|
56
|
+
def instance_method?
|
57
|
+
raw_name[0] == "#"
|
58
|
+
end
|
59
|
+
|
60
|
+
def class_method?
|
61
|
+
raw_name[0] == "."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module MetroRelic
|
67
|
+
class Tracker
|
68
|
+
attr_reader :method_list, :logger
|
69
|
+
|
70
|
+
def initialize(path, options={})
|
71
|
+
@logger = options[:logger] || Logger.new()
|
72
|
+
self.path = path
|
73
|
+
end
|
74
|
+
|
75
|
+
def track
|
76
|
+
method_list.each do |method|
|
77
|
+
begin
|
78
|
+
Tracer.new(method).trace!
|
79
|
+
logger.log("Added new relic monitoring to #{method}")
|
80
|
+
rescue
|
81
|
+
logger.log("Could not add MetroRelic tracking to #{method}")
|
82
|
+
raise NoMethodError.new
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def path=(path)
|
90
|
+
@method_list = File.read(path).split("\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
data/metro_relic.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metro_relic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "metro_relic"
|
8
|
+
spec.version = MetroRelic::VERSION
|
9
|
+
spec.authors = ["Brandon Farmer and Micah Cooper"]
|
10
|
+
spec.email = ["dev@hashrocket.com"]
|
11
|
+
spec.description = %q{Easily track custom newrelic metrics with a config file}
|
12
|
+
spec.summary = %q{Easily track custom newrelic metrics}
|
13
|
+
spec.homepage = "http://github.com/hashrocket/metro_relic"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "newrelic_rpm"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'metro_relic'
|
2
|
+
|
3
|
+
class Foo
|
4
|
+
def bar
|
5
|
+
"Hello World"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.baz
|
9
|
+
"Hello Class World"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class NoopLogger
|
15
|
+
def log(message)
|
16
|
+
# NOOP
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe MetroRelic::Tracker do
|
21
|
+
describe "#track" do
|
22
|
+
it "sends all specified instance methods metrics to newrelic" do
|
23
|
+
Foo.should_receive(:add_method_tracer).with(:bar, "Custom/MetroRelic/Foo#bar")
|
24
|
+
MetroRelic::Tracker.new('spec/fixtures/metro.config', logger: NoopLogger.new).track
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sends all specified class methods metrics to newrelic" do
|
28
|
+
Foo.singleton_class.should_receive(:add_method_tracer).with(:baz, "Custom/MetroRelic/Foo.baz")
|
29
|
+
MetroRelic::Tracker.new('spec/fixtures/metro.config', logger: NoopLogger.new).track
|
30
|
+
Foo.baz
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metro_relic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Farmer and Micah Cooper
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: newrelic_rpm
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Easily track custom newrelic metrics with a config file
|
70
|
+
email:
|
71
|
+
- dev@hashrocket.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .ruby-version
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/metro_relic.rb
|
83
|
+
- lib/metro_relic/version.rb
|
84
|
+
- metro_relic.gemspec
|
85
|
+
- spec/fixtures/metro.config
|
86
|
+
- spec/lib/metro_relic_spec.rb
|
87
|
+
homepage: http://github.com/hashrocket/metro_relic
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Easily track custom newrelic metrics
|
111
|
+
test_files:
|
112
|
+
- spec/fixtures/metro.config
|
113
|
+
- spec/lib/metro_relic_spec.rb
|