newrelic_platform 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +22 -0
- data/README.md +65 -0
- data/Rakefile +22 -0
- data/lib/newrelic_platform.rb +4 -0
- data/lib/newrelic_platform/client.rb +50 -0
- data/lib/newrelic_platform/collector.rb +78 -0
- data/lib/newrelic_platform/version.rb +3 -0
- data/newrelic_platform-0.0.2.gem +0 -0
- data/newrelic_platform.gemspec +24 -0
- data/test/test_base.rb +25 -0
- data/test/test_rest.rb +22 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3233a6fa87544c50b1a7777280eb308bff9ca8cd
|
4
|
+
data.tar.gz: 65488db4fc39b41e0b8131863bc40d84b0e7ecdd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc92a0f9047c90da2b811ae0172ead9234c59d7971ceffdc1567e0833976dd2da54a01bd219d777df2cdb83fa31dab39a3e2d560effe344f8dc1f3a03222778c
|
7
|
+
data.tar.gz: 0e84219994bd7dbde0a992dc438a629fb7abb9685a93a153f811f89e31a4587dadff9aa34050d3d38a674ec559f797f7f4b0d5a75f204717beebe75dff3a20f0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
newrelic_platform (0.0.2)
|
5
|
+
rest
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ethon (0.5.10)
|
11
|
+
ffi (~> 1.3.0)
|
12
|
+
mime-types (~> 1.18)
|
13
|
+
ffi (1.3.1)
|
14
|
+
mime-types (1.21)
|
15
|
+
rest (2.5.0)
|
16
|
+
rest-client (>= 0.3.0)
|
17
|
+
typhoeus (>= 0.5.4)
|
18
|
+
rest-client (1.6.7)
|
19
|
+
mime-types (>= 1.16)
|
20
|
+
typhoeus (0.6.2)
|
21
|
+
ethon (~> 0.5.10)
|
22
|
+
uber_config (1.0.5)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
newrelic_platform!
|
29
|
+
uber_config
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012, Iron.io, Inc. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
5
|
+
|
6
|
+
* Redistributions of source code must retain the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer in the documentation
|
10
|
+
and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
13
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
14
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
16
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
17
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
18
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
19
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
21
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# New Relic HTTP API Ruby Wrapper
|
2
|
+
|
3
|
+
Ruby wrapper around the New Relic HTTP API. Makes it very easy to post component and metric data to the API.
|
4
|
+
|
5
|
+
|
6
|
+
## Getting Started
|
7
|
+
|
8
|
+
|
9
|
+
### Install the Gem
|
10
|
+
|
11
|
+
The gem is currently private so you'll need to clone this repo and then install the gem.
|
12
|
+
|
13
|
+
gem install ./newrelic_platform-0.0.2.gem
|
14
|
+
|
15
|
+
|
16
|
+
### Create the client
|
17
|
+
|
18
|
+
```
|
19
|
+
new_relic = NewRelic::Client.new(:license => YOUR_NEW_RELIC_LICENSE,
|
20
|
+
:guid => YOUR_GUID,
|
21
|
+
:version => '0.0.1')
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
### Create the Collector
|
26
|
+
|
27
|
+
```
|
28
|
+
collector = new_relic.new_collector
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
### Create the component
|
33
|
+
|
34
|
+
```
|
35
|
+
component = collector.component("COMPONENT_NAME")
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
### Add Metrics
|
42
|
+
|
43
|
+
```
|
44
|
+
component.add_metric 'Widgets Sold', 'widgets', 1000
|
45
|
+
component.add_metric 'Widget Rate', 'widgets/sec', 5
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
### Post the data to New Relic
|
51
|
+
|
52
|
+
```
|
53
|
+
response = collector.submit
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
Boom. Data.
|
58
|
+
|
59
|
+
|
60
|
+
## Further Reading
|
61
|
+
|
62
|
+
You can use IronWorker by Iron.io to easily schedule this collector so that it runs every minute.
|
63
|
+
|
64
|
+
See more here: https://github.com/newrelic-platform/ironmq_worker
|
65
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
6
|
+
test.libs << 'lib' << 'test'
|
7
|
+
test.pattern = 'test/**/test_*.rb'
|
8
|
+
test.verbose = true
|
9
|
+
p ENV['gem']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
require 'rdoc/task'
|
15
|
+
Rake::RDocTask.new do |rdoc|
|
16
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
17
|
+
|
18
|
+
rdoc.rdoc_dir = 'doc'
|
19
|
+
rdoc.title = "newrelic_platform #{version}"
|
20
|
+
rdoc.rdoc_files.include('README*')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
if RUBY_VERSION.split('.')[1].to_i == 8
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'json'
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
# This is a simple wrapper that can use different http clients depending on what's installed.
|
10
|
+
# The purpose of this is so that users who can't install binaries easily (like windoze users)
|
11
|
+
# can have fallbacks that work.
|
12
|
+
|
13
|
+
module NewRelic
|
14
|
+
|
15
|
+
|
16
|
+
def self.logger=(logger)
|
17
|
+
@logger = logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger()
|
21
|
+
@logger
|
22
|
+
end
|
23
|
+
|
24
|
+
class Client
|
25
|
+
|
26
|
+
attr_accessor :license, :guid, :version, :options, :logger
|
27
|
+
# options:
|
28
|
+
# - :gem => specify gem explicitly
|
29
|
+
#
|
30
|
+
def initialize(options={})
|
31
|
+
|
32
|
+
@license = options[:license]
|
33
|
+
@guid = options[:guid]
|
34
|
+
@version = options[:version]
|
35
|
+
|
36
|
+
@options = options
|
37
|
+
@logger = Logger.new(STDOUT)
|
38
|
+
@logger.level = options[:log_level] || Logger::INFO
|
39
|
+
|
40
|
+
@agent = options[:agent] || "newrelic_platform gem"
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def new_collector
|
45
|
+
return Collector.new(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module NewRelic
|
2
|
+
|
3
|
+
class Collector
|
4
|
+
|
5
|
+
attr_accessor :client, :components
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
|
9
|
+
@client = client
|
10
|
+
@components = {}
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# options:
|
15
|
+
# :duration => time interval between metrics in seconds. default is 60.
|
16
|
+
def component(component_name, options={})
|
17
|
+
@components[component_name] ||= Component.new(self, component_name, options)
|
18
|
+
@components[component_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# options:
|
23
|
+
#
|
24
|
+
def submit(options={})
|
25
|
+
# build components array
|
26
|
+
components_array = []
|
27
|
+
components.each_pair do |k, c|
|
28
|
+
p c
|
29
|
+
components_array << {
|
30
|
+
:name => c.name,
|
31
|
+
:guid => client.guid,
|
32
|
+
:duration => c.options[:duration] || 60,
|
33
|
+
:metrics => c.metrics
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
body = {
|
38
|
+
:agent => {
|
39
|
+
:version => client.version,
|
40
|
+
:pid => 1,
|
41
|
+
:host => "whatever"
|
42
|
+
},
|
43
|
+
:components => components_array
|
44
|
+
}
|
45
|
+
|
46
|
+
headers = {
|
47
|
+
'Content-Type' => 'application/json',
|
48
|
+
'Accept' => 'application/json',
|
49
|
+
'X-License-Key' => client.license
|
50
|
+
}
|
51
|
+
puts "headers: #{headers.inspect}"
|
52
|
+
p body
|
53
|
+
response = Rest::Client.new.post('https://platform-api.newrelic.com/platform/v1/metrics',
|
54
|
+
:body => body.to_json,
|
55
|
+
:headers => headers)
|
56
|
+
JSON.parse(response.body)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class Component
|
64
|
+
|
65
|
+
attr_accessor :collector, :name, :metrics, :options
|
66
|
+
|
67
|
+
def initialize(collector, name, options={})
|
68
|
+
@collector = collector
|
69
|
+
@name = name
|
70
|
+
@metrics = {}
|
71
|
+
@options = options
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_metric(metric_name, units, value)
|
75
|
+
@metrics["Component/#{metric_name}[#{units}]"] = value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../lib/newrelic_platform/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Travis Reeder", "Chad Arimura"]
|
5
|
+
gem.email = ["travis@iron.io"]
|
6
|
+
gem.description = "Ruby wrapper around the New Relic HTTP API. Makes it very easy to post component and metric data to the API."
|
7
|
+
gem.summary = "Ruby wrapper around the New Relic HTTP API."
|
8
|
+
gem.homepage = "https://github.com/newrelic-platform/iron_sdk"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "newrelic_platform"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = NewRelic::VERSION
|
16
|
+
|
17
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
18
|
+
gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
|
19
|
+
gem.add_runtime_dependency "rest"
|
20
|
+
|
21
|
+
gem.add_development_dependency "uber_config"
|
22
|
+
|
23
|
+
end
|
24
|
+
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yaml'
|
3
|
+
require 'uber_config'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require File.join(File.dirname(__FILE__), '../lib/newrelic_platform')
|
7
|
+
rescue Exception => ex
|
8
|
+
puts "Could NOT load gem: " + ex.message
|
9
|
+
raise ex
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestBase < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts 'setup'
|
16
|
+
|
17
|
+
@config = UberConfig.load
|
18
|
+
p @config
|
19
|
+
|
20
|
+
@new_relic = NewRelic::Client.new(:license => @config['newrelic_license'], :guid=>"testeroni", :version=>"0.0.1", :log_level=>Logger::DEBUG)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
data/test/test_rest.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'yaml'
|
5
|
+
require File.expand_path('test_base', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class TestRest < TestBase
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basics
|
14
|
+
collector = @new_relic.new_collector
|
15
|
+
collector.component("Test Gem Component").add_metric 'testgem2', 'messages', 10
|
16
|
+
collector.component("Other component").add_metric 'testgem3', 'messages', 20
|
17
|
+
r = collector.submit
|
18
|
+
p r
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic_platform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Reeder
|
8
|
+
- Chad Arimura
|
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: rest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: uber_config
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Ruby wrapper around the New Relic HTTP API. Makes it very easy to post
|
43
|
+
component and metric data to the API.
|
44
|
+
email:
|
45
|
+
- travis@iron.io
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/newrelic_platform.rb
|
57
|
+
- lib/newrelic_platform/client.rb
|
58
|
+
- lib/newrelic_platform/collector.rb
|
59
|
+
- lib/newrelic_platform/version.rb
|
60
|
+
- newrelic_platform-0.0.2.gem
|
61
|
+
- newrelic_platform.gemspec
|
62
|
+
- test/test_base.rb
|
63
|
+
- test/test_rest.rb
|
64
|
+
homepage: https://github.com/newrelic-platform/iron_sdk
|
65
|
+
licenses: []
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.3.6
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.0.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Ruby wrapper around the New Relic HTTP API.
|
87
|
+
test_files:
|
88
|
+
- test/test_base.rb
|
89
|
+
- test/test_rest.rb
|