Sha256: 21a67c655e7eab5ae31f88e67439f22d2fc89508eab4b4017cebf45b7f58657f
Contents?: true
Size: 828 Bytes
Versions: 12
Compression:
Stored size: 828 Bytes
Contents
# Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/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
12 entries across 12 versions & 1 rubygems