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.



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

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

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



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

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



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

def min
  @min
end

#statsObject (readonly)

Returns the value of attribute stats.



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

def stats
  @stats
end

Instance Method Details

#max_millisObject



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

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

#min_millisObject



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

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.)



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

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



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

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