Class: Bosh::Agent::Message::State

Inherits:
Base show all
Defined in:
lib/bosh_agent/message/state.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#base_dir, #handler_error, #logger, #logs_dir, #settings, #store_migration_target, #store_path

Constructor Details

#initialize(args = nil) ⇒ State

Returns a new instance of State.



11
12
13
14
15
# File 'lib/bosh_agent/message/state.rb', line 11

def initialize(args = nil)
  if args.is_a?(Array)
    @full_format = true if args.include?("full")
  end
end

Class Method Details

.process(args) ⇒ Object



7
8
9
# File 'lib/bosh_agent/message/state.rb', line 7

def self.process(args)
  self.new(args).state
end

Instance Method Details

#job_stateObject



42
43
44
# File 'lib/bosh_agent/message/state.rb', line 42

def job_state
  Bosh::Agent::Monit.service_group_state
end

#stateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bosh_agent/message/state.rb', line 17

def state
  response = Bosh::Agent::Config.state.to_hash

  logger.info("Agent state: #{response.inspect}")

  if settings
    response["agent_id"] = settings["agent_id"]
    response["vm"] = settings["vm"]
  end

  response["job_state"] = job_state
  response["bosh_protocol"] = Bosh::Agent::BOSH_PROTOCOL
  response["ntp"] = Bosh::Agent::NTP.offset

  if @full_format
    response["vitals"] = Bosh::Agent::Monit.get_vitals
    response["vitals"]["disk"] = Bosh::Agent::DiskUtil.get_usage
  end

  response

rescue Bosh::Agent::StateError => e
  raise Bosh::Agent::MessageHandlerError, e
end