class OpenCensus::Stats::AggregationData::Distribution

# Distribution

This AggregationData contains a histogram of the collected values

Attributes

bucket_counts[R]

@return [Array<Integer>] Count of number of recorded values in buckets

buckets[R]

@return [Array<Integer>,Array<Float>] Buckets boundries

count[R]

@return [Integer] Count of recorded values

exemplars[R]

@return [Array<Exemplar>] Exemplars are points associated with each

bucket in the distribution giving an example of what was aggregated
into the bucket.
max[R]

@return [Integer,Float] Maximum recorded value

mean[R]

@return [Integer,Float] Mean of recorded values

min[R]

@return [Integer,Float] Minimum recorded value

start_time[R]

@return [Time] Time of first recorded value

sum[R]

@return [Integer,Float] Sum of recorded values

sum_of_squared_deviation[R]

@return [Integer,Float] Sum of squared deviation of recorded values

time[R]

@return [Time] The latest time a new value was recorded

Public Class Methods

new(buckets) click to toggle source

@private @param [Array<Integer>,Array<Float>] buckets Buckets boundries for distribution

# File lib/opencensus/stats/aggregation_data/distribution.rb, line 49
def initialize buckets
  @buckets = buckets
  @count = 0
  @sum = 0
  @max = -Float::INFINITY
  @min = Float::INFINITY
  @mean = 0
  @sum_of_squared_deviation = 0
  @bucket_counts = Array.new(buckets.length + 1, 0)
  @exemplars = []
  @start_time = Time.now.utc
end

Public Instance Methods

add(value, time, attachments: nil) click to toggle source

@private Add value to distribution @param [Integer,Float] value @param [Time] time Time of data point was recorded @param [Hash<String,String>,nil] attachments Attachments are key-value

pairs that describe the context in which the exemplar was recored.
# File lib/opencensus/stats/aggregation_data/distribution.rb, line 68
def add value, time, attachments: nil
  @time = time
  @count += 1
  @sum += value
  @max = value if value > @max
  @min = value if value < @min

  delta_from_mean = (value - @mean).to_f
  @mean += delta_from_mean / @count
  @sum_of_squared_deviation += delta_from_mean * (value - @mean)

  bucket_index = @buckets.find_index { |b| b > value } ||
                 @buckets.length
  @bucket_counts[bucket_index] += 1

  if attachments
    @exemplars[bucket_index] = Exemplar.new(
      value: value,
      time: time,
      attachments: attachments
    )
  end
end
value() click to toggle source

Get distribution result values. @return [Hash]

# File lib/opencensus/stats/aggregation_data/distribution.rb, line 94
def value
  {
    start_time: @start_time,
    count: @count,
    sum: @sum,
    max: @max,
    min: @min,
    sum_of_squared_deviation: @sum_of_squared_deviation,
    buckets: @buckets,
    bucket_counts: @bucket_counts
  }
end