lib/cabin/metrics/histogram.rb in cabin-0.3.8 vs lib/cabin/metrics/histogram.rb in cabin-0.4.1

- old
+ new

@@ -1,11 +1,11 @@ require "cabin/namespace" -require "cabin/inspectable" +require "cabin/metric" require "thread" class Cabin::Metrics::Histogram - include Cabin::Inspectable + include Cabin::Metric # A new Histogram. public def initialize @lock = Mutex.new @@ -18,26 +18,31 @@ # - min # - total sum # # Sliding values of all of these? @total = 0 - @min = 0 - @max = 0 + @min = nil + @max = nil @count = 0 @mean = 0.0 end # def initialize public def record(value) @lock.synchronize do @count += 1 @total += value - @min = value if value < @min - @max = value if value > @max + if @min.nil? or value < @min + @min = value + end + if @max.nil? or value > @max + @max = value + end @mean = @total / @count # TODO(sissel): median # TODO(sissel): percentiles end + emit end # def record # This is a very poor way to access the metric data. # TODO(sissel): Need to figure out a better interface. public