Class: Anomonitor::Configuration
- Inherits:
-
Object
- Object
- Anomonitor::Configuration
- Defined in:
- lib/anomonitor/configuration.rb
Defined Under Namespace
Classes: AlertRule, CollectorsConfig, TableSource
Instance Attribute Summary collapse
-
#alerts ⇒ Object
readonly
Returns the value of attribute alerts.
-
#authenticate ⇒ Object
Returns the value of attribute authenticate.
-
#auto_start ⇒ Object
Returns the value of attribute auto_start.
-
#collectors ⇒ Object
readonly
Returns the value of attribute collectors.
-
#cooldown ⇒ Object
Returns the value of attribute cooldown.
-
#dashboard_base_url ⇒ Object
Returns the value of attribute dashboard_base_url.
-
#dashboard_path ⇒ Object
Returns the value of attribute dashboard_path.
-
#digest_interval ⇒ Object
Returns the value of attribute digest_interval.
-
#digest_last_flushed_at ⇒ Object
Returns the value of attribute digest_last_flushed_at.
-
#exclude_tenants ⇒ Object
Returns the value of attribute exclude_tenants.
-
#notifier ⇒ Object
Returns the value of attribute notifier.
-
#notifier_rate_limit ⇒ Object
Returns the value of attribute notifier_rate_limit.
-
#poll_interval ⇒ Object
Returns the value of attribute poll_interval.
-
#poll_lock ⇒ Object
Returns the value of attribute poll_lock.
-
#poll_mode ⇒ Object
Returns the value of attribute poll_mode.
-
#retention_days ⇒ Object
Returns the value of attribute retention_days.
-
#schema_drift_exclude ⇒ Object
Returns the value of attribute schema_drift_exclude.
-
#schema_drift_interval ⇒ Object
Returns the value of attribute schema_drift_interval.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#tenant_switch ⇒ Object
Returns the value of attribute tenant_switch.
-
#tenants ⇒ Object
Returns the value of attribute tenants.
-
#webhook_url ⇒ Object
Returns the value of attribute webhook_url.
Instance Method Summary collapse
- #alert(metric, **options) ⇒ Object
- #anomaly_dashboard_url(anomaly_id) ⇒ Object
- #build_notifier ⇒ Object
- #digest_enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#mute(duration:, metric: nil, rule: nil, source: nil, tenant: nil, reason: nil) ⇒ Object
Persist a mute (DB) — metric/rule/source/tenant are optional matchers.
- #table(name) {|source| ... } ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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
#alerts ⇒ Object (readonly)
Returns the value of attribute alerts.
12 13 14 |
# File 'lib/anomonitor/configuration.rb', line 12 def alerts @alerts end |
#authenticate ⇒ Object
Returns the value of attribute authenticate.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def authenticate @authenticate end |
#auto_start ⇒ Object
Returns the value of attribute auto_start.
12 13 14 |
# File 'lib/anomonitor/configuration.rb', line 12 def auto_start @auto_start end |
#collectors ⇒ Object (readonly)
Returns the value of attribute collectors.
12 13 14 |
# File 'lib/anomonitor/configuration.rb', line 12 def collectors @collectors end |
#cooldown ⇒ Object
Returns the value of attribute cooldown.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def cooldown @cooldown end |
#dashboard_base_url ⇒ Object
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_path ⇒ Object
Returns the value of attribute dashboard_path.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def dashboard_path @dashboard_path end |
#digest_interval ⇒ Object
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_at ⇒ Object
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_tenants ⇒ Object
Returns the value of attribute exclude_tenants.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def exclude_tenants @exclude_tenants end |
#notifier ⇒ Object
Returns the value of attribute notifier.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def notifier @notifier end |
#notifier_rate_limit ⇒ Object
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_interval ⇒ Object
Returns the value of attribute poll_interval.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def poll_interval @poll_interval end |
#poll_lock ⇒ Object
Returns the value of attribute poll_lock.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def poll_lock @poll_lock end |
#poll_mode ⇒ Object
Returns the value of attribute poll_mode.
12 13 14 |
# File 'lib/anomonitor/configuration.rb', line 12 def poll_mode @poll_mode end |
#retention_days ⇒ Object
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_exclude ⇒ Object
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_interval ⇒ Object
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 |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
12 13 14 |
# File 'lib/anomonitor/configuration.rb', line 12 def tables @tables end |
#tenant_switch ⇒ Object
Returns the value of attribute tenant_switch.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def tenant_switch @tenant_switch end |
#tenants ⇒ Object
Returns the value of attribute tenants.
5 6 7 |
# File 'lib/anomonitor/configuration.rb', line 5 def tenants @tenants end |
#webhook_url ⇒ Object
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, **) rule = AlertRule.new(metric, **) @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_notifier ⇒ Object
52 53 54 |
# File 'lib/anomonitor/configuration.rb', line 52 def build_notifier Notifiers.build(self) end |
#digest_enabled? ⇒ 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
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 |