reacter 0.0.10 → 0.0.11
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.
- data/lib/reacter/adapters/amqp.rb +7 -6
- data/lib/reacter/adapters/http.rb +95 -0
- data/lib/reacter/adapters/socket.rb +53 -0
- data/lib/reacter/message.rb +1 -0
- data/lib/reacter/parser.rb +4 -0
- metadata +11 -9
@@ -18,12 +18,13 @@ class Reacter
|
|
18
18
|
end
|
19
19
|
|
20
20
|
@_connection = AMQP.connect({
|
21
|
-
:host
|
22
|
-
:port
|
23
|
-
:username
|
24
|
-
:password
|
25
|
-
:vhost
|
26
|
-
:timeout
|
21
|
+
:host => @config.get(:hostname, 'localhost'),
|
22
|
+
:port => @config.get(:port, 5672),
|
23
|
+
:username => @config.get(:username, 'guest'),
|
24
|
+
:password => @config.get(:password, 'guest'),
|
25
|
+
:vhost => @config.get(:vhost, '/'),
|
26
|
+
:timeout => @config.get(:timeout, DEFAULT_TIMEOUT),
|
27
|
+
:routing_key => @config.get(:timeout),
|
27
28
|
:on_tcp_connection_failure => @_errback
|
28
29
|
})
|
29
30
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#------------------------------------------------------------------------------#
|
2
|
+
# Socket Adapter
|
3
|
+
#
|
4
|
+
require 'reacter/adapter'
|
5
|
+
require 'reacter/config'
|
6
|
+
require 'reacter/util'
|
7
|
+
|
8
|
+
class Reacter
|
9
|
+
class HttpAdapter < Adapter
|
10
|
+
require 'em-http-server'
|
11
|
+
|
12
|
+
class HttpHandler < EM::HttpServer::Server
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
@callback = args.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_http_request()
|
19
|
+
begin
|
20
|
+
@callback.call({
|
21
|
+
:method => @http_request_method.to_sym,
|
22
|
+
:host => @http[:host],
|
23
|
+
:path => @http_request_uri,
|
24
|
+
:headers => @http,
|
25
|
+
:body => @http_content,
|
26
|
+
:query => Hash[(@http_query_string || '').split('&').collect{|i|
|
27
|
+
i = i.split('=')
|
28
|
+
[i[0], i[1]]
|
29
|
+
}],
|
30
|
+
})
|
31
|
+
rescue Exception => e
|
32
|
+
puts e
|
33
|
+
end
|
34
|
+
|
35
|
+
response = EM::DelegatedHttpResponse.new(self)
|
36
|
+
response.status = 200
|
37
|
+
response.send_response()
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def connect(args={})
|
43
|
+
@addr = @config.get(:address, '0.0.0.0')
|
44
|
+
@port = @config.get(:port, 8080).to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
def send(message, format=nil)
|
48
|
+
# TODO: implement this for relay support
|
49
|
+
# support: method
|
50
|
+
# output format
|
51
|
+
# destination URI (host port path querystring)
|
52
|
+
# HTTPS
|
53
|
+
# authentication (basic, SSL client cert)
|
54
|
+
# timeout
|
55
|
+
#
|
56
|
+
end
|
57
|
+
|
58
|
+
def poll(&block)
|
59
|
+
@server = EM.start_server(@addr, @port, HttpHandler, proc{|data|
|
60
|
+
if data
|
61
|
+
case data[:method]
|
62
|
+
when :GET
|
63
|
+
x, op, source, metric, value = data[:path].split('/')
|
64
|
+
|
65
|
+
if op == 'observe' or op.empty?
|
66
|
+
messages = Message.parse([{
|
67
|
+
:source => (source || data[:query]['source']),
|
68
|
+
:metric => (metric || data[:query]['metric']),
|
69
|
+
:value => (value || data[:query]['value'].to_f),
|
70
|
+
:time => (data[:query]['time'] || (Time.now.to_i * 1000)),
|
71
|
+
:attributes => data[:query].reject{|k,v|
|
72
|
+
%w{source metric value time}.include?(k)
|
73
|
+
}
|
74
|
+
}.compact])
|
75
|
+
end
|
76
|
+
|
77
|
+
when :POST, :PUT
|
78
|
+
messages = Message.parse(data[:body].gsub("\n",''))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
block.call(messages) if messages and not messages.empty?
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
def disconnect()
|
87
|
+
raise AdapterConnectionClosed
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def stdin?()
|
92
|
+
@_stdin
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#------------------------------------------------------------------------------#
|
2
|
+
# Socket Adapter
|
3
|
+
#
|
4
|
+
require 'reacter/adapter'
|
5
|
+
require 'reacter/config'
|
6
|
+
require 'reacter/util'
|
7
|
+
|
8
|
+
class Reacter
|
9
|
+
class SocketAdapter < Adapter
|
10
|
+
require 'socket'
|
11
|
+
|
12
|
+
class SocketHandler < EM::Connection
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
@callback = args.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def receive_data(data)
|
19
|
+
@callback.call(data) if @callback
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def connect(args={})
|
24
|
+
@addr = @config.get(:address, '0.0.0.0')
|
25
|
+
@port = @config.get(:port, 54546)
|
26
|
+
end
|
27
|
+
|
28
|
+
def send(message, format=nil)
|
29
|
+
# TODO: implement this for relay support
|
30
|
+
# support: host
|
31
|
+
# port
|
32
|
+
# format
|
33
|
+
# timeout
|
34
|
+
#
|
35
|
+
end
|
36
|
+
|
37
|
+
def poll(&block)
|
38
|
+
@server = EM.start_server(@addr, @port, SocketHandler, proc{|data|
|
39
|
+
messages = Message.parse(data.chomp)
|
40
|
+
block.call(messages) unless messages.empty?
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
def disconnect()
|
45
|
+
raise AdapterConnectionClosed
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def stdin?()
|
50
|
+
@_stdin
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/reacter/message.rb
CHANGED
data/lib/reacter/parser.rb
CHANGED
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.11
|
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: &11561840 !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: *11561840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: deep_merge
|
27
|
-
requirement: &
|
27
|
+
requirement: &11560640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11560640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: hashlib
|
38
|
-
requirement: &
|
38
|
+
requirement: &11560080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11560080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hiredis
|
49
|
-
requirement: &
|
49
|
+
requirement: &11589280 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11589280
|
58
58
|
description: A utility for consuming, transforming, and routing monitoring data from
|
59
59
|
various sources
|
60
60
|
email: ghetzel@outbrain.com
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- lib/reacter/adapter.rb
|
68
68
|
- lib/reacter/adapters/amqp.rb
|
69
69
|
- lib/reacter/adapters/file.rb
|
70
|
+
- lib/reacter/adapters/http.rb
|
71
|
+
- lib/reacter/adapters/socket.rb
|
70
72
|
- lib/reacter/agent.rb
|
71
73
|
- lib/reacter/agents/decider.rb
|
72
74
|
- lib/reacter/agents/filter.rb
|