class OpenCensus::Stats::AggregationData::Distribution
This AggregationData
contains a histogram of the collected values
Attributes
@return [Array<Integer>] Count
of number of recorded values in buckets
@return [Array<Integer>,Array<Float>] Buckets boundries
@return [Integer] Count
of recorded values
@return [Array<Exemplar>] Exemplars are points associated with each
bucket in the distribution giving an example of what was aggregated into the bucket.
@return [Integer,Float] Maximum recorded value
@return [Integer,Float] Mean of recorded values
@return [Integer,Float] Minimum recorded value
@return [Time] Time of first recorded value
@return [Integer,Float] Sum
of recorded values
@return [Integer,Float] Sum
of squared deviation of recorded values
@return [Time] The latest time a new value was recorded
Public Class Methods
@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
@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
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