Class: Anomonitor::Configuration::AlertRule
- Inherits:
-
Object
- Object
- Anomonitor::Configuration::AlertRule
- Defined in:
- lib/anomonitor/configuration.rb
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#multiplier ⇒ Object
readonly
Returns the value of attribute multiplier.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
-
#initialize(metric, max: nil, window: nil, multiplier: nil, severity: "high", match: {}) ⇒ AlertRule
constructor
A new instance of AlertRule.
-
#matches_point?(point) ⇒ Boolean
match: { queue: true } => tag present; { queue: nil } => tag absent; { queue: "x" } => exact.
- #spike? ⇒ Boolean
- #threshold? ⇒ Boolean
- #window_seconds ⇒ Object
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
#match ⇒ Object (readonly)
Returns the value of attribute match.
135 136 137 |
# File 'lib/anomonitor/configuration.rb', line 135 def match @match end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
135 136 137 |
# File 'lib/anomonitor/configuration.rb', line 135 def max @max end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
135 136 137 |
# File 'lib/anomonitor/configuration.rb', line 135 def metric @metric end |
#multiplier ⇒ Object (readonly)
Returns the value of attribute multiplier.
135 136 137 |
# File 'lib/anomonitor/configuration.rb', line 135 def multiplier @multiplier end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
135 136 137 |
# File 'lib/anomonitor/configuration.rb', line 135 def severity @severity end |
#window ⇒ Object (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
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.[key] || point.[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
150 151 152 |
# File 'lib/anomonitor/configuration.rb', line 150 def spike? !multiplier.nil? end |
#threshold? ⇒ Boolean
146 147 148 |
# File 'lib/anomonitor/configuration.rb', line 146 def threshold? !max.nil? end |
#window_seconds ⇒ Object
154 155 156 |
# File 'lib/anomonitor/configuration.rb', line 154 def window_seconds @window || (5 * 60) end |