Class: What::Monitor

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

Class Method Summary collapse

Class Method Details

.do_itObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/what/monitor.rb', line 24

def self.do_it
  Status['details'] = []
  loop do
    statuses = []
    healths = []
    @threads.each do |th|
      if th[:status]
        healths << th[:status]['health']
        statuses << th[:status]
      end
    end
    Status['health'] = Helpers.overall_health(healths)
    Status['details'] = statuses
    sleep Config['interval']
  end
end

.go!Object

don’t worry, these method names are ironic



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/what/monitor.rb', line 4

def self.go!
  @modules = Config['modules'].map do |mod|
    name = Helpers.camelize(mod.delete('type'))
    Modules.const_get(name).new(mod)
  end

  Thread.abort_on_exception = true
  @threads = @modules.collect do |mod|
    Thread.new do
      loop do
        mod.check!
        Thread.current[:status] = mod.status
        sleep mod.interval
      end
    end
  end

  Thread.new { self.do_it }
end