Class: Anomonitor::Configuration

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

Defined Under Namespace

Classes: AlertRule, CollectorsConfig, TableSource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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
# File 'lib/anomonitor/configuration.rb', line 14

def initialize
  @webhook_url = nil
  @notifier = nil
  @poll_interval = 60
  @cooldown = 15 * 60
  @retention_days = 7
  @dashboard_path = "/anomonitor"
  @dashboard_base_url = nil
  @schema_drift_interval = 15 * 60
  @authenticate = nil
  @poll_lock = true
  @digest_interval = nil
  @digest_last_flushed_at = nil
  @notifier_rate_limit = 0
  @poll_mode = :thread
  @auto_start = true
  @collectors = CollectorsConfig.new
  @tables = []
  @alerts = []

  @tenants = nil
  @exclude_tenants = %w[public]
  @tenant_switch = nil

  @schema_drift_exclude = %w[
    schema_migrations
    ar_internal_metadata
    anomonitor_*
  ]
end

Instance Attribute Details

#alertsObject (readonly)

Returns the value of attribute alerts.



12
13
14
# File 'lib/anomonitor/configuration.rb', line 12

def alerts
  @alerts
end

#authenticateObject

Returns the value of attribute authenticate.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def authenticate
  @authenticate
end

#auto_startObject

Returns the value of attribute auto_start.



12
13
14
# File 'lib/anomonitor/configuration.rb', line 12

def auto_start
  @auto_start
end

#collectorsObject (readonly)

Returns the value of attribute collectors.



12
13
14
# File 'lib/anomonitor/configuration.rb', line 12

def collectors
  @collectors
end

#cooldownObject

Returns the value of attribute cooldown.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def cooldown
  @cooldown
end

#dashboard_base_urlObject

Returns the value of attribute dashboard_base_url.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def dashboard_base_url
  @dashboard_base_url
end

#dashboard_pathObject

Returns the value of attribute dashboard_path.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def dashboard_path
  @dashboard_path
end

#digest_intervalObject

Returns the value of attribute digest_interval.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def digest_interval
  @digest_interval
end

#digest_last_flushed_atObject

Returns the value of attribute digest_last_flushed_at.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def digest_last_flushed_at
  @digest_last_flushed_at
end

#exclude_tenantsObject

Returns the value of attribute exclude_tenants.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def exclude_tenants
  @exclude_tenants
end

#notifierObject

Returns the value of attribute notifier.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def notifier
  @notifier
end

#notifier_rate_limitObject

Returns the value of attribute notifier_rate_limit.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def notifier_rate_limit
  @notifier_rate_limit
end

#poll_intervalObject

Returns the value of attribute poll_interval.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def poll_interval
  @poll_interval
end

#poll_lockObject

Returns the value of attribute poll_lock.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def poll_lock
  @poll_lock
end

#poll_modeObject

Returns the value of attribute poll_mode.



12
13
14
# File 'lib/anomonitor/configuration.rb', line 12

def poll_mode
  @poll_mode
end

#retention_daysObject

Returns the value of attribute retention_days.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def retention_days
  @retention_days
end

#schema_drift_excludeObject

Returns the value of attribute schema_drift_exclude.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def schema_drift_exclude
  @schema_drift_exclude
end

#schema_drift_intervalObject

Returns the value of attribute schema_drift_interval.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def schema_drift_interval
  @schema_drift_interval
end

#tablesObject (readonly)

Returns the value of attribute tables.



12
13
14
# File 'lib/anomonitor/configuration.rb', line 12

def tables
  @tables
end

#tenant_switchObject

Returns the value of attribute tenant_switch.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def tenant_switch
  @tenant_switch
end

#tenantsObject

Returns the value of attribute tenants.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def tenants
  @tenants
end

#webhook_urlObject

Returns the value of attribute webhook_url.



5
6
7
# File 'lib/anomonitor/configuration.rb', line 5

def webhook_url
  @webhook_url
end

Instance Method Details

#alert(metric, **options) ⇒ Object



96
97
98
99
100
# File 'lib/anomonitor/configuration.rb', line 96

def alert(metric, **options)
  rule = AlertRule.new(metric, **options)
  @alerts << rule
  rule
end

#anomaly_dashboard_url(anomaly_id) ⇒ Object



45
46
47
48
49
50
# File 'lib/anomonitor/configuration.rb', line 45

def anomaly_dashboard_url(anomaly_id)
  path = "#{dashboard_path.to_s.sub(%r{/+\z}, "")}/anomalies/#{anomaly_id}"
  path = "/#{path}" unless path.start_with?("/")
  base = dashboard_base_url.to_s.strip.sub(%r{/+\z}, "")
  base.empty? ? path : "#{base}#{path}"
end

#build_notifierObject



52
53
54
# File 'lib/anomonitor/configuration.rb', line 52

def build_notifier
  Notifiers.build(self)
end

#digest_enabled?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/anomonitor/configuration.rb', line 56

def digest_enabled?
  digest_interval.to_i.positive?
end

#mute(duration:, metric: nil, rule: nil, source: nil, tenant: nil, reason: nil) ⇒ Object

Persist a mute (DB) — metric/rule/source/tenant are optional matchers. duration: seconds or ActiveSupport duration (e.g. 24.hours)



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/anomonitor/configuration.rb', line 62

def mute(duration:, metric: nil, rule: nil, source: nil, tenant: nil, reason: nil)
  seconds = duration.respond_to?(:to_i) ? duration.to_i : duration
  Mute.create!(
    metric: metric&.to_s,
    rule: rule&.to_s,
    source: source&.to_s,
    tenant: tenant&.to_s,
    muted_until: Time.current + seconds,
    reason: reason
  )
end

#table(name) {|source| ... } ⇒ Object

Yields:

  • (source)


89
90
91
92
93
94
# File 'lib/anomonitor/configuration.rb', line 89

def table(name, &block)
  source = TableSource.new(name)
  yield source if block_given?
  @tables << source
  source
end