Class: Honeybadger::Histogram

Inherits:
Metric
  • Object
show all
Defined in:
lib/honeybadger/histogram.rb

Constant Summary collapse

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 =

not quite, but pretty much

1e20.to_f

Instance Attribute Summary

Attributes inherited from Metric

#attributes, #name, #samples

Instance Method Summary collapse

Methods inherited from Metric

#base_payload, #event_payloads, #initialize, #metric_type, metric_type, register, signature, #signature

Constructor Details

This class inherits a constructor from Honeybadger::Metric

Instance Method Details

#binsObject



22
23
24
# File 'lib/honeybadger/histogram.rb', line 22

def bins
  @attributes.fetch(:bins, DEFAULT_BINS).sort
end

#find_bin(value) ⇒ Object



16
17
18
19
20
# File 'lib/honeybadger/histogram.rb', line 16

def find_bin(value)
  bin = bins.find {|b| b >= value  }
  bin = INFINITY if bin.nil?
  bin
end

#payloadsObject



26
27
28
29
30
# File 'lib/honeybadger/histogram.rb', line 26

def payloads
  [{
    bins: (bins + [INFINITY]).map { |bin| [bin.to_f, @bin_counts[bin]] }
  }]
end

#record(value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/honeybadger/histogram.rb', line 8

def record(value)
  return unless value

  @samples += 1
  @bin_counts ||= Hash.new(0)
  @bin_counts[find_bin(value)] += 1
end