Class: Bosh::Monitor::Agent

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

Constant Summary collapse

ATTRIBUTES =
[ :deployment, :job, :index, :instance_id, :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
28
# 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]
  @instance_id = opts[:instance_id]
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



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

def name
  if @deployment && @job && @instance_id
    name = "#{@deployment}: #{@job}(#{@instance_id}) [id=#{@id}, "

    if @index
      name = name + "index=#{@index}, "
    end

    name + "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)


54
55
56
# File 'lib/bosh/monitor/agent.rb', line 54

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

#timed_out?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bosh/monitor/agent.rb', line 50

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