newrelic_plugin 1.0.2
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/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +19 -0
- data/lib/newrelic_plugin.rb +12 -0
- data/lib/newrelic_plugin/agent.rb +155 -0
- data/lib/newrelic_plugin/config.rb +84 -0
- data/lib/newrelic_plugin/data_collector.rb +67 -0
- data/lib/newrelic_plugin/error.rb +22 -0
- data/lib/newrelic_plugin/new_relic_connection.rb +67 -0
- data/lib/newrelic_plugin/new_relic_message.rb +173 -0
- data/lib/newrelic_plugin/processor.rb +18 -0
- data/lib/newrelic_plugin/processors/epoch_counter_processor.rb +21 -0
- data/lib/newrelic_plugin/processors/rate_processor.rb +35 -0
- data/lib/newrelic_plugin/run.rb +120 -0
- data/lib/newrelic_plugin/setup.rb +54 -0
- data/lib/newrelic_plugin/simple_syntax.rb +54 -0
- data/lib/newrelic_plugin/version.rb +5 -0
- data/newrelic_plugin.gemspec +47 -0
- data/test/agent_test.rb +153 -0
- data/test/fixtures/valid_payload.json +17 -0
- data/test/manual_test.rb +20 -0
- data/test/new_relic_message_test.rb +76 -0
- data/test/test_helper.rb +15 -0
- metadata +141 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/newrelic_plugin/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
6
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
|
+
s.rubygems_version = '1.3.5'
|
8
|
+
|
9
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
10
|
+
s.name = 'newrelic_plugin'
|
11
|
+
s.version = NewRelic::Plugin::VERSION
|
12
|
+
s.rubyforge_project = 'newrelic_plugin'
|
13
|
+
|
14
|
+
## Edit these as appropriate
|
15
|
+
s.summary = "New Relic Ruby Plugin SDK"
|
16
|
+
s.description = %q{The New Relic Plugin Gem is used to send plugin data to New Relic from non-application sources.}
|
17
|
+
|
18
|
+
s.authors = ["New Relic"]
|
19
|
+
s.email = ["support@newrelic.com"]
|
20
|
+
s.homepage = 'http://newrelic.com'
|
21
|
+
|
22
|
+
s.require_paths = %w[lib]
|
23
|
+
|
24
|
+
s.rdoc_options = ["--charset=UTF-8",
|
25
|
+
"--main", "README.md"]
|
26
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
27
|
+
|
28
|
+
s.add_dependency 'faraday', '>= 0.8.1'
|
29
|
+
s.add_dependency 'json'
|
30
|
+
|
31
|
+
## List your development dependencies here. Development dependencies are
|
32
|
+
## those that are only needed during development
|
33
|
+
#s.add_development_dependency "minitest"
|
34
|
+
#s.add_development_dependency "vcr"
|
35
|
+
s.add_development_dependency 'shoulda-context'
|
36
|
+
s.add_development_dependency 'mocha'
|
37
|
+
|
38
|
+
s.files = `git ls-files`.split($\)
|
39
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
40
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
41
|
+
|
42
|
+
|
43
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
44
|
+
## matches what you actually use.
|
45
|
+
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
46
|
+
|
47
|
+
end
|
data/test/agent_test.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AgentTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@agent_info = {:ident => 1}
|
7
|
+
@agent_class = TestingAgent::Agent.dup
|
8
|
+
end
|
9
|
+
|
10
|
+
context :agent_guid do
|
11
|
+
should 'set guid' do
|
12
|
+
@agent_class.class_eval do
|
13
|
+
agent_guid '12234'
|
14
|
+
end
|
15
|
+
agent = @agent_class.new('test agent', @agent_info)
|
16
|
+
assert_equal '12234', agent.class.guid
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'raise RuntimeError if guid is set to nil' do
|
20
|
+
assert_raise RuntimeError do
|
21
|
+
@agent_class.class_eval do
|
22
|
+
agent_guid nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'raise RuntimeError if guid is set to empty string' do
|
28
|
+
assert_raise RuntimeError do
|
29
|
+
@agent_class.class_eval do
|
30
|
+
agent_guid ""
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context :guid do
|
37
|
+
should "return instance @guid" do
|
38
|
+
agent = @agent_class.new('test agent', @agent_info)
|
39
|
+
agent.instance_variable_set(:@guid, 'test')
|
40
|
+
assert_equal 'test', agent.guid
|
41
|
+
end
|
42
|
+
|
43
|
+
should "return class guid" do
|
44
|
+
@agent_class.class_eval do
|
45
|
+
@guid = '123'
|
46
|
+
end
|
47
|
+
agent = @agent_class.new('test agent', @agent_info)
|
48
|
+
assert_equal '123', agent.guid
|
49
|
+
end
|
50
|
+
|
51
|
+
should "raise error if guid is not set properly" do
|
52
|
+
@agent_class.class_eval do
|
53
|
+
@guid = 'guid'
|
54
|
+
end
|
55
|
+
#agent = TestingAgent::Agent.new('test agent', @agent_info)
|
56
|
+
# refactor the code this is hitting before finishing this test
|
57
|
+
# this does not test well
|
58
|
+
#assert_raise RuntimeError, 'Did not set GUID' do
|
59
|
+
# agent.guid
|
60
|
+
#end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context :agent_version do
|
65
|
+
should 'set version' do
|
66
|
+
@agent_class.class_eval do
|
67
|
+
agent_version '0.0.1'
|
68
|
+
end
|
69
|
+
agent = @agent_class.new('test agent', @agent_info)
|
70
|
+
assert_equal '0.0.1', agent.class.version
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context :version do
|
75
|
+
should 'return class @version' do
|
76
|
+
@agent_class.class_eval do
|
77
|
+
@version = '1.2.3'
|
78
|
+
end
|
79
|
+
agent = @agent_class.new('test agent', @agent_info)
|
80
|
+
assert_equal '1.2.3', agent.version
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context :agent_human_labels do
|
85
|
+
setup do
|
86
|
+
@agent_class.class_eval do
|
87
|
+
agent_human_labels('Testing Agent') { 'Testing Agent block' }
|
88
|
+
end
|
89
|
+
@agent = @agent_class.new('test agent', @agent_info)
|
90
|
+
end
|
91
|
+
should 'set class @label' do
|
92
|
+
assert_equal 'Testing Agent', @agent.class.label
|
93
|
+
end
|
94
|
+
should 'set instance label proc' do
|
95
|
+
assert_equal "Testing Agent block", @agent.class.instance_label_proc.call
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context :no_config_required do
|
100
|
+
should 'set class @no_config_required' do
|
101
|
+
@agent_class.class_eval do
|
102
|
+
agent_human_labels('Testing Agent') { 'Testing Agent block' }
|
103
|
+
end
|
104
|
+
agent = @agent_class.new('test agent', @agent_info)
|
105
|
+
assert_equal true, agent.class.no_config_required
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context :config_required? do
|
110
|
+
should 'return false when class @no_config_required true' do
|
111
|
+
@agent_class.class_eval do
|
112
|
+
@no_config_required = true
|
113
|
+
end
|
114
|
+
agent = @agent_class.new('test agent', @agent_info)
|
115
|
+
assert_equal false, agent.class.config_required?
|
116
|
+
end
|
117
|
+
should 'return true when class @no_config_required false' do
|
118
|
+
@agent_class.class_eval do
|
119
|
+
@no_config_required = false
|
120
|
+
end
|
121
|
+
agent = @agent_class.new('test agent', @agent_info)
|
122
|
+
assert_equal true, agent.class.config_required?
|
123
|
+
end
|
124
|
+
should 'return true when class @no_config_required is not set' do
|
125
|
+
@agent_class.class_eval do
|
126
|
+
end
|
127
|
+
agent = @agent_class.new('test agent', @agent_info)
|
128
|
+
assert_equal true, agent.class.config_required?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context :agent_config_options do
|
133
|
+
should 'set class @config_options_list if empty' do
|
134
|
+
@agent_class.class_eval do
|
135
|
+
agent_config_options(:test, 'foo', 'bar')
|
136
|
+
end
|
137
|
+
@agent = @agent_class.new('test agent', @agent_info)
|
138
|
+
assert_equal [:test, 'foo', 'bar'], @agent.class.config_options_list
|
139
|
+
end
|
140
|
+
|
141
|
+
should 'add to existing @config_options_list' do
|
142
|
+
@agent_class.class_eval do
|
143
|
+
attr_accessor 'foobar'
|
144
|
+
@config_options_list = ['foobar']
|
145
|
+
agent_config_options(:test, 'foo', 'bar')
|
146
|
+
end
|
147
|
+
|
148
|
+
@agent = @agent_class.new('test agent', @agent_info)
|
149
|
+
assert_equal ['foobar', :test, 'foo', 'bar'], @agent.class.config_options_list
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"agent": {
|
3
|
+
"host" : "localhost",
|
4
|
+
"name" : "Test",
|
5
|
+
"version" : "1.0.0" },
|
6
|
+
"components": [
|
7
|
+
{ "name": "Xtra DB",
|
8
|
+
"guid": "com.newrelic.test.Plugin",
|
9
|
+
"duration" : 120,
|
10
|
+
"metrics" : {
|
11
|
+
"one": 100,
|
12
|
+
"two": [10,2,2,8,68]
|
13
|
+
}
|
14
|
+
}
|
15
|
+
]
|
16
|
+
}
|
17
|
+
|
data/test/manual_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
new_relic_message = NewRelic::Plugin::NewRelicMessage.new('fake connection', 'manual curl test', 'manual-test-guid', 'version', 60)
|
5
|
+
new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
6
|
+
new_relic_message.add_stat_fullname('other metric', 2, 2, :min => 2, :max => 2, :sum_of_squares => 8)
|
7
|
+
|
8
|
+
puts <<-EOF
|
9
|
+
########################################################
|
10
|
+
Manual testing -- output curl command with payload
|
11
|
+
########################################################
|
12
|
+
|
13
|
+
curl -vi http://collector.newrelic.com/platform/v1/metrics \
|
14
|
+
-H "X-License-Key: ADD_LICENSE_KEY" \
|
15
|
+
-H "Content-Type: application/json" \
|
16
|
+
-H "Accept: application/json" \
|
17
|
+
-X POST -d \'#{new_relic_message.send(:build_request_payload)}\'
|
18
|
+
|
19
|
+
########################################################
|
20
|
+
EOF
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NewRelicMessageTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@new_relic_message = NewRelic::Plugin::NewRelicMessage.new('foo', 'test component name', 'fake guid', 'version', 60)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'initialization' do
|
9
|
+
should 'start with an empty metrics array' do
|
10
|
+
assert_equal [], @new_relic_message.instance_variable_get(:@metrics)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context :add_stat_fullname do
|
15
|
+
setup do
|
16
|
+
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
17
|
+
end
|
18
|
+
should '@metric array should have 1 metric' do
|
19
|
+
assert_equal 1, @new_relic_message.metrics.size
|
20
|
+
end
|
21
|
+
|
22
|
+
should '@metric array should include expected data' do
|
23
|
+
stored_metric = {
|
24
|
+
:metric_name => 'test metric',
|
25
|
+
:count => 2,
|
26
|
+
:total => 2,
|
27
|
+
:min => 1,
|
28
|
+
:max => 3,
|
29
|
+
:sum_of_squares => 10
|
30
|
+
}
|
31
|
+
assert_equal stored_metric, @new_relic_message.metrics.first
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context :build_metrics_hash do
|
36
|
+
setup do
|
37
|
+
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
38
|
+
@new_relic_message.add_stat_fullname('other metric', 2, 2, :min => 2, :max => 2, :sum_of_squares => 8)
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'build expected metric hash' do
|
42
|
+
metric_hash = {
|
43
|
+
'test metric' => [2,2,3,1,10],
|
44
|
+
'other metric' => [2,2,2,2,8]
|
45
|
+
}
|
46
|
+
assert_equal metric_hash, @new_relic_message.send(:build_metrics_hash)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context :build_request_payload do
|
51
|
+
setup do
|
52
|
+
@new_relic_message.add_stat_fullname('test metric', 2, 2, :min => 1, :max => 3, :sum_of_squares => 10)
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'build expected request payload' do
|
56
|
+
payload = {
|
57
|
+
'agent' => {
|
58
|
+
'name' => 'test component name',
|
59
|
+
'version' => 'version',
|
60
|
+
'host' => ''
|
61
|
+
},
|
62
|
+
'components' => [
|
63
|
+
{
|
64
|
+
'name' => 'test component name',
|
65
|
+
'guid' => 'fake guid',
|
66
|
+
'duration' => 60,
|
67
|
+
'metrics' => @new_relic_message.send(:build_metrics_hash)
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_equal payload.to_json, @new_relic_message.send(:build_request_payload)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic_plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- New Relic
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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: shoulda-context
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mocha
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
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: The New Relic Plugin Gem is used to send plugin data to New Relic from
|
79
|
+
non-application sources.
|
80
|
+
email:
|
81
|
+
- support@newrelic.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- README.md
|
86
|
+
- LICENSE
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/newrelic_plugin.rb
|
94
|
+
- lib/newrelic_plugin/agent.rb
|
95
|
+
- lib/newrelic_plugin/config.rb
|
96
|
+
- lib/newrelic_plugin/data_collector.rb
|
97
|
+
- lib/newrelic_plugin/error.rb
|
98
|
+
- lib/newrelic_plugin/new_relic_connection.rb
|
99
|
+
- lib/newrelic_plugin/new_relic_message.rb
|
100
|
+
- lib/newrelic_plugin/processor.rb
|
101
|
+
- lib/newrelic_plugin/processors/epoch_counter_processor.rb
|
102
|
+
- lib/newrelic_plugin/processors/rate_processor.rb
|
103
|
+
- lib/newrelic_plugin/run.rb
|
104
|
+
- lib/newrelic_plugin/setup.rb
|
105
|
+
- lib/newrelic_plugin/simple_syntax.rb
|
106
|
+
- lib/newrelic_plugin/version.rb
|
107
|
+
- newrelic_plugin.gemspec
|
108
|
+
- test/agent_test.rb
|
109
|
+
- test/fixtures/valid_payload.json
|
110
|
+
- test/manual_test.rb
|
111
|
+
- test/new_relic_message_test.rb
|
112
|
+
- test/test_helper.rb
|
113
|
+
homepage: http://newrelic.com
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options:
|
117
|
+
- --charset=UTF-8
|
118
|
+
- --main
|
119
|
+
- README.md
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project: newrelic_plugin
|
136
|
+
rubygems_version: 1.8.23
|
137
|
+
signing_key:
|
138
|
+
specification_version: 2
|
139
|
+
summary: New Relic Ruby Plugin SDK
|
140
|
+
test_files:
|
141
|
+
- test/test_helper.rb
|