Class: SnowmanIO::Loop::CheckProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/snowman-io/loop/check_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(check) ⇒ CheckProcessor

Returns a new instance of CheckProcessor.



4
5
6
7
# File 'lib/snowman-io/loop/check_processor.rb', line 4

def initialize(check)
  @check  = check
  @metric = check.metric
end

Instance Method Details

#processObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/snowman-io/loop/check_processor.rb', line 9

def process
  if @check.template == Check::TEMPLATE_LAST_VALUE_LIMIT
    @check.cmp_fn.call(@metric.last_value, @check.value)

  elsif @check.template == Check::TEMPLATE_PREV_DAY_DATAPOINTS_LIMIT
    # use aggregation for prev day
    at = Time.now.beginning_of_day - 1.day
    if @metric.created_at < at # require full gather day
      count = @metric.aggregations.where("precision" => "daily", "at" => at).first.try(&:count).to_i
      @check.cmp_fn.call(count, @check.value)
    else
      false
    end

  else
    raise "Unknown check template: #{@check.template}"
  end
end