Class: Monitaur::Monitor
- Inherits:
-
Object
- Object
- Monitaur::Monitor
- Defined in:
- lib/monitaur/monitor.rb
Constant Summary collapse
- @@config =
Monitaur::Configuration
Instance Attribute Summary collapse
-
#hooks ⇒ Object
Returns the value of attribute hooks.
-
#output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
-
#apply_hooks ⇒ Object
Apply hooks.
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
-
#render ⇒ Object
Returns a hash of the sysinfo values including values from hooks.
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
16 17 18 |
# File 'lib/monitaur/monitor.rb', line 16 def initialize @hooks ||= @@config.hooks end |
Instance Attribute Details
#hooks ⇒ Object
Returns the value of attribute hooks.
14 15 16 |
# File 'lib/monitaur/monitor.rb', line 14 def hooks @hooks end |
#output ⇒ Object
Returns the value of attribute output.
13 14 15 |
# File 'lib/monitaur/monitor.rb', line 13 def output @output end |
Class Method Details
.config ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/monitaur/monitor.rb', line 60 def self.config if block_given? yield(@@config) end end |
Instance Method Details
#apply_hooks ⇒ Object
Apply hooks. Hooks are methods that gets executed after all the other info has been collected. The hooks collection accepts a Proc, a method name (Symbol) or a Hash. Symbols has to be a special case because the method has to be visible on the Monitaur::Monitor class. Methods should return a Hash object that gets merged in the global output hash
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/monitaur/monitor.rb', line 39 def apply_hooks @hooks.each do |hook| hook_output = nil if hook.is_a?(Proc) hook_output = hook.call elsif hook.is_a?(Symbol) hook_output = eval(hook.to_s) # run the symbol elsif hook.is_a?(Hash) hook_output = hook # hash already? assign to output end @output.merge!(hook_output) if hook_output && hook_output.is_a?(Hash) end unless @hooks.empty? end |
#render ⇒ Object
Returns a hash of the sysinfo values including values from hooks
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/monitaur/monitor.rb', line 22 def render @output ||= {} @output.merge!(system_info) @output.merge!(active_record_connection) apply_hooks @output end |