riemann-babbler 2.0.0pre13 → 2.0.0pre15

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riemann-babbler (2.0.0pre13)
4
+ riemann-babbler (2.0.0pre15)
5
5
  configatron
6
6
  docile
7
7
  file-tail
@@ -5,6 +5,7 @@ module Riemann
5
5
  RESOLV_RIEMANN_SERVER = 1
6
6
  INIT_CONNECT = 2
7
7
  CONNECTION_PROBLEM = 3
8
+ USER_CALL_SHUTDOWN = 4
8
9
  end
9
10
 
10
11
  end
@@ -3,51 +3,53 @@ module Riemann
3
3
  class PluginManager
4
4
 
5
5
  include Riemann::Babbler::Logging
6
-
7
- attr_accessor :sender
6
+ include Riemann::Babbler::Errors
8
7
 
9
8
  def initialize(sender, array_of_klasses)
10
9
  @plugins = array_of_klasses
11
10
  @sender = sender
11
+ @mapping = Hash.new
12
12
  end
13
13
 
14
14
  def run!
15
- hash_of_plugins_and_threads = Hash.new
16
- @plugins.map do |plugin|
17
15
 
16
+ @plugins.map do |plugin|
18
17
  unless plugin.new(@sender).send(:run_plugin)
19
18
  log :unknown, "Disable plugin: #{plugin}, because it not started by condition: run_plugin"
20
19
  next
21
20
  end
22
-
23
- hash_of_plugins_and_threads[plugin] = Thread.new {
24
- log :unknown, "Start plugin #{plugin}"
25
- plugin.new(@sender).run!
26
- }
27
-
21
+ @mapping[plugin] = run_thread(plugin)
28
22
  end
29
23
 
30
- Signal.trap 'TERM' do
31
- hash_of_plugins_and_threads.values.each(&:kill)
24
+ loop do
25
+ check_alive
26
+ sleep 10
32
27
  end
28
+ end
33
29
 
34
- loop {
35
- check_alive(hash_of_plugins_and_threads)
36
- sleep 10
30
+ def run_thread(plugin)
31
+ Thread.new {
32
+ log :unknown, "Start plugin #{plugin}"
33
+ plugin.new(@sender).run!
34
+ Signal.trap('TERM') do
35
+ shutdown
36
+ end
37
37
  }
38
38
  end
39
39
 
40
- def check_alive(hash_of_plugins_and_threads)
41
- log :debug, "Check alive of threads [#{hash_of_plugins_and_threads.count}]"
42
- hash_of_plugins_and_threads.each do |plugin, thread|
40
+ def check_alive
41
+ log :debug, "Check alive of threads [#{@mapping.count}]"
42
+ @mapping.each do |plugin, thread|
43
43
  next if thread.alive?
44
44
  log :error, "Plugin: #{plugin} is #{thread.inspect}, run it..."
45
- hash_of_plugins_and_threads[plugin] = Thread.new {
46
- plugin.new(@sender).run!
47
- }
45
+ @mapping[plugin] = run_thread(plugin)
48
46
  end
49
47
  end
50
48
 
49
+ def shutdown
50
+ exit Errors::USER_CALL_SHUTDOWN
51
+ end
52
+
51
53
  end
52
54
  end
53
55
  end
@@ -15,14 +15,24 @@ class Riemann::Babbler::Plugin::Responder < Riemann::Babbler::Plugin
15
15
  :uptime => Time.now.to_i - plugin.started_at,
16
16
  :errors => opts.errors.to_hash,
17
17
  :config => opts.riemann.to_hash
18
- }
18
+ }.to_json
19
+ end
20
+
21
+ def status_ok
22
+ {:status => 'ok'}.to_json
19
23
  end
20
24
 
21
25
  def run!
22
26
  log :unknown, "Start responder 0.0.0.0:#{plugin.port}"
23
27
  ::Net::HTTP::Server.run(:port => plugin.port) do |request, _|
24
28
  log :debug, "Responder request: #{request}"
25
- [200, { 'Content-Type' => 'application/json' }, [info.to_json]]
29
+ case
30
+ when request[:uri][:path] == "/kill" #&& request[:method] == "POST"
31
+ [200, { 'Content-Type' => 'application/json' }, [status_ok]]
32
+ Process.kill('TERM', $$)
33
+ else
34
+ [200, { 'Content-Type' => 'application/json' }, [info]]
35
+ end
26
36
  end
27
37
  end
28
38
 
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  module Babbler
3
- VERSION = '2.0.0pre13'
3
+ VERSION = '2.0.0pre15'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-babbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0pre13
4
+ version: 2.0.0pre15
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -306,7 +306,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
306
  version: '0'
307
307
  segments:
308
308
  - 0
309
- hash: -4537148055138242403
309
+ hash: 3173648175310025004
310
310
  required_rubygems_version: !ruby/object:Gem::Requirement
311
311
  none: false
312
312
  requirements: