netuitived 0.9.3 → 0.9.4
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/bin/netuitived +40 -0
- data/config/agent.yml +9 -8
- data/lib/netuitive/api_emissary.rb +11 -11
- data/lib/netuitive/metric_aggregator.rb +38 -63
- data/lib/netuitive/netuitived_config_manager.rb +40 -41
- data/lib/netuitive/netuitived_logger.rb +23 -0
- data/lib/netuitive/netuitived_server.rb +15 -1
- data/log/netuitive.log +0 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 271aaf503bc348eb7535765a23b5eab9ea281c42
|
4
|
+
data.tar.gz: 027dfde32ce851a332d10551aabe18f8a9f8ac27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03268b422fd9e8a5f9df25efb5f60b2c764c3c6b4d4960e8db733b35c40cd28ec686949fb19d059866ab0963e861100cfa0632dc60b37e76f346c19a26bdd163
|
7
|
+
data.tar.gz: 84207609a064ae447dd14b6c3a3e40eb9503d6e1fcc1b2a60e4036c2d5d514407dfcce6b7101d0c19cd8e25faf56c952d2d15b0226dfd5ca746827d70f157924
|
data/bin/netuitived
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
gem_root= File.expand_path("../..", __FILE__)
|
4
|
+
data=YAML.load_file "#{gem_root}/config/agent.yml"
|
5
|
+
if ARGV[0] == "start"
|
6
|
+
written = false
|
7
|
+
elementName=ENV["NETUITIVED_ELEMENT_NAME"]
|
8
|
+
if(elementName == nil or elementName == "")
|
9
|
+
elementName = data["elementName"]
|
10
|
+
if(elementName == "elementName" or elementName == "")
|
11
|
+
puts "please enter an element name: "
|
12
|
+
elementName = STDIN.gets.chomp
|
13
|
+
data["elementName"] = elementName
|
14
|
+
written = true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
apiId=ENV["NETUITIVED_API_ID"]
|
18
|
+
if(apiId == nil or apiId == "")
|
19
|
+
apiId = data["apiId"]
|
20
|
+
if(apiId == "apiId" or apiId == "")
|
21
|
+
puts "please enter an api key: "
|
22
|
+
apiId = STDIN.gets.chomp
|
23
|
+
data["apiId"] = apiId
|
24
|
+
written = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
if written
|
28
|
+
File.open("#{gem_root}/config/agent.yml", 'w') {|f| f.write data.to_yaml }
|
29
|
+
end
|
30
|
+
require 'netuitived'
|
31
|
+
elsif ARGV[0] == "stop"
|
32
|
+
require 'drb/drb'
|
33
|
+
netuitivedAddr=data["netuitivedAddr"]
|
34
|
+
netuitivedPort=data["netuitivedPort"]
|
35
|
+
SERVER_URI="druby://#{netuitivedAddr}:#{netuitivedPort}"
|
36
|
+
DRb.start_service
|
37
|
+
DRbObject.new_with_uri(SERVER_URI).stopServer
|
38
|
+
else
|
39
|
+
puts "invalid option. options are: start, stop"
|
40
|
+
end
|
data/config/agent.yml
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
#all are configurable using environment variables
|
2
|
+
apiId: apiId #apiId for the datasources. found in the datasources section in the netuitive ui. environment variable: NETUITIVED_API_ID
|
3
|
+
baseAddr: "api.app.netuitive.com" #where to send the data. in most cases use the default. environment variable: NETUITIVED_BASE_ADDR
|
4
|
+
port: nil #in most cases this will be nil. environment variable: NETUITIVED_PORT
|
5
|
+
elementName: elementName #name of the element to assign metrics to in netuitive. if unsure, just use the name of your app. environment variable: NETUITIVED_ELEMENT_NAME
|
6
|
+
debugLevel: error #options (in ascending order of debugness) are: error, info, debug. environment variable: NETUITIVED_DEBUG_LEVEL
|
7
|
+
netuitivedAddr: "localhost" #environment variable: NETUITIVED_NETUITIVED_ADDR
|
8
|
+
netuitivedPort: 8875 #environment variable: NETUITIVED_NETUITIVED_PORT
|
9
|
+
interval: 60 #environment variable: NETUITIVED_INTERVAL
|
9
10
|
|
@@ -1,16 +1,13 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
require 'netuitive/netuitived_config_manager'
|
4
|
+
require 'netuitive/netuitived_logger'
|
4
5
|
class APIEmissary
|
5
6
|
def sendElements(elementString)
|
6
|
-
|
7
|
-
puts elementString
|
8
|
-
end
|
7
|
+
NetuitiveLogger.log.debug elementString
|
9
8
|
req = Net::HTTP::Post.new("/ingest/#{ConfigManager.apiId}", initheader = {'Content-Type' =>'application/json'})
|
10
9
|
req.body = elementString
|
11
|
-
|
12
|
-
puts "starting post"
|
13
|
-
end
|
10
|
+
NetuitiveLogger.log.debug "starting post"
|
14
11
|
if ConfigManager.port =~ /(.*)nil(.*)/
|
15
12
|
port = nil
|
16
13
|
else
|
@@ -21,11 +18,14 @@ class APIEmissary
|
|
21
18
|
http.ssl_version = :SSLv3
|
22
19
|
http.request req
|
23
20
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
NetuitiveLogger.log.debug "post finished"
|
22
|
+
if (response.code != "202")
|
23
|
+
NetuitiveLogger.log.error "Response from submitting netuitive metrics to api
|
24
|
+
code: #{response.code}
|
25
|
+
message: #{response.message}
|
26
|
+
body: #{response.body}"
|
27
|
+
else
|
28
|
+
NetuitiveLogger.log.info "Response from submitting netuitive metrics to api
|
29
29
|
code: #{response.code}
|
30
30
|
message: #{response.message}
|
31
31
|
body: #{response.body}"
|
@@ -3,6 +3,7 @@ require 'netuitive/ingest_metric'
|
|
3
3
|
require 'netuitive/ingest_sample'
|
4
4
|
require 'netuitive/ingest_element'
|
5
5
|
require 'netuitive/netuitived_config_manager'
|
6
|
+
require 'netuitive/netuitived_logger'
|
6
7
|
|
7
8
|
class MetricAggregator
|
8
9
|
|
@@ -17,20 +18,16 @@ class MetricAggregator
|
|
17
18
|
def sendMetrics()
|
18
19
|
elementString=nil
|
19
20
|
@metricMutex.synchronize{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts "samples before send: #{@aggregatedSamples.count + @samples.count}"
|
28
|
-
end
|
21
|
+
NetuitiveLogger.log.debug "self: #{self.object_id}"
|
22
|
+
NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
|
23
|
+
NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
|
24
|
+
NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
|
25
|
+
NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
|
26
|
+
NetuitiveLogger.log.debug "metrics before send: #{@metrics.count}"
|
27
|
+
NetuitiveLogger.log.debug "samples before send: #{@aggregatedSamples.count + @samples.count}"
|
29
28
|
|
30
29
|
if @metrics.empty?
|
31
|
-
|
32
|
-
puts "no netuitive metrics to report"
|
33
|
-
end
|
30
|
+
NetuitiveLogger.log.info "no netuitive metrics to report"
|
34
31
|
return
|
35
32
|
end
|
36
33
|
aggregatedSamplesArray = @aggregatedSamples.values
|
@@ -47,31 +44,23 @@ class MetricAggregator
|
|
47
44
|
|
48
45
|
def addSample(metricId, val)
|
49
46
|
@metricMutex.synchronize{
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
puts "samples before add: #{@aggregatedSamples.count + @samples.count}"
|
59
|
-
end
|
47
|
+
NetuitiveLogger.log.debug "start addSample method"
|
48
|
+
NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
|
49
|
+
NetuitiveLogger.log.debug "self: #{self.object_id}"
|
50
|
+
NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
|
51
|
+
NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
|
52
|
+
NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
|
53
|
+
NetuitiveLogger.log.debug "metrics before add: #{@metrics.count}"
|
54
|
+
NetuitiveLogger.log.debug "samples before add: #{@aggregatedSamples.count + @samples.count}"
|
60
55
|
if not metricExists metricId
|
61
|
-
|
62
|
-
puts "adding new metric: #{metricId}"
|
63
|
-
end
|
56
|
+
NetuitiveLogger.log.info "adding new metric: #{metricId}"
|
64
57
|
@metrics.push(IngestMetric.new(metricId, metricId, nil, "custom", nil, false))
|
65
58
|
end
|
66
59
|
@samples.push(IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil))
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
puts "metrics after add: #{@metrics.count}"
|
72
|
-
puts "samples after add: #{@aggregatedSamples.count + @samples.count}"
|
73
|
-
puts "end addSample method"
|
74
|
-
end
|
60
|
+
NetuitiveLogger.log.info "netuitive sample added #{metricId} val: #{val}"
|
61
|
+
NetuitiveLogger.log.debug "metrics after add: #{@metrics.count}"
|
62
|
+
NetuitiveLogger.log.debug "samples after add: #{@aggregatedSamples.count + @samples.count}"
|
63
|
+
NetuitiveLogger.log.debug "end addSample method"
|
75
64
|
}
|
76
65
|
end
|
77
66
|
|
@@ -86,49 +75,35 @@ class MetricAggregator
|
|
86
75
|
|
87
76
|
def aggregateMetric(metricId, val)
|
88
77
|
@metricMutex.synchronize{
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
puts "samples before aggregate: #{@aggregatedSamples.count + @samples.count}"
|
98
|
-
end
|
78
|
+
NetuitiveLogger.log.debug "start addSample method"
|
79
|
+
NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
|
80
|
+
NetuitiveLogger.log.debug "self: #{self.object_id}"
|
81
|
+
NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
|
82
|
+
NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
|
83
|
+
NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
|
84
|
+
NetuitiveLogger.log.debug "metrics before aggregate: #{@metrics.count}"
|
85
|
+
NetuitiveLogger.log.debug "samples before aggregate: #{@aggregatedSamples.count + @samples.count}"
|
99
86
|
if not metricExists metricId
|
100
|
-
|
101
|
-
puts "adding new metric: #{metricId}"
|
102
|
-
end
|
87
|
+
NetuitiveLogger.log.info "adding new metric: #{metricId}"
|
103
88
|
@metrics.push(IngestMetric.new(metricId, metricId, nil, "custom", nil, false))
|
104
89
|
@aggregatedSamples["#{metricId}"]=IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil)
|
105
90
|
else
|
106
91
|
previousVal = @aggregatedSamples["#{metricId}"].val
|
107
92
|
@aggregatedSamples["#{metricId}"].val+=val
|
108
|
-
|
109
|
-
puts "netuitive sample aggregated #{metricId} old val: #{previousVal} new val: #{@aggregatedSamples["#{metricId}"].val}"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
if ConfigManager.isDebug?
|
113
|
-
puts "metrics after aggregate: #{@metrics.count}"
|
114
|
-
puts "samples after aggregate: #{@aggregatedSamples.count + @samples.count}"
|
115
|
-
puts "end addSample method"
|
93
|
+
NetuitiveLogger.log.info "netuitive sample aggregated #{metricId} old val: #{previousVal} new val: #{@aggregatedSamples["#{metricId}"].val}"
|
116
94
|
end
|
95
|
+
NetuitiveLogger.log.debug "metrics after aggregate: #{@metrics.count}"
|
96
|
+
NetuitiveLogger.log.debug "samples after aggregate: #{@aggregatedSamples.count + @samples.count}"
|
97
|
+
NetuitiveLogger.log.debug "end addSample method"
|
117
98
|
}
|
118
99
|
end
|
119
100
|
|
120
101
|
def clearMetrics
|
121
|
-
|
122
|
-
puts "start clearMetrics method"
|
123
|
-
end
|
102
|
+
NetuitiveLogger.log.debug "start clearMetrics method"
|
124
103
|
@metrics=Array.new
|
125
104
|
@samples=Array.new
|
126
105
|
@aggregatedSamples=Hash.new
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
if ConfigManager.isDebug?
|
131
|
-
puts "end clearMetrics method"
|
132
|
-
end
|
106
|
+
NetuitiveLogger.log.info "netuitive metrics cleared"
|
107
|
+
NetuitiveLogger.log.debug "end clearMetrics method"
|
133
108
|
end
|
134
109
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'netuitive/netuitived_logger'
|
2
3
|
class ConfigManager
|
3
4
|
|
4
5
|
class << self
|
5
6
|
def setup()
|
6
|
-
@@error=0
|
7
|
-
@@info=1
|
8
|
-
@@debug=2
|
9
7
|
readConfig()
|
10
8
|
end
|
11
9
|
|
@@ -37,57 +35,58 @@ class ConfigManager
|
|
37
35
|
@@interval
|
38
36
|
end
|
39
37
|
|
40
|
-
def isDebug?
|
41
|
-
if @@debugLevel >= @@debug
|
42
|
-
return true
|
43
|
-
end
|
44
|
-
return false
|
45
|
-
end
|
46
|
-
|
47
|
-
def isInfo?
|
48
|
-
if @@debugLevel >= @@info
|
49
|
-
return true
|
50
|
-
end
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
|
54
|
-
def isError?
|
55
|
-
if @@debugLevel >= @@error
|
56
|
-
return true
|
57
|
-
end
|
58
|
-
return false
|
59
|
-
end
|
60
|
-
|
61
38
|
def readConfig()
|
62
39
|
gem_root= File.expand_path("../../..", __FILE__)
|
63
40
|
data=YAML.load_file "#{gem_root}/config/agent.yml"
|
64
|
-
@@apiId=
|
65
|
-
@@
|
66
|
-
|
67
|
-
|
68
|
-
@@
|
69
|
-
@@
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
41
|
+
@@apiId=ENV["NETUITIVED_API_ID"]
|
42
|
+
if(@@apiId == nil or @@apiId == "")
|
43
|
+
@@apiId=data["apiId"]
|
44
|
+
end
|
45
|
+
@@baseAddr=ENV["NETUITIVED_BASE_ADDR"]
|
46
|
+
if(@@baseAddr == nil or @@baseAddr == "")
|
47
|
+
@@baseAddr=data["baseAddr"]
|
48
|
+
end
|
49
|
+
@@port=ENV["NETUITIVED_PORT"]
|
50
|
+
if(@@port == nil or @@port == "")
|
51
|
+
@@port=data["port"]
|
52
|
+
end
|
53
|
+
@@elementName=ENV["NETUITIVED_ELEMENT_NAME"]
|
54
|
+
if(@@elementName == nil or @@elementName == "")
|
55
|
+
@@elementName=data["elementName"]
|
56
|
+
end
|
57
|
+
@@netuitivedAddr=ENV["NETUITIVED_NETUITIVED_ADDR"]
|
58
|
+
if(@@netuitivedAddr == nil or @@netuitivedAddr == "")
|
59
|
+
@@netuitivedAddr=data["netuitivedAddr"]
|
60
|
+
end
|
61
|
+
@@netuitivedPort=ENV["NETUITIVED_NETUITIVED_PORT"]
|
62
|
+
if(@@netuitivedPort == nil or @@netuitivedPort == "")
|
63
|
+
@@netuitivedPort=data["netuitivedPort"]
|
64
|
+
end
|
65
|
+
@@interval=ENV["NETUITIVED_INTERVAL"]
|
66
|
+
if(@@interval == nil or @@interval == "")
|
67
|
+
@@interval=data["interval"]
|
68
|
+
end
|
69
|
+
debugLevelString=ENV["NETUITIVED_DEBUG_LEVEL"]
|
70
|
+
if(debugLevelString == nil or debugLevelString == "")
|
71
|
+
debugLevelString=data["debugLevel"]
|
72
|
+
end
|
73
|
+
NetuitiveLogger.log.info "port: #{@@netuitivedPort}"
|
74
|
+
NetuitiveLogger.log.info "addr: #{@@netuitivedAddr}"
|
74
75
|
if debugLevelString == "error"
|
75
|
-
|
76
|
+
NetuitiveLogger.log.level = Logger::ERROR
|
76
77
|
elsif debugLevelString == "info"
|
77
|
-
|
78
|
+
NetuitiveLogger.log.level = Logger::INFO
|
78
79
|
elsif debugLevelString == "debug"
|
79
|
-
|
80
|
+
NetuitiveLogger.log.level = Logger::DEBUG
|
80
81
|
else
|
81
|
-
|
82
|
+
NetuitiveLogger.log.level = Logger::ERROR
|
82
83
|
end
|
83
|
-
|
84
|
-
puts "read config file. Results:
|
84
|
+
NetuitiveLogger.log.debug "read config file. Results:
|
85
85
|
apiId: #{apiId}
|
86
86
|
baseAddr: #{baseAddr}
|
87
87
|
port: #{port}
|
88
88
|
elementName: #{elementName}
|
89
89
|
debugLevel: #{debugLevelString}"
|
90
|
-
end
|
91
90
|
end
|
92
91
|
end
|
93
92
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'logger'
|
2
|
+
class NetuitiveLogger
|
3
|
+
begin
|
4
|
+
@@log = Logger.new("#{File.expand_path("../../..", __FILE__)}/log/netuitive.log",'daily', 10)
|
5
|
+
rescue
|
6
|
+
puts "netuitive unable to open log file"
|
7
|
+
@@log = CheaterLogger.new
|
8
|
+
end
|
9
|
+
class << self
|
10
|
+
def log
|
11
|
+
return @@log
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class CheaterLogger
|
17
|
+
def debug(message)
|
18
|
+
end
|
19
|
+
def error(message)
|
20
|
+
end
|
21
|
+
def info(message)
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'netuitive/metric_aggregator'
|
2
|
-
|
2
|
+
require 'netuitive/netuitived_logger'
|
3
3
|
class NetuitivedServer
|
4
4
|
|
5
5
|
def initialize()
|
@@ -22,5 +22,19 @@ class NetuitivedServer
|
|
22
22
|
@metricAggregator.clearMetrics
|
23
23
|
end
|
24
24
|
|
25
|
+
def stopServer
|
26
|
+
Thread.new do
|
27
|
+
exitProcess
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def exitProcess
|
32
|
+
sleep(1)
|
33
|
+
NetuitiveLogger.log.info "stopping netuitived"
|
34
|
+
Process.exit!(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
private :exitProcess
|
38
|
+
|
25
39
|
end
|
26
40
|
|
data/log/netuitive.log
ADDED
File without changes
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netuitived
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
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-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Collects metrics over a certain interval and then sends them to Netuitive
|
14
14
|
email: jking@netuitive.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- netuitived
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
@@ -24,11 +25,14 @@ files:
|
|
24
25
|
- lib/netuitive/ingest_tag.rb
|
25
26
|
- lib/netuitive/metric_aggregator.rb
|
26
27
|
- lib/netuitive/netuitived_config_manager.rb
|
28
|
+
- lib/netuitive/netuitived_logger.rb
|
27
29
|
- lib/netuitive/netuitived_server.rb
|
28
30
|
- lib/netuitive/scheduler.rb
|
29
31
|
- lib/netuitived.rb
|
30
32
|
- config/agent.yml
|
31
33
|
- "./LICENSE"
|
34
|
+
- log/netuitive.log
|
35
|
+
- bin/netuitived
|
32
36
|
homepage: http://rubygems.org/gems/netuitived
|
33
37
|
licenses:
|
34
38
|
- Apache v2.0
|