Class: Bosh::Monitor::Events::Heartbeat

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/monitor/events/heartbeat.rb

Constant Summary collapse

CORE_JOBS =
Set.new(%w(cloud_controller dea health_manager nats router routerv2 stager uaa))
SERVICE_JOBS_PREFIXES =
%w(mysql mongodb rabbit postgresql vblob).join("|")
SERVICE_JOBS_GATEWAY_REGEX =
/(#{SERVICE_JOBS_PREFIXES})_gateway$/i
SERVICE_JOBS_NODE_REGEX =
/(#{SERVICE_JOBS_PREFIXES})_node(.*)/i
SERVICE_AUXILIARY_JOBS =
Set.new(%w(serialization_data_server backup_manager))

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #errors, #id, #kind, #logger

Instance Method Summary collapse

Methods inherited from Base

#add_error, create, create!, #error_message, #valid?

Constructor Details

#initialize(attributes = {}) ⇒ Heartbeat

Returns a new instance of Heartbeat.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bosh/monitor/events/heartbeat.rb', line 15

def initialize(attributes = {})
  super
  @kind = :heartbeat
  @metrics = []

  @id = @attributes["id"]
  @timestamp = Time.at(@attributes["timestamp"]) rescue @attributes["timestamp"]

  @deployment = @attributes["deployment"]
  @agent_id = @attributes["agent_id"]
  @job = @attributes["job"]
  @index = @attributes["index"].to_s
  @node_id = @attributes["node_id"]
  @job_state = @attributes["job_state"]

  @tags = {}
  @tags["job"] = @job if @job
  @tags["index"] = @index if @index
  @tags["id"] = @node_id if @node_id
  @tags["role"] = guess_role

  @vitals = @attributes["vitals"] || {}
  @load = @vitals["load"] || []
  @cpu = @vitals["cpu"] || {}
  @mem = @vitals["mem"] || {}
  @swap = @vitals["swap"] || {}
  @disk = @vitals["disk"] || {}
  @system_disk = @disk["system"] || {}
  @ephemeral_disk = @disk["ephemeral"] || {}
  @persistent_disk = @disk["persistent"] || {}

  populate_metrics
end

Instance Attribute Details

#agent_idObject (readonly)

Returns the value of attribute agent_id.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def agent_id
  @agent_id
end

#deploymentObject (readonly)

Returns the value of attribute deployment.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def deployment
  @deployment
end

#indexObject (readonly)

Returns the value of attribute index.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def index
  @index
end

#jobObject (readonly)

Returns the value of attribute job.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def job
  @job
end

#metricsObject (readonly)

Returns the value of attribute metrics.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def metrics
  @metrics
end

#node_idObject (readonly)

Returns the value of attribute node_id.



13
14
15
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13

def node_id
  @node_id
end

Instance Method Details

#add_metric(name, value) ⇒ Object



58
59
60
# File 'lib/bosh/monitor/events/heartbeat.rb', line 58

def add_metric(name, value)
  @metrics << Metric.new(name, value, @timestamp.to_i, @tags) if value
end

#short_descriptionObject



62
63
64
65
66
67
68
69
70
# File 'lib/bosh/monitor/events/heartbeat.rb', line 62

def short_description
  description = "Heartbeat from #{@job}/#{@node_id} (agent_id=#{@agent_id}"

  if @index && !@index.empty?
    description = description + " index=#{@index}"
  end

  description + ") @ #{@timestamp.utc}"
end

#to_hashObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bosh/monitor/events/heartbeat.rb', line 76

def to_hash
  {
    :kind => "heartbeat",
    :id => @id,
    :timestamp => @timestamp.to_i,
    :deployment => @deployment,
    :agent_id => @agent_id,
    :job => @job,
    :index => @index,
    :node_id => @node_id,
    :job_state => @job_state,
    :vitals => @vitals
  }
end

#to_jsonObject



91
92
93
# File 'lib/bosh/monitor/events/heartbeat.rb', line 91

def to_json
  Yajl::Encoder.encode(self.to_hash)
end

#to_plain_textObject



95
96
97
# File 'lib/bosh/monitor/events/heartbeat.rb', line 95

def to_plain_text
  self.short_description
end

#to_sObject



72
73
74
# File 'lib/bosh/monitor/events/heartbeat.rb', line 72

def to_s
  self.short_description
end

#validateObject



49
50
51
52
53
54
55
56
# File 'lib/bosh/monitor/events/heartbeat.rb', line 49

def validate
  add_error("id is missing") if @id.nil?
  add_error("timestamp is missing") if @timestamp.nil?

  if @timestamp && !@timestamp.kind_of?(Time)
    add_error("timestamp is invalid")
  end
end