Sha256: d65373e4a3fe37e271fa4e8f231c1527439a1234ad47ab984be1eeb9d46baf47
Contents?: true
Size: 996 Bytes
Versions: 11
Compression:
Stored size: 996 Bytes
Contents
require 'honeybadger/metric' module Honeybadger class Histogram < Metric DEFAULT_BINS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0] INFINITY = 1e20.to_f # not quite, but pretty much def record(value) return unless value @samples += 1 @total ||= 0 @total = @total + value @min = value if @min.nil? || @min > value @max = value if @max.nil? || @max < value @avg = @total.to_f / @samples @latest = value @bin_counts ||= Hash.new(0) @bin_counts[find_bin(value)] += 1 end def find_bin(value) bin = bins.find {|b| b >= value } bin = INFINITY if bin.nil? bin end def bins @attributes.fetch(:bins, DEFAULT_BINS).sort end def payloads [{ total: @total, min: @min, max: @max, avg: @avg, latest: @latest, bins: (bins + [INFINITY]).map { |bin| [bin.to_f, @bin_counts[bin]] } }] end end end
Version data entries
11 entries across 11 versions & 1 rubygems