Class: EventHub::Statistics
- Inherits:
-
Object
- Object
- EventHub::Statistics
- Defined in:
- lib/eventhub/statistics.rb
Instance Attribute Summary collapse
-
#messages_average_process_time ⇒ Object
readonly
Returns the value of attribute messages_average_process_time.
-
#messages_average_size ⇒ Object
readonly
Returns the value of attribute messages_average_size.
-
#messages_successful ⇒ Object
readonly
Returns the value of attribute messages_successful.
-
#messages_unsuccessful ⇒ Object
readonly
Returns the value of attribute messages_unsuccessful.
Instance Method Summary collapse
- #failure ⇒ Object
-
#initialize ⇒ Statistics
constructor
A new instance of Statistics.
- #measure(size, &block) ⇒ Object
- #messages_total ⇒ Object
- #messages_total_process_time ⇒ Object
- #messages_total_size ⇒ Object
- #success(process_time, size) ⇒ Object
Constructor Details
#initialize ⇒ Statistics
Returns a new instance of Statistics.
4 5 6 7 8 9 10 11 |
# File 'lib/eventhub/statistics.rb', line 4 def initialize @messages_successful = 0 @messages_unsuccessful = 0 @messages_average_size = 0 @messages_average_process_time = 0 @messages_total_process_time = 0 @mutex = Mutex.new end |
Instance Attribute Details
#messages_average_process_time ⇒ Object (readonly)
Returns the value of attribute messages_average_process_time.
2 3 4 |
# File 'lib/eventhub/statistics.rb', line 2 def @messages_average_process_time end |
#messages_average_size ⇒ Object (readonly)
Returns the value of attribute messages_average_size.
2 3 4 |
# File 'lib/eventhub/statistics.rb', line 2 def @messages_average_size end |
#messages_successful ⇒ Object (readonly)
Returns the value of attribute messages_successful.
2 3 4 |
# File 'lib/eventhub/statistics.rb', line 2 def @messages_successful end |
#messages_unsuccessful ⇒ Object (readonly)
Returns the value of attribute messages_unsuccessful.
2 3 4 |
# File 'lib/eventhub/statistics.rb', line 2 def @messages_unsuccessful end |
Instance Method Details
#failure ⇒ Object
35 36 37 38 39 40 |
# File 'lib/eventhub/statistics.rb', line 35 def failure @mutex.lock @messages_unsuccessful += 1 ensure @mutex.unlock end |
#measure(size, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eventhub/statistics.rb', line 14 def measure(size, &block) begin start = Time.now yield success(Time.now - start, size) rescue failure raise end end |
#messages_total ⇒ Object
42 43 44 |
# File 'lib/eventhub/statistics.rb', line 42 def + end |
#messages_total_process_time ⇒ Object
46 47 48 |
# File 'lib/eventhub/statistics.rb', line 46 def * end |
#messages_total_size ⇒ Object
50 51 52 |
# File 'lib/eventhub/statistics.rb', line 50 def * end |
#success(process_time, size) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/eventhub/statistics.rb', line 25 def success(process_time, size) @mutex.lock @messages_total_process_time += process_time @messages_average_process_time = ( + process_time) / ( + 1).to_f @messages_average_size = ( + size) / ( + 1).to_f @messages_successful += 1 ensure @mutex.unlock end |