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
@@ -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
|
-
|
31
|
-
|
24
|
+
loop do
|
25
|
+
check_alive
|
26
|
+
sleep 10
|
32
27
|
end
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
41
|
-
log :debug, "Check alive of threads [#{
|
42
|
-
|
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
|
-
|
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
|
-
|
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
|
|
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.
|
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:
|
309
|
+
hash: 3173648175310025004
|
310
310
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
311
311
|
none: false
|
312
312
|
requirements:
|