Class: Sqreen::Metric::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sqreen/metrics/base.rb

Overview

Base interface for a metric

Direct Known Subclasses

Average, Binning, Collect, Sum

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_opts = {}) ⇒ Base



18
19
20
# File 'lib/sqreen/metrics/base.rb', line 18

def initialize(_opts={})
  @sample = nil
end

Instance Attribute Details

#nameObject

for signals serialization



15
16
17
# File 'lib/sqreen/metrics/base.rb', line 15

def name
  @name
end

#periodObject

for signals serialization



15
16
17
# File 'lib/sqreen/metrics/base.rb', line 15

def period
  @period
end

#ruleObject

optional



16
17
18
# File 'lib/sqreen/metrics/base.rb', line 16

def rule
  @rule
end

Instance Method Details

#next_sample(time) ⇒ Object

create a new empty sample and publish the last one



32
33
34
35
36
37
# 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) ⇒ Object

Update the current metric with a new observation

Raises:



26
27
28
# File 'lib/sqreen/metrics/base.rb', line 26

def update(_key, _value)
  raise Sqreen::Exception, 'No current sample' unless @sample
end