Class: MonitorManager

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

Overview

Monitor Manager

Instance Method Summary collapse

Constructor Details

#initializeMonitorManager

Returns a new instance of MonitorManager.



3
4
5
# File 'lib/monitor_manager.rb', line 3

def initialize
  @list = []
end

Instance Method Details

#add(monitor) ⇒ Object



7
8
9
# File 'lib/monitor_manager.rb', line 7

def add(monitor)
  @list.push monitor
end

#runObject

The main run loop



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monitor_manager.rb', line 12

def run
  Kernel.loop do
    @list.each do |m|
      begin
        m.run
      rescue MonitorTypeExceptionHandled => e
        m.alert(e.message)
      end
    end
    sleep 0.2

    exit unless ENV['RUN_ONCE'].nil?
  end

rescue Interrupt
  string = "Exiting on request ...\n"
  puts string

rescue StandardError => e
  puts '*** This is really unexpected.'
  puts e.class.name
  puts "Message: #{e.message}"
  puts e.backtrace
end