Class: Kurchatov::Plugins::Riemann
- Inherits:
-
Kurchatov::Plugin
- Object
- Kurchatov::Plugin
- Kurchatov::Plugins::Riemann
- 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
Instance Attribute Summary collapse
-
#always_start ⇒ Object
Returns the value of attribute always_start.
-
#collect ⇒ Object
Returns the value of attribute collect.
-
#ignore_errors ⇒ Object
Returns the value of attribute ignore_errors.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#plugin ⇒ Object
Returns the value of attribute plugin.
-
#required ⇒ Object
Returns the value of attribute required.
-
#run ⇒ Object
Returns the value of attribute run.
-
#run_if ⇒ Object
Returns the value of attribute run_if.
Attributes inherited from Kurchatov::Plugin
Instance Method Summary collapse
-
#initialize(name = '') ⇒ Riemann
constructor
A new instance of Riemann.
- #plugin_config ⇒ Object
- #respond_to_ohai?(opts = {}) ⇒ Boolean
- #runnable_by_config? ⇒ Boolean
- #runnable_by_required? ⇒ Boolean
- #start ⇒ Object
- #start_collect ⇒ Object
- #start_run ⇒ Object
Methods included from Mixin::Monitor
Methods included from Mixin::Queue
Methods included from Mixin::Http
Methods included from Mixin::Command
#shell, #shell_out, #shell_out!
Methods included from Mixin::Event
Methods included from Mixin::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_start ⇒ Object
Returns the value of attribute always_start.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def always_start @always_start end |
#collect ⇒ Object
Returns the value of attribute collect.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def collect @collect end |
#ignore_errors ⇒ Object
Returns the value of attribute ignore_errors.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def ignore_errors @ignore_errors end |
#interval ⇒ Object
Returns the value of attribute interval.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def interval @interval end |
#plugin ⇒ Object
Returns the value of attribute plugin.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def plugin @plugin end |
#required ⇒ Object
Returns the value of attribute required.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def required @required end |
#run ⇒ Object
Returns the value of attribute run.
18 19 20 |
# File 'lib/kurchatov/plugin/riemann.rb', line 18 def run @run end |
#run_if ⇒ Object
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_config ⇒ Object
32 33 34 |
# File 'lib/kurchatov/plugin/riemann.rb', line 32 def plugin_config plugin end |
#respond_to_ohai?(opts = {}) ⇒ 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
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
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
36 37 38 39 |
# File 'lib/kurchatov/plugin/riemann.rb', line 36 def start super run.nil? ? start_collect : start_run end |
#start_collect ⇒ Object
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_run ⇒ Object
51 52 53 |
# File 'lib/kurchatov/plugin/riemann.rb', line 51 def start_run self.instance_eval(&run) end |