Class: EventHub::Heartbeat

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/eventhub/heartbeat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#class_to_array, #duration, #format_string, #now_stamp

Constructor Details

#initialize(processor) ⇒ Heartbeat

Returns a new instance of Heartbeat.



8
9
10
11
12
# File 'lib/eventhub/heartbeat.rb', line 8

def initialize(processor)
  @started_at = Time.now
  @processor = processor
  @statistics = @processor.statistics
end

Instance Attribute Details

#processorObject (readonly)

Returns the value of attribute processor.



6
7
8
# File 'lib/eventhub/heartbeat.rb', line 6

def processor
  @processor
end

#started_atObject (readonly)

Returns the value of attribute started_at.



6
7
8
# File 'lib/eventhub/heartbeat.rb', line 6

def started_at
  @started_at
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



6
7
8
# File 'lib/eventhub/heartbeat.rb', line 6

def statistics
  @statistics
end

Instance Method Details

#build_message(action = "running") ⇒ Object



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
48
49
50
51
52
# File 'lib/eventhub/heartbeat.rb', line 15

def build_message(action = "running")
  message = ::EventHub::Message.new
  message.origin_module_id  = processor.name
  message.origin_type       = "processor"
  message.origin_site_id    = 'global'

  message.process_name      = 'event_hub.heartbeat'

  now = Time.now

  # message structure needs more changes
  message.body = {
    version: processor.version,
    action:  action,
    pid:     Process.pid,
    process_name: 'event_hub.heartbeat',

    heartbeat: {
      started:                      now_stamp(started_at),
      stamp_last_beat:              now_stamp(now),
      uptime_in_ms:                 (now - started_at)*1000,
      heartbeat_cycle_in_ms:        processor.heartbeat_cycle_in_s * 1000,
      queues_consuming_from:        processor.listener_queues,
      queues_publishing_to:         ['event_hub.inbound'], # needs more dynamic in the future
      host:                         Socket.gethostname,
      addresses:                    addresses,
      messages: {
        total:                      statistics.messages_total,
        successful:                 statistics.messages_successful,
        unsuccessful:               statistics.messages_unsuccessful,
        average_size:               statistics.messages_average_size,
        average_process_time_in_ms: statistics.messages_average_process_time*1000,
        total_process_time_in_ms:   statistics.messages_total_process_time*1000
      }
    }
  }
  message
end