Class: God::Metric

Inherits:
Object
  • Object
show all
Defined in:
lib/god/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watch, destination = nil) ⇒ Metric

Returns a new instance of Metric.



6
7
8
9
10
# File 'lib/god/metric.rb', line 6

def initialize(watch, destination = nil)
  self.watch = watch
  self.destination = destination
  self.conditions = []
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions.



4
5
6
# File 'lib/god/metric.rb', line 4

def conditions
  @conditions
end

#destinationObject

Returns the value of attribute destination.



4
5
6
# File 'lib/god/metric.rb', line 4

def destination
  @destination
end

#watchObject

Returns the value of attribute watch.



4
5
6
# File 'lib/god/metric.rb', line 4

def watch
  @watch
end

Instance Method Details

#condition(kind) {|c| ... } ⇒ Object

Instantiate a Condition of type kind and pass it into the optional block. Attributes of the condition must be set in the config file

Yields:

  • (c)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/god/metric.rb', line 14

def condition(kind)
  # create the condition
  begin
    c = Condition.generate(kind, self.watch)
  rescue NoSuchConditionError => e
    abort e.message
  end
  
  # send to block so config can set attributes
  yield(c) if block_given?
  
  # call prepare on the condition
  c.prepare
  
  # test generic and specific validity
  unless Condition.valid?(c) && c.valid?
    abort "Exiting on invalid condition"
  end
  
  # inherit interval from watch if no poll condition specific interval was set
  if c.kind_of?(PollCondition) && !c.interval
    if self.watch.interval
      c.interval = self.watch.interval
    else
      abort "No interval set for Condition '#{c.class.name}' in Watch '#{self.watch.name}', and no default Watch interval from which to inherit"
    end
  end
  
  # remember
  self.conditions << c
end

#disableObject



52
53
54
55
56
# File 'lib/god/metric.rb', line 52

def disable
  self.conditions.each do |c|
    self.watch.detach(c)
  end
end

#enableObject



46
47
48
49
50
# File 'lib/god/metric.rb', line 46

def enable
  self.conditions.each do |c|
    self.watch.attach(c)
  end
end