netuitived 0.10.1 → 1.0.1

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.
@@ -1,43 +0,0 @@
1
- require 'net/http'
2
- require 'json'
3
- require 'netuitive/netuitived_config_manager'
4
- require 'netuitive/netuitived_logger'
5
- class APIEmissary
6
- def sendElements(elementString)
7
- NetuitiveLogger.log.debug elementString
8
- req = Net::HTTP::Post.new("/ingest/ruby/#{ConfigManager.apiId}", initheader = {'Content-Type' =>'application/json'})
9
- req.body = elementString
10
- NetuitiveLogger.log.debug "starting post"
11
- begin
12
- if ConfigManager.port =~ /(.*)nil(.*)/
13
- port = nil
14
- else
15
- port = ConfigManager.port.to_int
16
- end
17
- NetuitiveLogger.log.debug "port: #{port}"
18
- NetuitiveLogger.log.debug "path: #{req.path}"
19
- NetuitiveLogger.log.debug "addr: #{ConfigManager.baseAddr}"
20
- response = Net::HTTP.start("#{ConfigManager.baseAddr}", port, :use_ssl => true, :read_timeout => 30, :open_timeout => 30) do |http|
21
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
22
- http.ssl_version = :SSLv3
23
- http.request req
24
- end
25
- rescue => exception
26
- NetuitiveLogger.log.error "error with http post: "
27
- NetuitiveLogger.log.error exception.message
28
- NetuitiveLogger.log.error exception.backtrace
29
- end
30
- NetuitiveLogger.log.debug "post finished"
31
- if (response.code != "202" or response.code != "200")
32
- NetuitiveLogger.log.error "Response from submitting netuitive metrics to api
33
- code: #{response.code}
34
- message: #{response.message}
35
- body: #{response.body}"
36
- else
37
- NetuitiveLogger.log.info "Response from submitting netuitive metrics to api
38
- code: #{response.code}
39
- message: #{response.message}
40
- body: #{response.body}"
41
- end
42
- end
43
- end
@@ -1,10 +0,0 @@
1
- require 'json'
2
- class IngestAttribute
3
- def initialize(name, value)
4
- @name=name
5
- @value=value
6
- end
7
- def to_json(options = {})
8
- {'name' => @name, 'value' => @value}.to_json
9
- end
10
- 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
@@ -1,10 +0,0 @@
1
- require 'json'
2
- class IngestTag
3
- def initialize(name, value)
4
- @name=name
5
- @value=value
6
- end
7
- def to_json(options = {})
8
- {'name' => @name, 'value' => @value}.to_json
9
- end
10
- end
@@ -1,146 +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/netuitived_config_manager'
6
- require 'netuitive/netuitived_logger'
7
-
8
- class MetricAggregator
9
-
10
- def initialize()
11
- @metrics=Array.new
12
- @samples=Array.new
13
- @aggregatedSamples=Hash.new
14
- @metricMutex=Mutex.new
15
- @apiEmissary=APIEmissary.new
16
- end
17
-
18
- def sendMetrics()
19
- elementString=nil
20
- addSample("netuitive.collection_interval", ConfigManager.interval)
21
- @metricMutex.synchronize{
22
- NetuitiveLogger.log.debug "self: #{self.object_id}"
23
- NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
24
- NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
25
- NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
26
- NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
27
- NetuitiveLogger.log.debug "metrics before send: #{@metrics.count}"
28
- NetuitiveLogger.log.debug "samples before send: #{@aggregatedSamples.count + @samples.count}"
29
-
30
- if @metrics.empty?
31
- NetuitiveLogger.log.info "no netuitive metrics to report"
32
- return
33
- end
34
- aggregatedSamplesArray = @aggregatedSamples.values
35
- aggregatedSamplesArray.each do |sample|
36
- sample.timestamp=Time.new
37
- end
38
- element=IngestElement.new(ConfigManager.elementName, ConfigManager.elementName, "Ruby", nil, @metrics, @samples+aggregatedSamplesArray, nil, nil)
39
- elements= [element]
40
- elementString=elements.to_json
41
- clearMetrics
42
- }
43
- @apiEmissary.sendElements(elementString)
44
- end
45
-
46
- def addSample(metricId, val)
47
- addSampleWithType(metricId, val, "GAUGE")
48
- end
49
-
50
- def addCounterSample(metricId, val)
51
- addSampleWithType(metricId, val, "COUNTER")
52
- end
53
-
54
- def addSampleWithType(metricId, val, type)
55
- @metricMutex.synchronize{
56
- NetuitiveLogger.log.debug "start addSample method"
57
- NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
58
- NetuitiveLogger.log.debug "self: #{self.object_id}"
59
- NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
60
- NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
61
- NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
62
- NetuitiveLogger.log.debug "metrics before add: #{@metrics.count}"
63
- NetuitiveLogger.log.debug "samples before add: #{@aggregatedSamples.count + @samples.count}"
64
- if metricId == nil
65
- NetuitiveLogger.log.info "null metricId for addSample"
66
- return false
67
- end
68
- if val == nil
69
- NetuitiveLogger.log.info "null value for addSample for metricId #{metricId}"
70
- return false
71
- end
72
- if not metricExists metricId
73
- NetuitiveLogger.log.info "adding new metric: #{metricId}"
74
- @metrics.push(IngestMetric.new(metricId, metricId, nil, type, nil, false))
75
- end
76
- @samples.push(IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil))
77
- NetuitiveLogger.log.info "netuitive sample added #{metricId} val: #{val}"
78
- NetuitiveLogger.log.debug "metrics after add: #{@metrics.count}"
79
- NetuitiveLogger.log.debug "samples after add: #{@aggregatedSamples.count + @samples.count}"
80
- NetuitiveLogger.log.debug "end addSample method"
81
- }
82
- end
83
-
84
- def metricExists(metricId)
85
- @metrics.each do |metric|
86
- if metric.id == metricId
87
- return true
88
- end
89
- end
90
- return false
91
- end
92
-
93
- def aggregateMetric(metricId, val)
94
- aggregateMetricWithType(metricId, val, "GAUGE")
95
- end
96
-
97
- def aggregateCounterMetric(metricId, val)
98
- aggregateMetricWithType(metricId, val, "COUNTER")
99
- end
100
-
101
- def aggregateMetricWithType(metricId, val, type)
102
- @metricMutex.synchronize{
103
- NetuitiveLogger.log.debug "start addSample method"
104
- NetuitiveLogger.log.debug "Thread: #{Thread.current.object_id}"
105
- NetuitiveLogger.log.debug "self: #{self.object_id}"
106
- NetuitiveLogger.log.debug "metrics id: #{@metrics.object_id}"
107
- NetuitiveLogger.log.debug "samples id: #{@samples.object_id}"
108
- NetuitiveLogger.log.debug "aggregatedSamples id: #{@aggregatedSamples.object_id}"
109
- NetuitiveLogger.log.debug "metrics before aggregate: #{@metrics.count}"
110
- NetuitiveLogger.log.debug "samples before aggregate: #{@aggregatedSamples.count + @samples.count}"
111
- if metricId == nil
112
- NetuitiveLogger.log.info "null metricId for aggregateMetric"
113
- return false
114
- end
115
- if val == nil
116
- NetuitiveLogger.log.info "null value for aggregateMetric for metricId #{metricId}"
117
- return false
118
- end
119
- if not metricExists metricId
120
- NetuitiveLogger.log.info "adding new metric: #{metricId}"
121
- @metrics.push(IngestMetric.new(metricId, metricId, nil, type, nil, false))
122
- @aggregatedSamples["#{metricId}"]=IngestSample.new(metricId, Time.new, val, nil, nil, nil, nil, nil)
123
- else
124
- if @aggregatedSamples["#{metricId}"] == nil
125
- NetuitiveLogger.log.info "cannot aggregate metric #{metricId} that already has samples for this interval"
126
- return false
127
- end
128
- previousVal = @aggregatedSamples["#{metricId}"].val
129
- @aggregatedSamples["#{metricId}"].val+=val
130
- NetuitiveLogger.log.info "netuitive sample aggregated #{metricId} old val: #{previousVal} new val: #{@aggregatedSamples["#{metricId}"].val}"
131
- end
132
- NetuitiveLogger.log.debug "metrics after aggregate: #{@metrics.count}"
133
- NetuitiveLogger.log.debug "samples after aggregate: #{@aggregatedSamples.count + @samples.count}"
134
- NetuitiveLogger.log.debug "end addSample method"
135
- }
136
- end
137
-
138
- def clearMetrics
139
- NetuitiveLogger.log.debug "start clearMetrics method"
140
- @metrics=Array.new
141
- @samples=Array.new
142
- @aggregatedSamples=Hash.new
143
- NetuitiveLogger.log.info "netuitive metrics cleared"
144
- NetuitiveLogger.log.debug "end clearMetrics method"
145
- end
146
- end
@@ -1,92 +0,0 @@
1
- require 'yaml'
2
- require 'netuitive/netuitived_logger'
3
- class ConfigManager
4
-
5
- class << self
6
- def setup()
7
- readConfig()
8
- end
9
-
10
- def apiId
11
- @@apiId
12
- end
13
-
14
- def baseAddr
15
- @@baseAddr
16
- end
17
-
18
- def port
19
- @@port
20
- end
21
-
22
- def elementName
23
- @@elementName
24
- end
25
-
26
- def netuitivedAddr
27
- @@netuitivedAddr
28
- end
29
-
30
- def netuitivedPort
31
- @@netuitivedPort
32
- end
33
-
34
- def interval
35
- @@interval
36
- end
37
-
38
- def readConfig()
39
- gem_root= File.expand_path("../../..", __FILE__)
40
- data=YAML.load_file "#{gem_root}/config/agent.yml"
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}"
75
- if debugLevelString == "error"
76
- NetuitiveLogger.log.level = Logger::ERROR
77
- elsif debugLevelString == "info"
78
- NetuitiveLogger.log.level = Logger::INFO
79
- elsif debugLevelString == "debug"
80
- NetuitiveLogger.log.level = Logger::DEBUG
81
- else
82
- NetuitiveLogger.log.level = Logger::ERROR
83
- end
84
- NetuitiveLogger.log.debug "read config file. Results:
85
- apiId: #{apiId}
86
- baseAddr: #{baseAddr}
87
- port: #{port}
88
- elementName: #{elementName}
89
- debugLevel: #{debugLevelString}"
90
- end
91
- end
92
- end
@@ -1,24 +0,0 @@
1
- require 'logger'
2
- class CheaterLogger
3
- attr_accessor :level
4
- def debug(message)
5
- end
6
- def error(message)
7
- end
8
- def info(message)
9
- end
10
- end
11
-
12
- class NetuitiveLogger
13
- begin
14
- @@log = Logger.new("#{File.expand_path("../../..", __FILE__)}/log/netuitive.log",'daily', 10)
15
- rescue
16
- puts "netuitive unable to open log file"
17
- @@log = CheaterLogger.new
18
- end
19
- class << self
20
- def log
21
- return @@log
22
- end
23
- end
24
- end
@@ -1,53 +0,0 @@
1
- require 'netuitive/metric_aggregator'
2
- require 'netuitive/netuitived_logger'
3
- require 'netuitive/netuitived_config_manager'
4
- class NetuitivedServer
5
-
6
- def initialize()
7
- @metricAggregator = MetricAggregator.new
8
- end
9
-
10
- def sendMetrics()
11
- @metricAggregator.sendMetrics
12
- end
13
-
14
- def addSample(metricId, val)
15
- @metricAggregator.addSample(metricId, val)
16
- end
17
-
18
- def addCounterSample(metricId, val)
19
- @metricAggregator.addCounterSample(metricId, val)
20
- end
21
-
22
- def aggregateMetric(metricId, val)
23
- @metricAggregator.aggregateMetric(metricId, val)
24
- end
25
-
26
- def aggregateCounterMetric(metricId, val)
27
- @metricAggregator.aggregateCounterMetric(metricId, val)
28
- end
29
-
30
- def clearMetrics
31
- @metricAggregator.clearMetrics
32
- end
33
-
34
- def interval()
35
- return ConfigManager.interval
36
- end
37
-
38
- def stopServer
39
- Thread.new do
40
- exitProcess
41
- end
42
- end
43
-
44
- def exitProcess
45
- sleep(1)
46
- NetuitiveLogger.log.info "stopping netuitived"
47
- Process.exit!(true)
48
- end
49
-
50
- private :exitProcess
51
-
52
- end
53
-
@@ -1,14 +0,0 @@
1
- require 'netuitive/netuitived_config_manager'
2
- require 'drb/drb'
3
- class Scheduler
4
- def self.startSchedule
5
- Thread.new do
6
- while true do
7
- sleep(ConfigManager.interval)
8
- Thread.new do
9
- FRONT_OBJECT.sendMetrics
10
- end
11
- end
12
- end
13
- end
14
- end