Class: Salus::Absolute

Inherits:
Metric
  • Object
show all
Defined in:
lib/salus/metric/absolute.rb

Constant Summary

Constants inherited from Metric

Metric::STORAGE_DEPTH

Instance Method Summary collapse

Methods inherited from Metric

#clear, descendants, #expired?, inherited, #initialize, #load, #mute?, #push, #save, #timestamp, #to_h, #ttl, #value

Methods included from Lockable

#broadcast, #signal, #synchronize, #wait, #wait_until

Methods included from Logging

#log

Constructor Details

This class inherits a constructor from Salus::Metric

Instance Method Details

#calcObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/salus/metric/absolute.rb', line 3

def calc
  super
  @last_calced_value = nil

  if @values.length < STORAGE_DEPTH
    return
  elsif @values[0].expired?(@values[1].timestamp)
    return
  elsif !@values[1].value.is_a?(Numeric)
    return
  end

  @last_calced_value = begin
    dt = (@values[1].timestamp - @values[0].timestamp)
    (dt == 0) ? nil : (@values[1].value / dt)
  end
end