Class: NewRelic::Histogram::Bucket

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

Overview

Stores statistics for response times falling in a particular range. A bucket has a min and max response time. A response time event falls in a bucket if min <= r/t < max. A bucket also has an associated metric for reporting data to RPM. The bucket range is encoded in the metic name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max = nil) ⇒ Bucket

Returns a new instance of Bucket.



23
24
25
26
# File 'lib/new_relic/histogram.rb', line 23

def initialize(min, max = nil)
  @min = min
  @max = max
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



21
22
23
# File 'lib/new_relic/histogram.rb', line 21

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



21
22
23
# File 'lib/new_relic/histogram.rb', line 21

def min
  @min
end

#statsObject (readonly)

Returns the value of attribute stats.



21
22
23
# File 'lib/new_relic/histogram.rb', line 21

def stats
  @stats
end

Instance Method Details

#max_millisObject



56
57
58
# File 'lib/new_relic/histogram.rb', line 56

def max_millis
  max.nil? ? nil : (max * 1000).round
end

#min_millisObject



52
53
54
# File 'lib/new_relic/histogram.rb', line 52

def min_millis
  (min * 1000).round
end

#process(value) ⇒ Object

This has return value like <=> but does something more than simply compare. If the value falls within range for the bucket, increment count and return 0; otherwise return a value < 0 if the value belongs in a bucket with a lower range you can guess what it returns if the value belongs in a bucket with a higher range. (Hint: it’s not 0, and it’s not less than zero.)



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/new_relic/histogram.rb', line 38

def process(value)
  if value < min
    return -1

  # max == nil means unlimited max (last bucket)
  elsif max && value >= max
    return 1

  else
    stats.record_data_point(value)
    return 0
  end
end

#to_sObject



60
61
62
# File 'lib/new_relic/histogram.rb', line 60

def to_s
  "#{min_millis} - #{max_millis}: #{stats.call_count}"
end