netuitive_ruby_api 0.9.2 → 0.9.3
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 +4 -4
- data/config/agent.yml +3 -5
- data/lib/netuitive/ruby_config_manager.rb +51 -46
- data/lib/netuitive_ruby_api.rb +10 -7
- metadata +5 -12
- data/lib/netuitive/api_emissary.rb +0 -35
- data/lib/netuitive/ingest_attribute.rb +0 -10
- data/lib/netuitive/ingest_element.rb +0 -17
- data/lib/netuitive/ingest_metric.rb +0 -15
- data/lib/netuitive/ingest_sample.rb +0 -18
- data/lib/netuitive/ingest_tag.rb +0 -10
- data/lib/netuitive/metric_aggregator.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74fc103aa5937aa1ec899a8c077a77b6422cf3b5
|
4
|
+
data.tar.gz: 92841e2be3f35c1613211c5d61d39d6d6fc6f4e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda154e4df70c990327808667d59a1a547a73514ae5fdb9df2ac4fe90996c4463e71f4ba0e5836dfdc4033c4daeae3facde9df7a7ae0bc959aed90e704c4e3f5
|
7
|
+
data.tar.gz: 9d6552e1bbd21b57f555f3e4376afe62fe2d9f0417deabee64c77c89f20e2dd81610d221b42eddf893ee3cfa5e064d512478c9f4cb32b51c1d6f3cd9511e2f32
|
data/config/agent.yml
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
elementName: [element name] #name of the element to assign metrics to in netuitive. if unsure, just use the name of your app
|
5
|
-
debugLevel: error #options (in ascending order of debugness) are: error, info, debug
|
1
|
+
debugLevel: info #options (in ascending order of debugness) are: error, info, debug
|
2
|
+
netuitivedAddr: localhost
|
3
|
+
netuitivedPort: 8787
|
@@ -1,61 +1,66 @@
|
|
1
1
|
class ConfigManager
|
2
2
|
|
3
|
-
|
3
|
+
class << self
|
4
|
+
def setup()
|
5
|
+
@@error=0
|
6
|
+
@@info=1
|
7
|
+
@@debug=2
|
8
|
+
readConfig()
|
9
|
+
end
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@debug=2
|
9
|
-
readConfig()
|
10
|
-
end
|
11
|
+
def netuitivedAddr
|
12
|
+
@@netuitivedAddr
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
return true
|
15
|
+
def netuitivedPort
|
16
|
+
@@netuitivedPort
|
15
17
|
end
|
16
|
-
return false
|
17
|
-
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def isDebug?
|
20
|
+
if @@debugLevel >= @@debug
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
return false
|
22
24
|
end
|
23
|
-
return false
|
24
|
-
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def isInfo?
|
27
|
+
if @@debugLevel >= @@info
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
return false
|
29
31
|
end
|
30
|
-
return false
|
31
|
-
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@port=data["port"]
|
39
|
-
@elementName=data["elementName"]
|
40
|
-
debugLevelString=data["debugLevel"]
|
41
|
-
if debugLevelString == "error"
|
42
|
-
@debugLevel=@error
|
43
|
-
elsif debugLevelString == "info"
|
44
|
-
@debugLevel=@info
|
45
|
-
elsif debugLevelString == "debug"
|
46
|
-
@debugLevel=@debug
|
47
|
-
else
|
48
|
-
@debugLevel=@error
|
33
|
+
def isError?
|
34
|
+
if @@debugLevel >= @@error
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
return false
|
49
38
|
end
|
50
39
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
40
|
+
def readConfig()
|
41
|
+
gem_root= File.expand_path("../../..", __FILE__)
|
42
|
+
data=YAML.load_file "#{gem_root}/config/agent.yml"
|
43
|
+
@@netuitivedAddr=data["netuitivedAddr"]
|
44
|
+
@@netuitivedPort=data["netuitivedPort"]
|
45
|
+
puts "port: #{@@netuitivedPort}"
|
46
|
+
puts "addr: #{@@netuitivedAddr}"
|
47
|
+
debugLevelString=data["debugLevel"]
|
48
|
+
if debugLevelString == "error"
|
49
|
+
@@debugLevel=@@error
|
50
|
+
elsif debugLevelString == "info"
|
51
|
+
@@debugLevel=@@info
|
52
|
+
elsif debugLevelString == "debug"
|
53
|
+
@@debugLevel=@@debug
|
54
|
+
else
|
55
|
+
@@debugLevel=@@error
|
56
|
+
end
|
57
|
+
|
58
|
+
if isDebug?
|
59
|
+
puts "read config file. Results:
|
60
|
+
netuitivedAddr: #{@@netuitivedAddr}
|
61
|
+
netuitivedPort: #{@@netuitivedPort}
|
62
|
+
debugLevel: #{debugLevelString}"
|
63
|
+
end
|
58
64
|
end
|
59
65
|
end
|
60
|
-
|
61
66
|
end
|
data/lib/netuitive_ruby_api.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
require 'netuitive/
|
1
|
+
require 'netuitive/ruby_config_manager'
|
2
|
+
require 'drb/drb'
|
2
3
|
class NetuitiveRubyAPI
|
3
4
|
class << self
|
4
|
-
def setup
|
5
|
-
@@
|
5
|
+
def setup(server)
|
6
|
+
@@netuitivedServer=server
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
return @@
|
9
|
+
def netuitivedServer
|
10
|
+
return @@netuitivedServer
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
13
|
-
|
14
|
-
|
14
|
+
ConfigManager::setup
|
15
|
+
SERVER_URI="druby://#{ConfigManager.netuitivedAddr}:#{ConfigManager.netuitivedPort}"
|
16
|
+
DRb.start_service
|
17
|
+
NetuitiveRubyAPI.setup(DRbObject.new_with_uri(SERVER_URI))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netuitive_ruby_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John King
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows for easy submittion of metrics to Netuitive
|
14
14
|
email: jking@netuitive.com
|
@@ -16,17 +16,10 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/netuitive/api_emissary.rb
|
20
|
-
- lib/netuitive/ingest_attribute.rb
|
21
|
-
- lib/netuitive/ingest_element.rb
|
22
|
-
- lib/netuitive/ingest_metric.rb
|
23
|
-
- lib/netuitive/ingest_sample.rb
|
24
|
-
- lib/netuitive/ingest_tag.rb
|
25
|
-
- lib/netuitive/metric_aggregator.rb
|
26
19
|
- lib/netuitive/ruby_config_manager.rb
|
27
20
|
- lib/netuitive_ruby_api.rb
|
28
21
|
- config/agent.yml
|
29
|
-
- ./LICENSE
|
22
|
+
- "./LICENSE"
|
30
23
|
homepage: http://rubygems.org/gems/netuitive_ruby_api
|
31
24
|
licenses:
|
32
25
|
- Apache v2.0
|
@@ -37,12 +30,12 @@ require_paths:
|
|
37
30
|
- lib
|
38
31
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
32
|
requirements:
|
40
|
-
- -
|
33
|
+
- - ">="
|
41
34
|
- !ruby/object:Gem::Version
|
42
35
|
version: '0'
|
43
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
37
|
requirements:
|
45
|
-
- -
|
38
|
+
- - ">="
|
46
39
|
- !ruby/object:Gem::Version
|
47
40
|
version: '0'
|
48
41
|
requirements: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'json'
|
4
|
-
require 'yaml'
|
5
|
-
require 'netuitive/ruby_config_manager'
|
6
|
-
class APIEmissary
|
7
|
-
|
8
|
-
def initialize(apiId, baseAddr, port)
|
9
|
-
@apiId=apiId
|
10
|
-
@baseAddr=baseAddr
|
11
|
-
@port=port
|
12
|
-
@configManager=ConfigManager.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def sendElements(elements)
|
16
|
-
if @configManager.isDebug?
|
17
|
-
puts elements.to_json
|
18
|
-
end
|
19
|
-
|
20
|
-
uri = URI("#{@baseAddr}/ingest/#{@apiId}")
|
21
|
-
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
22
|
-
req.body = elements.to_json
|
23
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
|
24
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
25
|
-
http.ssl_version = :SSLv3
|
26
|
-
http.request req
|
27
|
-
end
|
28
|
-
if (response.code != "202" and @configManager.isError?) or (@configManager.isInfo?)
|
29
|
-
puts "Response from submitting netuitive metrics to api
|
30
|
-
code: #{response.code}
|
31
|
-
message: #{response.message}
|
32
|
-
body: #{response.body}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
class IngestElement
|
3
|
-
attr_accessor :id, :name, :type, :location, :metrics, :samples, :tags, :attributes
|
4
|
-
def initialize(id, name, type, location, metrics, samples, tags, attributes)
|
5
|
-
@id=id
|
6
|
-
@name=name
|
7
|
-
@type=type
|
8
|
-
@location=location
|
9
|
-
@metrics=metrics
|
10
|
-
@samples=samples
|
11
|
-
@tags=tags
|
12
|
-
@attributes=attributes
|
13
|
-
end
|
14
|
-
def to_json(options = {})
|
15
|
-
{'id' => @id, 'name' => @name, 'type' => @type, 'location' => @location, 'metrics' => @metrics, 'samples' => @samples,'tags' => @tags, 'attributes' => @attributes}.to_json.tr('\\', '')
|
16
|
-
end
|
17
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
class IngestMetric
|
3
|
-
attr_accessor :id, :name, :unit, :type, :tags, :aggregate
|
4
|
-
def initialize(id, name, unit, type, tags, aggregate)
|
5
|
-
@id=id
|
6
|
-
@name=name
|
7
|
-
@unit=unit
|
8
|
-
@type=type
|
9
|
-
@tags=tags
|
10
|
-
@aggregate=aggregate
|
11
|
-
end
|
12
|
-
def to_json(options = {})
|
13
|
-
{'id' => @id,'name' => @name, 'unit' => @unit,'type' => @type, 'tags' => @tags}.to_json
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
class IngestSample
|
3
|
-
attr_accessor :metricId, :timestamp, :val, :min, :max, :avg, :sum, :cnt
|
4
|
-
def initialize(metricId, timestamp, val, min, max, avg, sum, cnt)
|
5
|
-
@metricId=metricId
|
6
|
-
@timestamp=timestamp
|
7
|
-
@val=val
|
8
|
-
@min=min
|
9
|
-
@max=max
|
10
|
-
@avg=avg
|
11
|
-
@sum=sum
|
12
|
-
@cnt=cnt
|
13
|
-
end
|
14
|
-
def to_json(options = {})
|
15
|
-
millis=@timestamp.to_f * 1000
|
16
|
-
{'metricId' => @metricId,'timestamp' => millis.round, 'val' => @val,'min' => @min, 'max' => @max, 'avg' => @avg,'sum' => @sum, 'cnt' => @cnt}.to_json
|
17
|
-
end
|
18
|
-
end
|
data/lib/netuitive/ingest_tag.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'netuitive/api_emissary'
|
2
|
-
require 'netuitive/ingest_metric'
|
3
|
-
require 'netuitive/ingest_sample'
|
4
|
-
require 'netuitive/ingest_element'
|
5
|
-
require 'netuitive/ruby_config_manager'
|
6
|
-
|
7
|
-
class MetricAggregator
|
8
|
-
|
9
|
-
def initialize()
|
10
|
-
@metrics=Array.new
|
11
|
-
@samples=Array.new
|
12
|
-
@aggregatedMetrics=Array.new
|
13
|
-
@aggregatedSamples=Hash.new
|
14
|
-
@metricMutex=Mutex.new
|
15
|
-
@configManager=ConfigManager.new
|
16
|
-
@apiEmissary=APIEmissary.new(@configManager.apiId, @configManager.baseAddr, @configManager.port)
|
17
|
-
end
|
18
|
-
|
19
|
-
def sendMetrics()
|
20
|
-
@metricMutex.synchronize{
|
21
|
-
if @metrics.empty?
|
22
|
-
if @configManager.isInfo?
|
23
|
-
puts "no netuitive metrics to report"
|
24
|
-
end
|
25
|
-
return
|
26
|
-
end
|
27
|
-
aggregatedSamplesArray = @aggregatedSamples.values
|
28
|
-
aggregatedSamplesArray.each do |sample|
|
29
|
-
sample.timestamp=Time.new
|
30
|
-
end
|
31
|
-
element=IngestElement.new(@configManager.elementName, @configManager.elementName, "custom", nil, @metrics+@aggregatedMetrics, @samples+aggregatedSamplesArray, nil, nil)
|
32
|
-
elements= [element]
|
33
|
-
@apiEmissary.sendElements(elements)
|
34
|
-
clearMetrics
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def addSample(metricId, val)
|
39
|
-
@metricMutex.synchronize{
|
40
|
-
if not metricExists metricId
|
41
|
-
metric=IngestMetric.new(metricId, metricId, nil, "custom", nil, false)
|
42
|
-
@metrics.push(metric)
|
43
|
-
end
|
44
|
-
sample=IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil)
|
45
|
-
@samples.push(sample)
|
46
|
-
if @configManager.isInfo?
|
47
|
-
puts "netuitive sample added #{metricId} val: #{val}"
|
48
|
-
end
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def metricExists(metricId)
|
53
|
-
@metrics.each do |metric|
|
54
|
-
if metric.id == metricId
|
55
|
-
return true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
return false
|
59
|
-
end
|
60
|
-
|
61
|
-
def aggregateMetric(metricId, val)
|
62
|
-
@metricMutex.synchronize{
|
63
|
-
if not metricExists metricId
|
64
|
-
metric=IngestMetric.new(metricId, metricId, nil, "custom", nil, false)
|
65
|
-
@metrics.push(metric)
|
66
|
-
sample=IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil)
|
67
|
-
@aggregatedSamples["#{metricId}"]=sample
|
68
|
-
else
|
69
|
-
sample=@aggregatedSamples["#{metricId}"]
|
70
|
-
sample.val+=val
|
71
|
-
@aggregatedSamples["#{metricId}"]=sample
|
72
|
-
end
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def clearMetrics
|
77
|
-
@metrics=Array.new
|
78
|
-
@samples=Array.new
|
79
|
-
@aggregatedSamples=Hash.new
|
80
|
-
end
|
81
|
-
end
|