Class: RServiceBus2::StatisticManager
- Inherits:
-
Object
- Object
- RServiceBus2::StatisticManager
- Defined in:
- lib/rservicebus2/statistic_manager.rb
Overview
Used to collect various run time stats for runtime reporting
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #get_for_reporting_2 ⇒ Object
- #get_for_reporting_9 ⇒ Object
- #inc(key) ⇒ Object
- #inc_message_type(class_name) ⇒ Object
- #inc_total_errored ⇒ Object
- #inc_total_processed ⇒ Object
- #inc_total_published ⇒ Object
- #inc_total_reply ⇒ Object
- #inc_total_sent ⇒ Object
-
#initialize(host) ⇒ StatisticManager
constructor
A new instance of StatisticManager.
- #report ⇒ Object
- #tick ⇒ Object
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
#output ⇒ Object
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_2 ⇒ Object
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_9 ⇒ Object
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 (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_errored ⇒ Object
28 29 30 |
# File 'lib/rservicebus2/statistic_manager.rb', line 28 def inc_total_errored @total_errored += 1 end |
#inc_total_processed ⇒ Object
24 25 26 |
# File 'lib/rservicebus2/statistic_manager.rb', line 24 def inc_total_processed @total_processed += 1 end |
#inc_total_published ⇒ Object
36 37 38 |
# File 'lib/rservicebus2/statistic_manager.rb', line 36 def inc_total_published @total_published += 1 end |
#inc_total_reply ⇒ Object
40 41 42 |
# File 'lib/rservicebus2/statistic_manager.rb', line 40 def inc_total_reply @total_reply += 1 end |
#inc_total_sent ⇒ Object
32 33 34 |
# File 'lib/rservicebus2/statistic_manager.rb', line 32 def inc_total_sent @total_sent += 1 end |
#report ⇒ Object
74 75 76 |
# File 'lib/rservicebus2/statistic_manager.rb', line 74 def report @host.log(get_for_reporting_9) if @output end |
#tick ⇒ Object
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 |