Class: Bosh::Monitor::Agent

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

Constant Summary collapse

ATTRIBUTES =
[ :deployment, :job, :index, :cid ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, opts = {}) ⇒ Agent

Returns a new instance of Agent.

Raises:

  • (ArgumentError)


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

def initialize(id, opts={})
  raise ArgumentError, "Agent must have an id" if id.nil?

  @id            = id
  @discovered_at = Time.now
  @updated_at    = Time.now
  @logger        = Bhm.logger
  @intervals     = Bhm.intervals

  @deployment = opts[:deployment]
  @job = opts[:job]
  @index = opts[:index]
  @cid = opts[:cid]
end

Instance Attribute Details

#discovered_atObject (readonly)

Returns the value of attribute discovered_at.



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

def discovered_at
  @discovered_at
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/bosh/monitor/agent.rb', line 4

def id
  @id
end

#updated_atObject

Returns the value of attribute updated_at.



6
7
8
# File 'lib/bosh/monitor/agent.rb', line 6

def updated_at
  @updated_at
end

Instance Method Details

#nameObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bosh/monitor/agent.rb', line 29

def name
  if @deployment && @job && @index
    "#{@deployment}: #{@job}(#{@index}) [id=#{@id}, cid=#{@cid}]"
  else
    state = ATTRIBUTES.inject([]) do |acc, attribute|
      value = send(attribute)
      acc << "#{attribute}=#{value}" if value
      acc
    end

    "agent #{@id} [#{state.join(", ")}]"
  end
end

#rogue?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/bosh/monitor/agent.rb', line 47

def rogue?
  (Time.now - @discovered_at) > @intervals.rogue_agent_alert && @deployment.nil?
end

#timed_out?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/bosh/monitor/agent.rb', line 43

def timed_out?
  (Time.now - @updated_at) > @intervals.agent_timeout
end