Class: Anomonitor::Configuration::AlertRule

Inherits:
Object
  • Object
show all
Defined in:
lib/anomonitor/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric, max: nil, window: nil, multiplier: nil, severity: "high", match: {}) ⇒ AlertRule

Returns a new instance of AlertRule.



137
138
139
140
141
142
143
144
# File 'lib/anomonitor/configuration.rb', line 137

def initialize(metric, max: nil, window: nil, multiplier: nil, severity: "high", match: {})
  @metric = metric.to_sym
  @max = max
  @window = normalize_duration(window)
  @multiplier = multiplier
  @severity = severity
  @match = (match || {}).transform_keys(&:to_sym)
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def match
  @match
end

#maxObject (readonly)

Returns the value of attribute max.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def max
  @max
end

#metricObject (readonly)

Returns the value of attribute metric.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def metric
  @metric
end

#multiplierObject (readonly)

Returns the value of attribute multiplier.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def multiplier
  @multiplier
end

#severityObject (readonly)

Returns the value of attribute severity.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def severity
  @severity
end

#windowObject (readonly)

Returns the value of attribute window.



135
136
137
# File 'lib/anomonitor/configuration.rb', line 135

def window
  @window
end

Instance Method Details

#matches_point?(point) ⇒ Boolean

match: { queue: true } => tag present; { queue: nil } => tag absent; { queue: "x" } => exact

Returns:

  • (Boolean)


159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/anomonitor/configuration.rb', line 159

def matches_point?(point)
  return true if match.nil? || match.empty?

  match.all? do |key, expected|
    tag = point.tags[key] || point.tags[key.to_s]
    case expected
    when true then !tag.nil? && tag.to_s != ""
    when false, nil then tag.nil? || tag.to_s == ""
    else
      tag.to_s == expected.to_s
    end
  end
end

#spike?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/anomonitor/configuration.rb', line 150

def spike?
  !multiplier.nil?
end

#threshold?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/anomonitor/configuration.rb', line 146

def threshold?
  !max.nil?
end

#window_secondsObject



154
155
156
# File 'lib/anomonitor/configuration.rb', line 154

def window_seconds
  @window || (5 * 60)
end