Sha256: 82fefd48f52194e6514d59b5adfb3c46e7c18bfdeb2cb15627710cdb8f5a35ba

Contents?: true

Size: 827 Bytes

Versions: 38

Compression:

Stored size: 827 Bytes

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.io/terms.html

require 'sqreen/metrics/base'

module Sqreen
  module Metric
    # This perform an average aggregation
    class Average < Base
      # from class attr_accessor :aggregate

      def update(key, value)
        super
        @sums[key] ||= 0
        @sums[key] += value
        @counts[key] ||= 0
        @counts[key] += 1
      end

      protected

      def new_sample(time)
        super(time)
        @sums = {}
        @counts = {}
      end

      def finalize_sample(time)
        super(time)
        @sample[FINISH_KEY] = time
        h = {}
        @sums.each do |k, v|
          h[k] = v.to_f / @counts[k]
        end
        @sample[OBSERVATION_KEY] = h
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
sqreen-1.18.1-java lib/sqreen/metrics/average.rb
sqreen-1.18.1 lib/sqreen/metrics/average.rb
sqreen-1.18.0-java lib/sqreen/metrics/average.rb
sqreen-1.18.0 lib/sqreen/metrics/average.rb
sqreen-1.17.2-java lib/sqreen/metrics/average.rb
sqreen-1.17.2 lib/sqreen/metrics/average.rb
sqreen-1.17.2.rc1-java lib/sqreen/metrics/average.rb
sqreen-1.17.2.rc1 lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta4-java lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta4 lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta3-java lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta3 lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta2-java lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta2 lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta1-java lib/sqreen/metrics/average.rb
sqreen-1.17.2.beta1 lib/sqreen/metrics/average.rb
sqreen-1.17.0-java lib/sqreen/metrics/average.rb
sqreen-1.17.0 lib/sqreen/metrics/average.rb
sqreen-1.16.2-java lib/sqreen/metrics/average.rb
sqreen-1.16.2 lib/sqreen/metrics/average.rb