reacter 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/reacter/adapters/amqp.rb +3 -1
- data/lib/reacter/adapters/http.rb +37 -0
- data/lib/reacter/adapters/socket.rb +1 -0
- data/lib/reacter/agents/logger.rb +1 -1
- data/lib/reacter/core.rb +3 -0
- data/lib/reacter/message.rb +7 -2
- data/lib/reacter/parsers/json.rb +1 -1
- data/lib/reacter/parsers/kairosdb.rb +1 -1
- data/lib/reacter/parsers/logstash.rb +52 -0
- metadata +27 -15
@@ -45,7 +45,9 @@ class Reacter
|
|
45
45
|
|
46
46
|
def poll(&block)
|
47
47
|
@_queue.bind(@_exchange).subscribe do |payload|
|
48
|
-
|
48
|
+
format = @config.get(:format)
|
49
|
+
format = format.to_sym unless format.nil?
|
50
|
+
yield Message.as(format).parse(payload)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#------------------------------------------------------------------------------#
|
2
2
|
# Socket Adapter
|
3
3
|
#
|
4
|
+
require 'em-http-request'
|
4
5
|
require 'reacter/adapter'
|
5
6
|
require 'reacter/config'
|
6
7
|
require 'reacter/util'
|
@@ -42,9 +43,45 @@ class Reacter
|
|
42
43
|
def connect(args={})
|
43
44
|
@addr = @config.get(:address, '0.0.0.0')
|
44
45
|
@port = @config.get(:port, 8080).to_i
|
46
|
+
@buffer = []
|
47
|
+
|
48
|
+
if args[:mode] == 'write'
|
49
|
+
@writer = EventMachine::HttpRequest.new(@config.get('write.url'))
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def send(message, format=nil)
|
54
|
+
if defined?(@writer)
|
55
|
+
if (sz = @config.get(:buffersize))
|
56
|
+
if @buffer.length == sz
|
57
|
+
payload = @buffer.join(@config.get('write.joiner', "\n"))
|
58
|
+
@buffer = []
|
59
|
+
else
|
60
|
+
@buffer << Message.dump(message, format)
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
else
|
64
|
+
payload = Message.dump(message, format)
|
65
|
+
end
|
66
|
+
|
67
|
+
if @config.get('write.template')
|
68
|
+
payload = @config.get('write.template').gsub('%{content}', payload)
|
69
|
+
end
|
70
|
+
|
71
|
+
method = @config.get('write.method', :post).to_sym
|
72
|
+
|
73
|
+
case method
|
74
|
+
when :post, :put
|
75
|
+
@writer.send(method, {
|
76
|
+
:body => payload
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
return true
|
81
|
+
else
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
|
48
85
|
# TODO: implement this for relay support
|
49
86
|
# support: method
|
50
87
|
# output format
|
@@ -22,7 +22,7 @@ class Reacter
|
|
22
22
|
|
23
23
|
def received(message)
|
24
24
|
if @output_format.nil?
|
25
|
-
line = "logger: [#{message.
|
25
|
+
line = "logger: [#{message.time.to_i}] #{message.source}/#{message.metric} = #{message.value}"
|
26
26
|
else
|
27
27
|
line = Message.dump(message, @output_format)
|
28
28
|
end
|
data/lib/reacter/core.rb
CHANGED
@@ -63,8 +63,11 @@ class Reacter
|
|
63
63
|
|
64
64
|
# agent message dispatch subprocess
|
65
65
|
dispatch = proc do |messages|
|
66
|
+
messages = [messages] unless messages.is_a?(Array)
|
67
|
+
|
66
68
|
messages.each do |message|
|
67
69
|
rv = message
|
70
|
+
rv = Message.new(rv) unless rv.is_a?(Message)
|
68
71
|
|
69
72
|
# send this message to all agents
|
70
73
|
@_agents.each do |agent|
|
data/lib/reacter/message.rb
CHANGED
@@ -44,6 +44,11 @@ class Reacter
|
|
44
44
|
@_format = format
|
45
45
|
end
|
46
46
|
|
47
|
+
def as(format)
|
48
|
+
load_parsers()
|
49
|
+
(@@_parsers[format] || Message)
|
50
|
+
end
|
51
|
+
|
47
52
|
def load_parsers()
|
48
53
|
unless defined?(@@_parsers)
|
49
54
|
@@_parsers = {}
|
@@ -93,10 +98,10 @@ class Reacter
|
|
93
98
|
# use first parser that claims it can handle this string
|
94
99
|
@@_parsers.each do |name, parser|
|
95
100
|
if parser.detected?(message)
|
96
|
-
|
101
|
+
Util.debug("Using parser #{name}")
|
97
102
|
m = parser.parse(message)
|
98
103
|
(m.is_a?(Array) ? messages += m : messages << m)
|
99
|
-
|
104
|
+
break
|
100
105
|
end
|
101
106
|
end
|
102
107
|
|
data/lib/reacter/parsers/json.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'reacter/parser'
|
3
|
+
|
4
|
+
class Reacter
|
5
|
+
class Message
|
6
|
+
class LogstashParser < Parser
|
7
|
+
class<<self
|
8
|
+
require 'multi_json'
|
9
|
+
require 'oj'
|
10
|
+
|
11
|
+
def detected?(message)
|
12
|
+
message.include?('@fields')
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(message)
|
16
|
+
message = Hash[MultiJson.load(message)]
|
17
|
+
|
18
|
+
return {
|
19
|
+
:metric => message.get(@config.get(:metric, '@fields.name')),
|
20
|
+
:source => message.get(@config.get(:source, '@fields.host')),
|
21
|
+
:time => Time.parse(message.get(@config.get(:timestamp, '@timestamp'))).to_i,
|
22
|
+
:value => message.get(@config.get(:timestamp, '@fields.value')),
|
23
|
+
:attributes => message.get('@fields', {}).merge({
|
24
|
+
'tags' => message.get('tags', [])
|
25
|
+
})
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump(message)
|
30
|
+
return "LOGSTASH DUMP"
|
31
|
+
message = message.to_h if message.is_a?(Message)
|
32
|
+
return nil unless message.is_a?(Hash)
|
33
|
+
return nil unless message[:source]
|
34
|
+
return nil unless message[:metric]
|
35
|
+
return nil unless message[:value]
|
36
|
+
return nil unless message[:time]
|
37
|
+
|
38
|
+
# attributes = {
|
39
|
+
# :host => message[:source]
|
40
|
+
# }.merge(message[:attributes] || {})
|
41
|
+
|
42
|
+
# MultiJson.dump({
|
43
|
+
# :name => message[:metric],
|
44
|
+
# :timestamp => message[:time].to_i,
|
45
|
+
# :value => message[:value],
|
46
|
+
# :tags => attributes
|
47
|
+
# })
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reacter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-03-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &7808000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7808000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: em-http-server
|
27
|
-
requirement: &
|
27
|
+
requirement: &7805180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7805180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: em-http-request
|
38
|
+
requirement: &7802460 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *7802460
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: deep_merge
|
38
|
-
requirement: &
|
49
|
+
requirement: &7733280 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :runtime
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *7733280
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: hashlib
|
49
|
-
requirement: &
|
60
|
+
requirement: &7731840 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :runtime
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *7731840
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: hiredis
|
60
|
-
requirement: &
|
71
|
+
requirement: &7754180 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :runtime
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *7754180
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: multi_json
|
71
|
-
requirement: &
|
82
|
+
requirement: &7753480 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :runtime
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *7753480
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: oj
|
82
|
-
requirement: &
|
93
|
+
requirement: &7753060 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,7 +98,7 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :runtime
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *7753060
|
91
102
|
description: A utility for consuming, transforming, and routing monitoring data from
|
92
103
|
various sources
|
93
104
|
email: ghetzel@outbrain.com
|
@@ -117,6 +128,7 @@ files:
|
|
117
128
|
- lib/reacter/parsers/json.rb
|
118
129
|
- lib/reacter/parsers/tsdb.rb
|
119
130
|
- lib/reacter/parsers/kairosdb.rb
|
131
|
+
- lib/reacter/parsers/logstash.rb
|
120
132
|
- lib/reacter/util.rb
|
121
133
|
- bin/reacter
|
122
134
|
homepage: http://outbrain.github.com/reacter/
|