Class: Honeybadger::Histogram
- Inherits:
-
Metric
- Object
- Metric
- Honeybadger::Histogram
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
Instance Method Details
#bins ⇒ Object
31
32
33
|
# File 'lib/honeybadger/histogram.rb', line 31
def bins
@attributes.fetch(:bins, DEFAULT_BINS).sort
end
|
#find_bin(value) ⇒ Object
25
26
27
28
29
|
# File 'lib/honeybadger/histogram.rb', line 25
def find_bin(value)
bin = bins.find {|b| b >= value }
bin = INFINITY if bin.nil?
bin
end
|
#payloads ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/honeybadger/histogram.rb', line 35
def payloads
[{
total: @total,
min: @min,
max: @max,
avg: @avg,
latest: @latest,
bins: (bins + [INFINITY]).map { |bin| [bin.to_f, @bin_counts[bin]] }
}]
end
|
#record(value) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/honeybadger/histogram.rb', line 8
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
|