Class: Rack::Healthz::RequestAccumulator
- Inherits:
-
Object
- Object
- Rack::Healthz::RequestAccumulator
- Defined in:
- lib/rack/healthz/request_accumulator.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#max_time ⇒ Object
readonly
Returns the value of attribute max_time.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#min_time ⇒ Object
readonly
Returns the value of attribute min_time.
-
#std ⇒ Object
readonly
Returns the value of attribute std.
Instance Method Summary collapse
- #<<(elapsed_time) ⇒ Object
-
#initialize(category) ⇒ RequestAccumulator
constructor
A new instance of RequestAccumulator.
- #to_h ⇒ Object
Constructor Details
#initialize(category) ⇒ RequestAccumulator
Returns a new instance of RequestAccumulator.
7 8 9 10 11 12 13 14 |
# File 'lib/rack/healthz/request_accumulator.rb', line 7 def initialize(category) @category = category @count = 0 @sum_of_times = 0.0 @sum_of_square_times = 0.0 @min_time = Float::INFINITY @max_time = -Float::INFINITY end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def category @category end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def count @count end |
#max_time ⇒ Object (readonly)
Returns the value of attribute max_time.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def max_time @max_time end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def mean @mean end |
#min_time ⇒ Object (readonly)
Returns the value of attribute min_time.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def min_time @min_time end |
#std ⇒ Object (readonly)
Returns the value of attribute std.
5 6 7 |
# File 'lib/rack/healthz/request_accumulator.rb', line 5 def std @std end |
Instance Method Details
#<<(elapsed_time) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/healthz/request_accumulator.rb', line 16 def <<(elapsed_time) @count += 1 @sum_of_times += elapsed_time @sum_of_square_times += elapsed_time ** 2 @min_time = [@min_time, elapsed_time].min @max_time = [@max_time, elapsed_time].max @mean = @sum_of_times / @count @std = if @count > 1 Math.sqrt((@sum_of_square_times / @count) - (@sum_of_times / @count) ** 2) elsif @count == 1 0.0 else nil end self end |
#to_h ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/healthz/request_accumulator.rb', line 34 def to_h { 'count' => count, 'min' => min_time, 'max' => max_time, 'mean' => mean, 'std' => std } end |