Sha256: 20637fef2325adee386df54722e6c00c7502074f728132968ac073cb38e2624c

Contents?: true

Size: 685 Bytes

Versions: 21

Compression:

Stored size: 685 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
      @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
      [{
        bins: (bins + [INFINITY]).map { |bin| [bin.to_f, @bin_counts[bin]] }
      }]
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
honeybadger-5.18.0 lib/honeybadger/histogram.rb
honeybadger-5.17.0 lib/honeybadger/histogram.rb
honeybadger-5.16.0 lib/honeybadger/histogram.rb
honeybadger-5.15.6 lib/honeybadger/histogram.rb
honeybadger-5.15.5 lib/honeybadger/histogram.rb
honeybadger-5.15.4 lib/honeybadger/histogram.rb
honeybadger-5.15.3 lib/honeybadger/histogram.rb
honeybadger-5.15.2 lib/honeybadger/histogram.rb
honeybadger-5.15.1 lib/honeybadger/histogram.rb
honeybadger-5.15.0 lib/honeybadger/histogram.rb
honeybadger-5.14.2 lib/honeybadger/histogram.rb
honeybadger-5.14.1 lib/honeybadger/histogram.rb
honeybadger-5.14.0 lib/honeybadger/histogram.rb
honeybadger-5.13.3 lib/honeybadger/histogram.rb
honeybadger-5.13.2 lib/honeybadger/histogram.rb
honeybadger-5.13.1 lib/honeybadger/histogram.rb
honeybadger-5.13.0 lib/honeybadger/histogram.rb
honeybadger-5.12.0 lib/honeybadger/histogram.rb
honeybadger-5.11.2 lib/honeybadger/histogram.rb
honeybadger-5.11.1 lib/honeybadger/histogram.rb