Class: RServiceBus2::StatisticManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/statistic_manager.rb

Overview

Used to collect various run time stats for runtime reporting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ StatisticManager

Returns a new instance of StatisticManager.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rservicebus2/statistic_manager.rb', line 6

def initialize(host)
  @host = host
  @hash = {}

  @total_processed = 0
  @total_errored = 0
  @total_sent = 0
  @total_published = 0
  @total_reply = 0

  @total_by_message_type = {}

  @output = !RServiceBus2.get_value('VERBOSE', nil).nil?
  @max_stat_output_countdown =
    RServiceBus2.get_value('STAT_OUTPUT_COUNTDOWN', '1').to_i
  @stat_output_countdown = 0
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



4
5
6
# File 'lib/rservicebus2/statistic_manager.rb', line 4

def output
  @output
end

Instance Method Details

#get_for_reporting_2Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rservicebus2/statistic_manager.rb', line 54

def get_for_reporting_2
  return unless @written == false

  @written = true
  types = Hash.new(0)
  ObjectSpace.each_object do |obj|
    types[obj.class] += 1
  end

  types
end

#get_for_reporting_9Object



66
67
68
69
70
71
72
# File 'lib/rservicebus2/statistic_manager.rb', line 66

def get_for_reporting_9
  "T:#{@total_processed};" \
  "E:#{@total_errored};" \
  "S:#{@total_sent};" \
  "P:#{@total_published};" \
  "R:#{@total_reply}"
end

#inc(key) ⇒ Object



44
45
46
47
# File 'lib/rservicebus2/statistic_manager.rb', line 44

def inc(key)
  @hash[key] = 0 if @hash[key].nil?
  @hash[key] += 1
end

#inc_message_type(class_name) ⇒ Object



49
50
51
52
# File 'lib/rservicebus2/statistic_manager.rb', line 49

def inc_message_type(class_name)
  @total_by_message_type[class_name] = 0 if @total_by_message_type[class_name].nil?
  @total_by_message_type[class_name] += 1
end

#inc_total_erroredObject



28
29
30
# File 'lib/rservicebus2/statistic_manager.rb', line 28

def inc_total_errored
  @total_errored += 1
end

#inc_total_processedObject



24
25
26
# File 'lib/rservicebus2/statistic_manager.rb', line 24

def inc_total_processed
  @total_processed += 1
end

#inc_total_publishedObject



36
37
38
# File 'lib/rservicebus2/statistic_manager.rb', line 36

def inc_total_published
  @total_published += 1
end

#inc_total_replyObject



40
41
42
# File 'lib/rservicebus2/statistic_manager.rb', line 40

def inc_total_reply
  @total_reply += 1
end

#inc_total_sentObject



32
33
34
# File 'lib/rservicebus2/statistic_manager.rb', line 32

def inc_total_sent
  @total_sent += 1
end

#reportObject



74
75
76
# File 'lib/rservicebus2/statistic_manager.rb', line 74

def report
  @host.log(get_for_reporting_9) if @output
end

#tickObject



78
79
80
81
82
83
84
# File 'lib/rservicebus2/statistic_manager.rb', line 78

def tick
  @stat_output_countdown -= 1
  return unless @stat_output_countdown <= 0

  report
  @stat_output_countdown = @max_stat_output_countdown
end