Class: Kurchatov::Plugins::Riemann

Inherits:
Kurchatov::Plugin show all
Includes:
Mixin::Command, Mixin::Event, Mixin::Http, Mixin::Monitor, Mixin::Ohai, Mixin::Queue
Defined in:
lib/kurchatov/plugin/riemann.rb

Constant Summary

Constants included from Mixin::Event

Mixin::Event::EVENT_FIELDS

Instance Attribute Summary collapse

Attributes inherited from Kurchatov::Plugin

#name

Instance Method Summary collapse

Methods included from Mixin::Monitor

#monitor

Methods included from Mixin::Queue

#events

Methods included from Mixin::Http

#rest_get

Methods included from Mixin::Command

#shell, #shell_out, #shell_out!

Methods included from Mixin::Event

#event

Methods included from Mixin::Ohai

#ohai

Constructor Details

#initialize(name = '') ⇒ Riemann

Returns a new instance of Riemann.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kurchatov/plugin/riemann.rb', line 20

def initialize(name = '')
  super(name)
  @run_if = Proc.new { true }
  @required = Proc.new { true }
  @run = nil
  @plugin = Mashie.new
  @always_start = false
  @ignore_errors = false
  @collect = nil
  @interval = 60.0
end

Instance Attribute Details

#always_startObject

Returns the value of attribute always_start.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def always_start
  @always_start
end

#collectObject

Returns the value of attribute collect.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def collect
  @collect
end

#ignore_errorsObject

Returns the value of attribute ignore_errors.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def ignore_errors
  @ignore_errors
end

#intervalObject

Returns the value of attribute interval.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def interval
  @interval
end

#pluginObject

Returns the value of attribute plugin.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def plugin
  @plugin
end

#requiredObject

Returns the value of attribute required.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def required
  @required
end

#runObject

Returns the value of attribute run.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def run
  @run
end

#run_ifObject

Returns the value of attribute run_if.



18
19
20
# File 'lib/kurchatov/plugin/riemann.rb', line 18

def run_if
  @run_if
end

Instance Method Details

#plugin_configObject



32
33
34
# File 'lib/kurchatov/plugin/riemann.rb', line 32

def plugin_config
  plugin
end

#respond_to_ohai?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/kurchatov/plugin/riemann.rb', line 55

def respond_to_ohai?(opts = {})
  opts.each { |k, v| return false unless ohai[k] == v }
  true
end

#runnable_by_config?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
# File 'lib/kurchatov/plugin/riemann.rb', line 69

def runnable_by_config?
  Log.info("Plugin '#{self.name}' disabled by run and collect nil") and return if (collect.nil? && run.nil?)
  Log.info("Plugin '#{self.name}' disabled in config") and return if (plugin[:disable] == true)
  Log.info("Plugin '#{self.name}' not started by run_if condition ") and
      return unless self.instance_eval(&run_if)
  Log.error("Plugin '#{self.name}' not started by required block") and return unless runnable_by_required?
  @plugin[:service] ||= name
  true
end

#runnable_by_required?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
# File 'lib/kurchatov/plugin/riemann.rb', line 60

def runnable_by_required?
  begin
    self.instance_eval(&required)
  rescue LoadError
    return
  end
  true
end

#startObject



36
37
38
39
# File 'lib/kurchatov/plugin/riemann.rb', line 36

def start
  super
  run.nil? ? start_collect : start_run
end

#start_collectObject



41
42
43
44
45
46
47
48
49
# File 'lib/kurchatov/plugin/riemann.rb', line 41

def start_collect
  loop do
    t_start = Time.now
    Timeout::timeout(interval * 2.to_f/3) do
      self.instance_eval(&collect)
    end
    sleep(interval - (Time.now - t_start).to_i)
  end
end

#start_runObject



51
52
53
# File 'lib/kurchatov/plugin/riemann.rb', line 51

def start_run
  self.instance_eval(&run)
end