Class: Wakame::Monitor::Service::ServiceChecker

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

Direct Known Subclasses

CommandChecker, PidFileChecker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(svc_id, svc_mon, interval) ⇒ ServiceChecker

Returns a new instance of ServiceChecker.



11
12
13
14
15
16
17
18
19
20
# File 'lib/wakame/monitor/service.rb', line 11

def initialize(svc_id, svc_mon, interval)
  @svc_id = svc_id
  @service_monitor = svc_mon
  @interval = interval
  @status = Wakame::Service::STATUS_OFFLINE
  count = 0
  @timer = Wakame::Monitor::CheckerTimer.new(@interval) {
    self.signal_checker
  }
end

Instance Attribute Details

#intervalObject (readonly)

include Wakame::Packets::Agent



8
9
10
# File 'lib/wakame/monitor/service.rb', line 8

def interval
  @interval
end

#last_checked_atObject

Returns the value of attribute last_checked_at.



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

def last_checked_at
  @last_checked_at
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#svc_idObject (readonly)

include Wakame::Packets::Agent



8
9
10
# File 'lib/wakame/monitor/service.rb', line 8

def svc_id
  @svc_id
end

#timerObject (readonly)

include Wakame::Packets::Agent



8
9
10
# File 'lib/wakame/monitor/service.rb', line 8

def timer
  @timer
end

Instance Method Details

#checkObject



41
42
# File 'lib/wakame/monitor/service.rb', line 41

def check
end

#startObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/wakame/monitor/service.rb', line 22

def start
  if !@timer.running?
    # Runs checker once for immediate status update.
    signal_checker

    @timer.start
    @service_monitor.send_event(Wakame::Packets::MonitoringStarted.new(@service_monitor.agent, self.svc_id))
    Wakame.log.debug("#{self.class}: Started the checker")
  end
end

#stopObject



33
34
35
36
37
38
39
# File 'lib/wakame/monitor/service.rb', line 33

def stop
  if @timer.running?
    @timer.stop
    @service_monitor.send_event(Wakame::Packets::MonitoringStopped.new(@service_monitor.agent, self.svc_id))
    Wakame.log.debug("#{self.class}: Stopped the checker")
  end
end