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, Mixin::RunitService
- Defined in:
- lib/kurchatov/plugin/riemann.rb
Constant Summary
Constants included from Mixin::Http
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::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
Methods included from Mixin::Ohai
Methods inherited from Kurchatov::Plugin
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_start ⇒ Object
Returns the value of attribute always_start.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def always_start @always_start end |
#collect ⇒ Object
Returns the value of attribute collect.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def collect @collect end |
#ignore_errors ⇒ Object
Returns the value of attribute ignore_errors.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def ignore_errors @ignore_errors end |
#interval ⇒ Object
Returns the value of attribute interval.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def interval @interval end |
#plugin ⇒ Object
Returns the value of attribute plugin.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def plugin @plugin end |
#required ⇒ Object
Returns the value of attribute required.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def required @required end |
#run ⇒ Object
Returns the value of attribute run.
19 20 21 |
# File 'lib/kurchatov/plugin/riemann.rb', line 19 def run @run end |
#run_if ⇒ Object
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_config ⇒ Object
33 34 35 |
# File 'lib/kurchatov/plugin/riemann.rb', line 33 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
37 38 39 40 |
# File 'lib/kurchatov/plugin/riemann.rb', line 37 def start! super run.nil? ? start_collect : start_run end |
#start_collect ⇒ Object
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_run ⇒ Object
51 52 53 |
# File 'lib/kurchatov/plugin/riemann.rb', line 51 def start_run self.instance_eval(&run) end |