riemann-babbler 2.0.0pre11 → 2.0.0pre13

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/.travis.yml CHANGED
@@ -2,4 +2,4 @@ language:
2
2
  - ruby
3
3
  rvm:
4
4
  - 1.9.3
5
- script: "bundle exec rspec spec/default.rb"
5
+ script: "bundle exec rspec test/default_spec.rb"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riemann-babbler (2.0.0pre11)
4
+ riemann-babbler (2.0.0pre13)
5
5
  configatron
6
6
  docile
7
7
  file-tail
@@ -21,8 +21,9 @@ GEM
21
21
  coderay (1.0.9)
22
22
  configatron (2.13.0)
23
23
  yamler (>= 0.1.0)
24
+ diff-lcs (1.2.4)
24
25
  docile (1.1.0)
25
- ffi (1.9.0)
26
+ ffi (1.9.3)
26
27
  file-tail (1.0.12)
27
28
  tins (~> 0.5)
28
29
  method_source (0.8.2)
@@ -45,6 +46,14 @@ GEM
45
46
  beefcake (>= 0.3.5)
46
47
  mtrc (>= 0.0.4)
47
48
  trollop (>= 1.16.2)
49
+ rspec (2.14.1)
50
+ rspec-core (~> 2.14.0)
51
+ rspec-expectations (~> 2.14.0)
52
+ rspec-mocks (~> 2.14.0)
53
+ rspec-core (2.14.7)
54
+ rspec-expectations (2.14.3)
55
+ diff-lcs (>= 1.1.3, < 2.0)
56
+ rspec-mocks (2.14.4)
48
57
  slop (3.4.6)
49
58
  sys-filesystem (1.1.1)
50
59
  ffi
@@ -61,3 +70,4 @@ DEPENDENCIES
61
70
  pry
62
71
  rake
63
72
  riemann-babbler!
73
+ rspec
data/bin/riemann-babbler CHANGED
@@ -4,7 +4,6 @@
4
4
  require 'trollop'
5
5
  require 'yaml'
6
6
  require_relative '../lib/riemann/babbler'
7
- require_relative '../lib/riemann/babbler/plugin'
8
7
 
9
8
  include Riemann::Babbler::Logging
10
9
  include Riemann::Babbler::Options
@@ -42,5 +41,6 @@ opts.configure_from_hash({ :riemann => cmd_opts })
42
41
  merge_config(opts.riemann.config)
43
42
 
44
43
  # start
45
- Riemann::Babbler::Responder.new.run!
46
- Riemann::Babbler::PluginLoader.new(Riemann::Babbler::Sender.new).run!
44
+ sender = Riemann::Babbler::Sender.new
45
+ plugins_to_start = Riemann::Babbler::PluginLoader.new.plugin_to_start
46
+ Riemann::Babbler::PluginManager.new(sender, plugins_to_start).run!
@@ -37,7 +37,7 @@ module Riemann
37
37
 
38
38
  # return string Riemann::Babbler::Plugin::TwCli_3
39
39
  def underscore_to_name(name = 'tw_cli_3', parent = 'Riemann::Babbler::Plugin')
40
- parent + '::' + name.to_s.split('_').map { |part|
40
+ parent + '::' + name.to_s.split('_').map { |part|
41
41
  if part.to_i != 0
42
42
  "_#{part}"
43
43
  else
@@ -1,3 +1,5 @@
1
+ require_relative 'plugin'
2
+
1
3
  module Riemann
2
4
  module Babbler
3
5
  class PluginLoader
@@ -19,15 +21,15 @@ module Riemann
19
21
  'net',
20
22
  'runit',
21
23
  'tw_cli',
22
- 'errors_reporter'
24
+ 'errors_reporter',
25
+ 'responder'
23
26
  ].freeze
24
27
 
25
- attr_accessor :sender, :load_plugin_names_from_config, :delete_from_autostart
28
+ attr_accessor :load_plugin_names_from_config, :delete_from_autostart
26
29
 
27
- def initialize(riemann)
28
- @sender = riemann
30
+ def initialize
29
31
  @load_plugin_names_from_config = Array.new
30
- @delete_from_autostart = Array.new
32
+ @delete_from_autostart = Array.new
31
33
  end
32
34
 
33
35
  def all_available_plugins
@@ -91,7 +93,7 @@ module Riemann
91
93
  require_from_config
92
94
  end
93
95
 
94
- def run!
96
+ def plugin_to_start
95
97
 
96
98
  started_plugins = []
97
99
 
@@ -101,7 +103,7 @@ module Riemann
101
103
  require_all_plugins!
102
104
 
103
105
  plugin_names_to_run = plugin_names_to_run +
104
- load_plugin_names_from_config.map {|name| name.to_s}
106
+ load_plugin_names_from_config.map { |name| name.to_s }
105
107
 
106
108
  plugin_names_to_run = (plugin_names_to_run - delete_from_autostart).uniq
107
109
 
@@ -111,16 +113,8 @@ module Riemann
111
113
  end
112
114
  end
113
115
 
114
- plugin_threads = started_plugins.map do |plugin|
115
- Thread.new {
116
- log :unknown, "Start plugin #{plugin}"
117
- plugin.new(sender).run!
118
- }
119
- end
120
- Signal.trap 'TERM' do
121
- plugin_threads.each(&:kill)
122
- end
123
- plugin_threads.each(&:join)
116
+ log :debug, "Return plugin to start: #{started_plugins}"
117
+ started_plugins
124
118
  end
125
119
 
126
120
  end
@@ -0,0 +1,53 @@
1
+ module Riemann
2
+ module Babbler
3
+ class PluginManager
4
+
5
+ include Riemann::Babbler::Logging
6
+
7
+ attr_accessor :sender
8
+
9
+ def initialize(sender, array_of_klasses)
10
+ @plugins = array_of_klasses
11
+ @sender = sender
12
+ end
13
+
14
+ def run!
15
+ hash_of_plugins_and_threads = Hash.new
16
+ @plugins.map do |plugin|
17
+
18
+ unless plugin.new(@sender).send(:run_plugin)
19
+ log :unknown, "Disable plugin: #{plugin}, because it not started by condition: run_plugin"
20
+ next
21
+ end
22
+
23
+ hash_of_plugins_and_threads[plugin] = Thread.new {
24
+ log :unknown, "Start plugin #{plugin}"
25
+ plugin.new(@sender).run!
26
+ }
27
+
28
+ end
29
+
30
+ Signal.trap 'TERM' do
31
+ hash_of_plugins_and_threads.values.each(&:kill)
32
+ end
33
+
34
+ loop {
35
+ check_alive(hash_of_plugins_and_threads)
36
+ sleep 10
37
+ }
38
+ end
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|
43
+ next if thread.alive?
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
+ }
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -6,7 +6,7 @@ class Riemann::Babbler::Plugin::ErrorsReporter < Riemann::Babbler::Plugin
6
6
  end
7
7
 
8
8
  def collect
9
- status = Array.new
9
+ status = Array.new
10
10
  messages = Array.new
11
11
 
12
12
  opts.errors.to_hash.each do |plugin_name, plugin_status|
@@ -22,9 +22,9 @@ class Riemann::Babbler::Plugin::ErrorsReporter < Riemann::Babbler::Plugin
22
22
  else
23
23
  @report_ok = false
24
24
  status << {
25
- :service => plugin.service,
26
- :state => 'critical',
27
- :metric => messages.count,
25
+ :service => plugin.service,
26
+ :state => 'critical',
27
+ :metric => messages.count,
28
28
  :description => "Problem with plugins:\n #{messages.join("\n")}"
29
29
  }
30
30
  end
@@ -0,0 +1,29 @@
1
+ require 'net/http/server'
2
+ require 'json'
3
+
4
+ class Riemann::Babbler::Plugin::Responder < Riemann::Babbler::Plugin
5
+
6
+ def init
7
+ plugin.set_default(:port, opts.riemann.responder_port)
8
+ plugin.set_default(:started_at, Time.now.to_i)
9
+ end
10
+
11
+ def info
12
+ {
13
+ :version => Riemann::Babbler::VERSION,
14
+ :ruby => "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}",
15
+ :uptime => Time.now.to_i - plugin.started_at,
16
+ :errors => opts.errors.to_hash,
17
+ :config => opts.riemann.to_hash
18
+ }
19
+ end
20
+
21
+ def run!
22
+ log :unknown, "Start responder 0.0.0.0:#{plugin.port}"
23
+ ::Net::HTTP::Server.run(:port => plugin.port) do |request, _|
24
+ log :debug, "Responder request: #{request}"
25
+ [200, { 'Content-Type' => 'application/json' }, [info.to_json]]
26
+ end
27
+ end
28
+
29
+ end
@@ -44,7 +44,7 @@ class Riemann::Babbler::Plugin::Runit < Riemann::Babbler::Plugin
44
44
  # сервис запущен и работает дольше чем мы приходили к нему в прошлый раз
45
45
  if srv_runned && srv_uptime > plugin.interval
46
46
  @status_history.delete(srv_name)
47
- status << { :service => plugin.service + ' ' + srv_name, :state => 'ok', :description => "runit service #{srv_name} running", :metric => srv_uptime }
47
+ status << { :service => plugin.service + ' ' + srv_name, :state => 'ok', :description => "runit service #{srv_name} running" }
48
48
  else
49
49
  # сервис запущен но работает подозрительно мало, но последний раз замечен не был
50
50
  if srv_uptime < plugin.interval && srv_runned && !@status_history.include?(srv_name)
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  module Babbler
3
- VERSION = '2.0.0pre11'
3
+ VERSION = '2.0.0pre13'
4
4
  end
5
5
  end
@@ -4,5 +4,5 @@ require 'riemann/babbler/logging'
4
4
  require 'riemann/babbler/errors'
5
5
  require 'riemann/babbler/monkey_patches'
6
6
  require 'riemann/babbler/sender'
7
- require 'riemann/babbler/responder'
8
- require 'riemann/babbler/plugin_loader'
7
+ require 'riemann/babbler/plugin_loader'
8
+ require 'riemann/babbler/plugin_manager'
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_development_dependency 'bundler', '~> 1.3'
34
34
  spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
35
36
  spec.add_development_dependency 'pry'
36
37
  end
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/riemann/babbler'
2
+
3
+ include Riemann::Babbler::Options
4
+
5
+ describe 'Riemann Babbler Loader' do
6
+
7
+ before(:each) do
8
+ merge_config(File.expand_path('../my_config.yml', __FILE__))
9
+ @plugins = Riemann::Babbler::PluginLoader.new.plugin_to_start
10
+ @plugins = @plugins.map {|plugin| plugin.to_s}
11
+ end
12
+
13
+ it "load from file" do
14
+ opts.riemann.host.should == 'host_from_yaml'
15
+ end
16
+
17
+ it "load parent plugins" do
18
+ @plugins.should include('Riemann::Babbler::Plugin::Disk_1')
19
+ end
20
+
21
+ it "load parent from array" do
22
+ @plugins.should include('Riemann::Babbler::Plugin::Cpu_1')
23
+ end
24
+
25
+ end
@@ -0,0 +1,10 @@
1
+ riemann:
2
+ host: host_from_yaml
3
+ plugins_directory: /tmp
4
+
5
+ plugins:
6
+ disk_1:
7
+ parent: disk
8
+ cpu:
9
+ - service: cpu 1
10
+ - service: cpu 2
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.0pre11
4
+ version: 2.0.0pre13
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-31 00:00:00.000000000 Z
12
+ date: 2013-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: riemann-client
@@ -203,6 +203,22 @@ dependencies:
203
203
  - - ! '>='
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: rspec
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
206
222
  - !ruby/object:Gem::Dependency
207
223
  name: pry
208
224
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +259,7 @@ files:
243
259
  - lib/riemann/babbler/options.rb
244
260
  - lib/riemann/babbler/plugin.rb
245
261
  - lib/riemann/babbler/plugin_loader.rb
262
+ - lib/riemann/babbler/plugin_manager.rb
246
263
  - lib/riemann/babbler/plugins/cpu.rb
247
264
  - lib/riemann/babbler/plugins/cpu_fan.rb
248
265
  - lib/riemann/babbler/plugins/cpu_temp.rb
@@ -265,13 +282,15 @@ files:
265
282
  - lib/riemann/babbler/plugins/net_stat.rb
266
283
  - lib/riemann/babbler/plugins/nginx.rb
267
284
  - lib/riemann/babbler/plugins/pgsql.rb
285
+ - lib/riemann/babbler/plugins/responder.rb
268
286
  - lib/riemann/babbler/plugins/runit.rb
269
287
  - lib/riemann/babbler/plugins/status_file.rb
270
288
  - lib/riemann/babbler/plugins/tw_cli.rb
271
- - lib/riemann/babbler/responder.rb
272
289
  - lib/riemann/babbler/sender.rb
273
290
  - lib/riemann/babbler/version.rb
274
291
  - riemann-babbler.gemspec
292
+ - test/default_spec.rb
293
+ - test/my_config.yml
275
294
  homepage: https://github.com/vadv/riemann-babbler
276
295
  licenses:
277
296
  - MIT
@@ -287,7 +306,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
287
306
  version: '0'
288
307
  segments:
289
308
  - 0
290
- hash: -1211602378390530689
309
+ hash: -4537148055138242403
291
310
  required_rubygems_version: !ruby/object:Gem::Requirement
292
311
  none: false
293
312
  requirements:
@@ -300,4 +319,6 @@ rubygems_version: 1.8.23
300
319
  signing_key:
301
320
  specification_version: 3
302
321
  summary: Monitoring tool for riemann server, aka plugin manager
303
- test_files: []
322
+ test_files:
323
+ - test/default_spec.rb
324
+ - test/my_config.yml
@@ -1,43 +0,0 @@
1
- require 'net/http/server'
2
- require 'json'
3
-
4
- module Riemann
5
- module Babbler
6
-
7
- class Responder
8
-
9
-
10
- include Riemann::Babbler::Logging
11
- include Riemann::Babbler::Options
12
-
13
- attr_accessor :port, :started_at
14
-
15
- def initialize
16
- @port = opts.riemann.responder_port
17
- @started_at = Time.now.to_i
18
- end
19
-
20
- def info
21
- {
22
- :version => Riemann::Babbler::VERSION,
23
- :ruby => "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}",
24
- :uptime => Time.now.to_i - started_at,
25
- :errors => opts.errors.to_hash,
26
- :config => opts.riemann.to_hash
27
- }
28
- end
29
-
30
- def run!
31
- Thread.new {
32
- log :unknown, "Start responder 0.0.0.0:#{port}"
33
- Net::HTTP::Server.run(:port => port) do |request, _|
34
- log :debug, "Responder request: #{request}"
35
- [200, { 'Content-Type' => 'application/json' }, [info.to_json]]
36
- end
37
- }
38
- end
39
- end
40
-
41
- end
42
- end
43
-