Class: Flamingo::Stats::RateCounter
- Inherits:
-
Object
- Object
- Flamingo::Stats::RateCounter
- Defined in:
- lib/flamingo/stats/rate_counter.rb
Overview
Simple counter for measuring stream rates in events per second
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#rate ⇒ Object
Returns the value of attribute rate.
Instance Method Summary collapse
- #event! ⇒ Object
-
#initialize(sample_duration = 60, &block) ⇒ RateCounter
constructor
A new instance of RateCounter.
Constructor Details
#initialize(sample_duration = 60, &block) ⇒ RateCounter
Returns a new instance of RateCounter.
9 10 11 12 13 |
# File 'lib/flamingo/stats/rate_counter.rb', line 9 def initialize(sample_duration=60, &block) @sample_duration = sample_duration self.callback = block start_sample end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
7 8 9 |
# File 'lib/flamingo/stats/rate_counter.rb', line 7 def callback @callback end |
#rate ⇒ Object
Returns the value of attribute rate.
7 8 9 |
# File 'lib/flamingo/stats/rate_counter.rb', line 7 def rate @rate end |
Instance Method Details
#event! ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flamingo/stats/rate_counter.rb', line 15 def event! @count += 1 if (diff = (now - @sample_start_time)) >= @sample_duration self.rate = (@count / diff.to_f) if callback callback.call(rate) end start_sample end end |