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.16.1-java lib/sqreen/metrics/average.rb
sqreen-1.16.1 lib/sqreen/metrics/average.rb
sqreen-1.16.0-java lib/sqreen/metrics/average.rb
sqreen-1.16.0 lib/sqreen/metrics/average.rb
sqreen-1.15.8-java lib/sqreen/metrics/average.rb
sqreen-1.15.8 lib/sqreen/metrics/average.rb
sqreen-1.15.8.beta2-java lib/sqreen/metrics/average.rb
sqreen-1.15.8.beta2 lib/sqreen/metrics/average.rb
sqreen-1.15.8.beta1-java lib/sqreen/metrics/average.rb
sqreen-1.15.8.beta1 lib/sqreen/metrics/average.rb
sqreen-1.15.7-java lib/sqreen/metrics/average.rb
sqreen-1.15.7 lib/sqreen/metrics/average.rb
sqreen-1.15.7.beta1-java lib/sqreen/metrics/average.rb
sqreen-1.15.7.beta1 lib/sqreen/metrics/average.rb
sqreen-1.15.6-java lib/sqreen/metrics/average.rb
sqreen-1.15.6 lib/sqreen/metrics/average.rb
sqreen-1.15.5-java lib/sqreen/metrics/average.rb
sqreen-1.15.5 lib/sqreen/metrics/average.rb