class Sqreen::Metric::Base

Base interface for a metric

Attributes

name[RW]
period[RW]
rule[RW]

Public Class Methods

new(_opts={}) click to toggle source
# File lib/sqreen/metrics/base.rb, line 18
def initialize(_opts={})
  @sample = nil
end

Public Instance Methods

next_sample(time) click to toggle source

create a new empty sample and publish the last one @param time [Float] Time of start of new sample/end of the last one

# File lib/sqreen/metrics/base.rb, line 32
def next_sample(time)
  finalize_sample(time) unless @sample.nil?
  current_sample = @sample
  new_sample(time)
  current_sample
end
update(_key, _value) click to toggle source

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

# File lib/sqreen/metrics/base.rb, line 26
def update(_key, _value)
  raise Sqreen::Exception, 'No current sample' unless @sample
end

Protected Instance Methods

finalize_sample(time) click to toggle source

@param time [Float]

# File lib/sqreen/metrics/base.rb, line 47
def finalize_sample(time)
  @sample[FINISH_KEY] = time
end
new_sample(time) click to toggle source

@param time [Float]

# File lib/sqreen/metrics/base.rb, line 42
def new_sample(time)
  @sample = { OBSERVATION_KEY => {}, START_KEY => time }
end