Class: Wakame::Monitor::Agent

Inherits:
Object
  • Object
show all
Includes:
Wakame::Monitor
Defined in:
lib/wakame/monitor/agent.rb

Constant Summary

Constants included from Wakame::Monitor

STATUS_FAIL, STATUS_OFFLINE, STATUS_ONLINE

Instance Method Summary collapse

Methods included from Wakame::Monitor

#disable, #enable, included, #publish_to

Constructor Details

#initializeAgent

Returns a new instance of Agent.



5
6
7
# File 'lib/wakame/monitor/agent.rb', line 5

def initialize
  @status = STATUS_ONLINE
end

Instance Method Details

#checkObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wakame/monitor/agent.rb', line 28

def check
  if Wakame.config.environment == :EC2
    attrs = Wakame::Agent.ec2_fetch_local_attrs
  else
    attrs = {}
  end

  res = {:attrs=>attrs, :monitors=>[], :actors=>[], :services=>{}}
  EM.barrier {
    agent.monitor_manager.monitors.each { |key, m|
      res[:monitors] << {:class=>m.class.to_s}
    }
    agent.actor_manager.actors.each { |key, a|
      res[:actors] << {:class=>a.class.to_s}
    }

    svcmon = agent.monitor_manager.find_monitor('/service')
    svcmon.checkers.each { |svc_id, a|
      res[:services][svc_id]={:status=>a.status}
    }
  }

  res
end

#reload(config) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wakame/monitor/agent.rb', line 13

def reload(config)
  # Send the first ping signal as soon as possible since the ping contanins vital information to construct the Agent object on master node.
  send_ping(check())

  if @timer && @time.running?
    @timer.stop
  end

  # Setup periodical ping publisher.
  @timer = CheckerTimer.new(config[:interval] || 10) {
    send_ping(check())
  }
  @timer.start
end

#send_ping(hash) ⇒ Object



9
10
11
# File 'lib/wakame/monitor/agent.rb', line 9

def send_ping(hash)
  publish_to('ping', Wakame::Packets::Ping.new(agent, hash[:attrs], hash[:actors], hash[:monitors], hash[:services]).marshal)
end