metriks-reporter-new_relic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +10 -0
- data/lib/metriks/reporter/new_relic.rb +23 -0
- data/lib/metriks/reporter/new_relic/sampler.rb +62 -0
- data/lib/metriks/reporter/new_relic/version.rb +7 -0
- data/metriks-reporter-new_relic.gemspec +26 -0
- data/test/metriks/reporter/new_relic/sampler_test.rb +47 -0
- data/test/metriks/reporter/new_relic_test.rb +14 -0
- data/test/test_helper.rb +2 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jon Guymon
|
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,21 @@
|
|
1
|
+
# Metriks::Reporter::NewRelic
|
2
|
+
|
3
|
+
Allows metric data collected by with the Metriks gem to be reported to your New Relic account via a running New Relic Ruby agent.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'metriks/reporter/new_relic'
|
9
|
+
|
10
|
+
Metriks::Reporter::NewRelic.start
|
11
|
+
```
|
12
|
+
|
13
|
+
Metric data will be available via [custom dashboards](https://newrelic.com/docs/instrumentation/custom-dashboards) in the "Custom" namespace. If you record some timer data like this:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Metriks.timer('some.time') do
|
17
|
+
something(that, takes).a.while
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
It will be recorded in New Relic as "Custom/some/time".
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'metriks'
|
2
|
+
require 'newrelic_rpm'
|
3
|
+
require 'metriks/reporter/new_relic/sampler'
|
4
|
+
|
5
|
+
module Metriks
|
6
|
+
module Reporter
|
7
|
+
module NewRelic
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def start
|
11
|
+
::NewRelic::Agent.instance.stats_engine.add_harvest_sampler(Sampler.new)
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
# not yet able
|
16
|
+
end
|
17
|
+
|
18
|
+
def restart
|
19
|
+
# not yet able
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'new_relic/agent/sampler'
|
2
|
+
|
3
|
+
module Metriks::Reporter
|
4
|
+
module NewRelic
|
5
|
+
class Sampler < ::NewRelic::Agent::Sampler
|
6
|
+
def initialize(options={})
|
7
|
+
@registry = options[:registry] || Metriks::Registry.default
|
8
|
+
@cache = Hash.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def poll
|
12
|
+
@registry.each do |name, metric|
|
13
|
+
case metric
|
14
|
+
when defined?(Metriks::Gauge) && metric.kind_of?(Metriks::Gauge)
|
15
|
+
NewRelic::Agent.record_metric(newrelic_name(name), metric.value)
|
16
|
+
|
17
|
+
when Metriks::Timer
|
18
|
+
count = value_update(name, :count, metric.count) do |old,new|
|
19
|
+
new - old
|
20
|
+
end
|
21
|
+
min = value_update(name, :min, metric.min) do |old,new|
|
22
|
+
new < old ? new : old
|
23
|
+
end
|
24
|
+
max = value_update(name, :max, metric.max) do |old,new|
|
25
|
+
new > old ? new : old
|
26
|
+
end
|
27
|
+
value = {
|
28
|
+
:total => metric.mean,
|
29
|
+
:count => count,
|
30
|
+
:min => min,
|
31
|
+
:max => max,
|
32
|
+
# NOTE: we lose the total sum of squares, not in the registry
|
33
|
+
:sum_of_squares => 0
|
34
|
+
}
|
35
|
+
::NewRelic::Agent.record_metric(newrelic_name(name), value)
|
36
|
+
|
37
|
+
when Metriks::Counter
|
38
|
+
count = value_update(name, :count, metric.count) do |old,new|
|
39
|
+
new - old
|
40
|
+
end
|
41
|
+
::NewRelic::Agent.increment_metric(newrelic_name(name), count)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def newrelic_name(name)
|
47
|
+
"Custom/" + name.gsub('.', '/')
|
48
|
+
end
|
49
|
+
|
50
|
+
def value_update(metric_name, field_name, new_value)
|
51
|
+
cache_key = "#{metric_name}-#{field_name}"
|
52
|
+
if @cache[cache_key] == nil
|
53
|
+
update = new_value
|
54
|
+
else
|
55
|
+
update = yield(@cache[cache_key], new_value)
|
56
|
+
end
|
57
|
+
@cache[cache_key] = update
|
58
|
+
return update
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metriks/reporter/new_relic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "metriks-reporter-new_relic"
|
8
|
+
spec.version = Metriks::Reporter::NewRelic::VERSION
|
9
|
+
spec.authors = ["Jon Guymon"]
|
10
|
+
spec.email = ["jon@newrelic.com"]
|
11
|
+
spec.description = %q{Allows metric data collected by with the Metriks gem to be reported to your New Relic account via a running New Relic Ruby agent.}
|
12
|
+
spec.summary = %q{Metriks Reporter for New Relic.}
|
13
|
+
spec.homepage = "https://github.com/newrelic/metriks-reporter-new_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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'newrelic_rpm', '> 3.5.0'
|
25
|
+
spec.add_dependency 'metriks'
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'metriks/reporter/new_relic/sampler'
|
3
|
+
|
4
|
+
class Metriks::Reporter::NewRelic::SamplerTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@registry = Metriks::Registry.new
|
7
|
+
@sampler = Metriks::Reporter::NewRelic::Sampler.new(:registry => @registry)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_harvests_guage_values_from_registry
|
11
|
+
@registry.gauge('queue.size').set(666)
|
12
|
+
@sampler.poll
|
13
|
+
assert_equal(666, NewRelic::Agent.instance.stats_engine \
|
14
|
+
.lookup_stats('Custom/queue/size').total_call_time)
|
15
|
+
end if Metriks.respond_to?(:gauge)
|
16
|
+
|
17
|
+
def test_harvests_timer_data
|
18
|
+
@registry.timer('queue.time').update(2)
|
19
|
+
@registry.timer('queue.time').update(4)
|
20
|
+
@registry.timer('queue.time').update(6)
|
21
|
+
|
22
|
+
@sampler.poll
|
23
|
+
|
24
|
+
stats = NewRelic::Agent.instance.stats_engine \
|
25
|
+
.lookup_stats('Custom/queue/time')
|
26
|
+
assert_equal(3, stats.call_count)
|
27
|
+
assert_equal(4, stats.total_call_time)
|
28
|
+
assert_equal(2, stats.min_call_time)
|
29
|
+
assert_equal(6, stats.max_call_time)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_harvests_counter_data_incrementally
|
33
|
+
@registry.counter('queue.push').increment
|
34
|
+
|
35
|
+
@sampler.poll
|
36
|
+
|
37
|
+
@registry.counter('queue.push').increment
|
38
|
+
@registry.counter('queue.push').increment
|
39
|
+
|
40
|
+
@sampler.poll
|
41
|
+
|
42
|
+
stats = NewRelic::Agent.instance.stats_engine \
|
43
|
+
.lookup_stats('Custom/queue/push')
|
44
|
+
assert_equal 3, stats.call_count # 3 not 4, don't recount the first
|
45
|
+
assert_equal 0, stats.total_call_time
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'metriks/reporter/new_relic'
|
3
|
+
|
4
|
+
class Metriks::Reporter::NewRelicTest < Test::Unit::TestCase
|
5
|
+
def test_start_adds_sampler_to_agent
|
6
|
+
::NewRelic::Agent.manual_start
|
7
|
+
Metriks::Reporter::NewRelic.start
|
8
|
+
assert(::NewRelic::Agent.instance.stats_engine.send(:harvest_samplers) \
|
9
|
+
.map{|s| s.class}.include?(Metriks::Reporter::NewRelic::Sampler))
|
10
|
+
end
|
11
|
+
|
12
|
+
def _test_stop_removes_sampler_from_agent
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metriks-reporter-new_relic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Guymon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: newrelic_rpm
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>'
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.5.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.5.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: metriks
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Allows metric data collected by with the Metriks gem to be reported to
|
79
|
+
your New Relic account via a running New Relic Ruby agent.
|
80
|
+
email:
|
81
|
+
- jon@newrelic.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/metriks/reporter/new_relic.rb
|
92
|
+
- lib/metriks/reporter/new_relic/sampler.rb
|
93
|
+
- lib/metriks/reporter/new_relic/version.rb
|
94
|
+
- metriks-reporter-new_relic.gemspec
|
95
|
+
- test/metriks/reporter/new_relic/sampler_test.rb
|
96
|
+
- test/metriks/reporter/new_relic_test.rb
|
97
|
+
- test/test_helper.rb
|
98
|
+
homepage: https://github.com/newrelic/metriks-reporter-new_relic
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.23
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Metriks Reporter for New Relic.
|
123
|
+
test_files:
|
124
|
+
- test/metriks/reporter/new_relic/sampler_test.rb
|
125
|
+
- test/metriks/reporter/new_relic_test.rb
|
126
|
+
- test/test_helper.rb
|