Sha256: 353e32ce593907e9f7aad5abd61bfacabc723e4683d893edc9a9c0a775c7a512
Contents?: true
Size: 1.29 KB
Versions: 38
Compression:
Stored size: 1.29 KB
Contents
# Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.io/terms.html require 'sqreen/exception' module Sqreen module Metric OBSERVATION_KEY = 'observation'.freeze START_KEY = 'start'.freeze FINISH_KEY = 'finish'.freeze # Base interface for a metric class Base def initialize(_opts={}) @sample = nil end # Update the current metric with a new observation # @param _at [Time] when was the observation made # @param _key [String] which aggregation key was it made for # @param _value [Object] The observation def update(_key, _value) raise Sqreen::Exception, 'No current sample' unless @sample end # create a new empty sample and publish the last one # @param time [Float] Time of start of new sample/end of the last one def next_sample(time) finalize_sample(time) unless @sample.nil? current_sample = @sample new_sample(time) current_sample end protected # @param time [Float] def new_sample(time) @sample = { OBSERVATION_KEY => {}, START_KEY => time } end # @param time [Float] def finalize_sample(time) @sample[FINISH_KEY] = time end end end end
Version data entries
38 entries across 38 versions & 1 rubygems