Class: Bosh::Agent::Heartbeat
Instance Attribute Summary collapse
-
#agent_id ⇒ Object
Mostly for tests so we can override these without touching Config.
-
#logger ⇒ Object
Mostly for tests so we can override these without touching Config.
-
#nats ⇒ Object
Mostly for tests so we can override these without touching Config.
-
#state ⇒ Object
Mostly for tests so we can override these without touching Config.
Instance Method Summary collapse
-
#heartbeat_payload ⇒ Object
Heartbeat payload example: { “job”: “cloud_controller”, “index”: 3, “job_state”:“running”, “vitals”: { “load”: [“0.09”,“0.04”,“0.01”], “cpu”: “user”:“0.0”,“sys”:“0.0”,“wait”:“0“user”:“0.0”,“sys”:“0.0”,“wait”:“0.4”, “mem”: “percent”:“3.5”,“kb”:“145996”, “swap”: “percent”:“0.0”,“kb”:“0”, “disk”: { “system”: => “82”, “ephemeral”: => “5”, “persistent”: => “94” }, “ntp”: { “offset”: “-0.06423”, “timestamp”: “14 Oct 11:13:19” } }.
-
#initialize ⇒ Heartbeat
constructor
A new instance of Heartbeat.
- #send_via_mbus ⇒ Object
Constructor Details
Instance Attribute Details
#agent_id ⇒ Object
Mostly for tests so we can override these without touching Config
8 9 10 |
# File 'lib/bosh_agent/heartbeat.rb', line 8 def agent_id @agent_id end |
#logger ⇒ Object
Mostly for tests so we can override these without touching Config
8 9 10 |
# File 'lib/bosh_agent/heartbeat.rb', line 8 def logger @logger end |
#nats ⇒ Object
Mostly for tests so we can override these without touching Config
8 9 10 |
# File 'lib/bosh_agent/heartbeat.rb', line 8 def nats @nats end |
#state ⇒ Object
Mostly for tests so we can override these without touching Config
8 9 10 |
# File 'lib/bosh_agent/heartbeat.rb', line 8 def state @state end |
Instance Method Details
#heartbeat_payload ⇒ Object
Heartbeat payload example:
"job": "cloud_controller",
"index": 3,
"job_state":"running",
"vitals": {
"load": ["0.09","0.04","0.01"],
"cpu": {"user":"0.0","sys":"0.0","wait":"0.4",
"mem": "percent":"3.5","kb":"145996",
"swap": "percent":"0.0","kb":"0",
"disk": {
"system": => "82",
"ephemeral": => "5",
"persistent": => "94"
},
"ntp": {
"offset": "-0.06423",
"timestamp": "14 Oct 11:13:19"
}
}
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bosh_agent/heartbeat.rb', line 55 def heartbeat_payload job_state = Bosh::Agent::Monit.service_group_state monit_vitals = Bosh::Agent::Monit.get_vitals disk_usage = Bosh::Agent::DiskUtil.get_usage job_name = @state["job"] ? @state["job"]["name"] : nil index = @state["index"] vitals = monit_vitals.merge("disk" => disk_usage) Yajl::Encoder.encode("job" => job_name, "index" => index, "job_state" => job_state, "vitals" => vitals, "ntp" => Bosh::Agent::NTP.offset) end |
#send_via_mbus ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bosh_agent/heartbeat.rb', line 17 def send_via_mbus if @state.nil? @logger.error("Unable to send heartbeat: agent state unknown") return end if @nats.nil? raise Bosh::Agent::HeartbeatError, "NATS should be initialized in order to send heartbeats" end @nats.publish("hm.agent.heartbeat.#{@agent_id}", heartbeat_payload) do yield if block_given? @logger.debug("Heartbeat delivered") end @logger.info("Heartbeat sent") end |