reacter 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 705e53e181d608617873b15bfd3cf551c63f6b0f
4
+ data.tar.gz: b294a6dadfdc57f23a12e3e9c7eb88c7ff1bbcbf
5
+ SHA512:
6
+ metadata.gz: 8a4f7b6cb348e915b831e14e8655ae42614b6af505357ab1d6eda503815183ffc75c178d9ebed2a1dffe1814ebfade07cac6c1c801ee482f20d546d9c417e957
7
+ data.tar.gz: c398d6e3c7bcbd9e7512c2ad2fcbe1768450bf5674bf356a222962042d8de5926c16126c1de90654c7c535875d9947a653a2c983fbe4202ff08b221c48729b70
@@ -9,15 +9,18 @@ require 'reacter/util'
9
9
  class AdapterConnectionFailed < Exception; end
10
10
  class AdapterConnectionFaulted < Exception; end
11
11
  class AdapterConnectionClosed < Exception; end
12
+ class AdapterExit < Exception; end
12
13
 
13
14
  class Reacter
14
15
  class Adapter
15
16
  attr :config
16
17
  attr :type
18
+ attr :enable
17
19
 
18
20
  def initialize(config=nil)
19
21
  @config = (config || Reacter.get('global.adapter', {}))
20
22
  @type = @config.get('type')
23
+ @enable = true
21
24
  Util.info("Loading adapter #{@type}...")
22
25
  end
23
26
 
@@ -39,7 +42,19 @@ class Reacter
39
42
 
40
43
  # implement: manual disconnect / cleanup
41
44
  def disconnect()
42
- raise AdapterConnectionClosed
45
+ raise AdapterExit
46
+ end
47
+
48
+ def disable()
49
+ @enable = false
50
+ end
51
+
52
+ def enable()
53
+ @enable = true
54
+ end
55
+
56
+ def enabled?()
57
+ @enable
43
58
  end
44
59
 
45
60
  class<<self
@@ -22,7 +22,10 @@ class Reacter
22
22
 
23
23
  @_channel = AMQP::Channel.new(@_connection)
24
24
  @_queue = @_channel.queue(@config.get(:queue, DEFAULT_QUEUENAME), {
25
- :auto_delete => @config.get(:autodelete, true)
25
+ :auto_delete => @config.get(:autodelete, true),
26
+ :arguments => {
27
+ 'x-message-ttl' => @config.get(:ttl)
28
+ }.compact
26
29
  })
27
30
 
28
31
  @_exchange = @config.get(:exchange, '')
@@ -9,15 +9,15 @@ class Reacter
9
9
  class FileAdapter < Adapter
10
10
  def connect(args={})
11
11
  if @config.get(:filename) == 'stdin'
12
- @_stdin = true
12
+ @_input = STDIN
13
13
  else
14
- @_stdin = false
15
-
16
- readfile = (@config.get('filename') || @config.get('file.read'))
17
- writefile = @config.get('file.write')
14
+ if (readfile = (@config.get('filename') || @config.get('file.read')))
15
+ @_input = File.open(File.expand_path(readfile), 'r+')
16
+ end
17
+ end
18
18
 
19
- @_input = File.open(File.expand_path(readfile), 'r+') if readfile
20
- @_output = File.open(File.expand_path(writefile), 'a') if writefile
19
+ if (writefile = @config.get('file.write'))
20
+ @_output = File.open(File.expand_path(writefile), 'a')
21
21
  end
22
22
  end
23
23
 
@@ -34,6 +34,7 @@ class Reacter
34
34
  def poll(&block)
35
35
  if @_input
36
36
  loop do
37
+ disconnect() if @_input.eof?
37
38
  line = @_input.gets
38
39
  yield Message.parse(line)
39
40
  end
@@ -43,7 +44,7 @@ class Reacter
43
44
  end
44
45
 
45
46
  def disconnect()
46
- raise AdapterConnectionClosed
47
+ raise AdapterExit
47
48
  end
48
49
 
49
50
  private
@@ -9,19 +9,28 @@ class Reacter
9
9
  def initialize()
10
10
  super
11
11
 
12
- if @config['type']
13
- @_adapter = Adapter.create(@config['type'], @config)
14
- raise "Could not create relay adapter #{@config['type']}" unless @_adapter
15
- @_adapter.connect()
12
+ @_adapters = []
13
+ @_signature = Util.signature(object_id.to_s(16).upcase)
14
+
15
+ @config = (@config.is_a?(Hash) ? [@config] : [*@config])
16
+
17
+ @config.each do |c|
18
+ if c['type']
19
+ adapter = Adapter.create(c['type'], c)
20
+ adapter.connect()
21
+ @_adapters << adapter
22
+ end
16
23
  end
17
24
 
18
- @_signature = Util.signature()
25
+ @_adapter_cycle = @_adapters.cycle.each
19
26
  end
20
27
 
21
28
  def received(message)
22
- if @_adapter
23
- message[:relayed_from] = @_signature unless (@config['transparent'] === true)
24
- @_adapter.send(message, @config['format'])
29
+ adapter = @_adapter_cycle.next
30
+
31
+ if adapter
32
+ message[:relayed_from] = @_signature unless (adapter.config['transparent'] === true)
33
+ adapter.send(message, adapter.config['format'])
25
34
  else
26
35
  Util.warn("relay: Message received without an active relay adapter, dropping")
27
36
  return false
data/lib/reacter/core.rb CHANGED
@@ -76,28 +76,44 @@ class Reacter
76
76
  end
77
77
 
78
78
  # enter polling loop
79
- begin
80
- @_adapters.each do |adapter|
81
- poller = proc do
79
+ @_adapters.each do |adapter|
80
+ next unless adapter.enabled?
81
+
82
+ poller = proc do
83
+ begin
82
84
  adapter.poll do |messages|
83
85
  dispatch.call(messages)
84
86
  end
85
- end
87
+ rescue AdapterConnectionFailed => e
88
+ Util.error("Adapter connection failed: #{e.message}")
86
89
 
87
- EM.defer(poller)
88
- end
90
+ rescue AdapterConnectionFaulted => e
91
+ Util.error("Adapter connection error: #{e.message}")
89
92
 
90
- rescue AdapterConnectionFailed => e
91
- Util.error("Adapter connection failed: #{e.message}")
93
+ rescue AdapterConnectionClosed => e
94
+ Util.info("Adapter closed connection")
92
95
 
93
- rescue AdapterConnectionFaulted => e
94
- Util.error("Adapter connection error: #{e.message}")
96
+ rescue AdapterExit => e
97
+ adapter.disable()
98
+ end
99
+ end
95
100
 
96
- rescue AdapterConnectionClosed => e
97
- Util.info("Adapter closed connection")
101
+ EM.defer(poller)
102
+ end
103
+
104
+ EM.add_periodic_timer(1) do
98
105
 
106
+ # exit if all adapters are disabled
107
+ if @_adapters.select{|i| i.enabled? }.empty?
108
+ Util.info("All adapters disabled, exiting")
109
+ stop()
110
+ end
99
111
  end
100
112
  end
113
+
114
+ def stop()
115
+ EM.stop_event_loop()
116
+ end
101
117
  end
102
118
 
103
119
  class<<self
data/lib/reacter/util.rb CHANGED
@@ -11,7 +11,7 @@ class Reacter
11
11
  }
12
12
 
13
13
  def signature(custom=nil)
14
- ([%x{hostname -f}.strip.chomp, Process.pid]+[*custom]).compact.join(':')
14
+ ([%x{hostname -f}.strip.chomp, Process.pid.to_s(16).upcase]+[*custom]).compact.join(':')
15
15
  end
16
16
 
17
17
  def log(message, severity=:info, log=:default)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reacter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gary Hetzel
@@ -13,37 +12,46 @@ date: 2013-03-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: eventmachine
16
- requirement: &9815500 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *9815500
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: deep_merge
27
- requirement: &9813980 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *9813980
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: hashlib
38
- requirement: &9813340 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *9813340
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  description: A utility for consuming, transforming, and routing monitoring data from
48
56
  various sources
49
57
  email: ghetzel@outbrain.com
@@ -72,26 +80,25 @@ files:
72
80
  - bin/reacter
73
81
  homepage: http://outbrain.github.com/reacter/
74
82
  licenses: []
83
+ metadata: {}
75
84
  post_install_message:
76
85
  rdoc_options: []
77
86
  require_paths:
78
87
  - lib
79
88
  required_ruby_version: !ruby/object:Gem::Requirement
80
- none: false
81
89
  requirements:
82
- - - ! '>='
90
+ - - '>='
83
91
  - !ruby/object:Gem::Version
84
92
  version: '0'
85
93
  required_rubygems_version: !ruby/object:Gem::Requirement
86
- none: false
87
94
  requirements:
88
- - - ! '>='
95
+ - - '>='
89
96
  - !ruby/object:Gem::Version
90
97
  version: '0'
91
98
  requirements: []
92
99
  rubyforge_project:
93
- rubygems_version: 1.8.11
100
+ rubygems_version: 2.0.0
94
101
  signing_key:
95
- specification_version: 3
102
+ specification_version: 4
96
103
  summary: Reacter monitoring processor
97
104
  test_files: []