Class: Monitaur::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/monitaur/monitor.rb

Constant Summary collapse

@@config =
Monitaur::Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonitor

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

#hooksObject

Returns the value of attribute hooks.



14
15
16
# File 'lib/monitaur/monitor.rb', line 14

def hooks
  @hooks
end

#outputObject

Returns the value of attribute output.



13
14
15
# File 'lib/monitaur/monitor.rb', line 13

def output
  @output
end

Class Method Details

.configObject



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_hooksObject

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

#renderObject

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