Class: Kurchatov::Plugins::Riemann

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

Constant Summary

Constants included from Mixin::Http

Mixin::Http::USER_AGENT

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::RunitService

#runit_service_running?, #runit_service_stat, #runit_service_uptime

Methods included from Mixin::Http

#http_get, #http_post, #rest_get

Methods included from Mixin::Command

#shell, #shell_out, #shell_out!

Methods included from Mixin::Event

#event

Methods included from Mixin::Ohai

#ohai

Methods inherited from Kurchatov::Plugin

#stop!, #stopped?

Constructor Details

#initialize(name = '') ⇒ Riemann

Returns a new instance of Riemann.



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

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.



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

def always_start
  @always_start
end

#collectObject

Returns the value of attribute collect.



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

def collect
  @collect
end

#ignore_errorsObject

Returns the value of attribute ignore_errors.



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

def ignore_errors
  @ignore_errors
end

#intervalObject

Returns the value of attribute interval.



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

def interval
  @interval
end

#pluginObject

Returns the value of attribute plugin.



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

def plugin
  @plugin
end

#requiredObject

Returns the value of attribute required.



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

def required
  @required
end

#runObject

Returns the value of attribute run.



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

def run
  @run
end

#run_ifObject

Returns the value of attribute run_if.



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

def run_if
  @run_if
end

Instance Method Details

#plugin_configObject



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

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

#start!Object



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

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

#start_collectObject



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

def start_collect
  loop do
    tick = Time.now
    Timeout::timeout(interval) { self.instance_eval(&collect) }
    tick = interval - (Time.now - tick).to_f
    tick > 0.0 ? sleep(tick) : raise(Timeout::Error, "Execution timeout. Exec time: #{tick}, interval: #{interval}")
  end
end

#start_runObject



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

def start_run
  self.instance_eval(&run)
end