Class: Cabin::Metrics::Histogram
- Inherits:
-
Object
- Object
- Cabin::Metrics::Histogram
- Includes:
- Inspectable
- Defined in:
- lib/cabin/metrics/histogram.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Histogram
constructor
A new instance of Histogram.
- #record(value) ⇒ Object
- #to_hash ⇒ Object
- #value ⇒ Object
Methods included from Inspectable
Constructor Details
#initialize ⇒ Histogram
Returns a new instance of Histogram.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cabin/metrics/histogram.rb', line 10 def initialize @lock = Mutex.new @inspectables = [ :@total, :@min, :@max, :@count, :@mean ] # Histogram should track many things, including: # - percentiles (50, 75, 90, 95, 99?) # - median # - max # - min # - total sum # # Sliding values of all of these? @total = 0 @min = 0 @max = 0 @count = 0 @mean = 0.0 end |
Instance Method Details
#record(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cabin/metrics/histogram.rb', line 30 def record(value) @lock.synchronize do @count += 1 @total += value @min = value if value < @min @max = value if value > @max @mean = @total / @count # TODO(sissel): median # TODO(sissel): percentiles end end |
#to_hash ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cabin/metrics/histogram.rb', line 50 def to_hash return @lock.synchronize do { :count => @count, :total => @total, :min => @min, :max => @max, :mean => @mean, } end end |
#value ⇒ Object
45 46 47 |
# File 'lib/cabin/metrics/histogram.rb', line 45 def value return @lock.synchronize { @count } end |