Class: Bosh::Monitor::Events::Heartbeat
- 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 vcap_redis))
- SERVICE_JOBS_PREFIXES =
%w(mysql mongodb redis 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
-
#agent_id ⇒ Object
readonly
Returns the value of attribute agent_id.
-
#deployment ⇒ Object
readonly
Returns the value of attribute deployment.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Attributes inherited from Base
#attributes, #errors, #id, #kind, #logger
Instance Method Summary collapse
- #add_metric(name, value) ⇒ Object
-
#initialize(attributes = {}) ⇒ Heartbeat
constructor
A new instance of Heartbeat.
- #short_description ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
- #to_plain_text ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
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 |
# 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 @job_state = @attributes["job_state"] @tags = {} @tags["job"] = @job if @job @tags["index"] = @index if @index @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_id ⇒ Object (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 |
#deployment ⇒ Object (readonly)
Returns the value of attribute deployment.
13 14 15 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13 def deployment @deployment end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
13 14 15 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13 def index @index end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
13 14 15 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13 def job @job end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
13 14 15 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 13 def metrics @metrics end |
Instance Method Details
#add_metric(name, value) ⇒ Object
56 57 58 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 56 def add_metric(name, value) @metrics << Metric.new(name, value, @timestamp.to_i, @tags) if value end |
#short_description ⇒ Object
60 61 62 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 60 def short_description "Heartbeat from #{@job}/#{@index} (#{@agent_id}) @ #{@timestamp.utc}" end |
#to_hash ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 68 def to_hash { :kind => "heartbeat", :id => @id, :timestamp => @timestamp.to_i, :deployment => @deployment, :agent_id => @agent_id, :job => @job, :index => @index, :job_state => @job_state, :vitals => @vitals } end |
#to_json ⇒ Object
82 83 84 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 82 def to_json Yajl::Encoder.encode(self.to_hash) end |
#to_plain_text ⇒ Object
86 87 88 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 86 def to_plain_text self.short_description end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 64 def to_s self.short_description end |
#validate ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/bosh/monitor/events/heartbeat.rb', line 47 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 |