Class: RailsErrorDashboard::ErrorBaseline
- Inherits:
-
ErrorLogsRecord
- Object
- ActiveRecord::Base
- ErrorLogsRecord
- RailsErrorDashboard::ErrorBaseline
- Defined in:
- app/models/rails_error_dashboard/error_baseline.rb
Overview
Stores baseline statistics for error types
Baselines are calculated periodically (hourly, daily, weekly) to establish “normal” error behavior. This enables anomaly detection by comparing current error counts against historical baselines.
Constant Summary collapse
- BASELINE_TYPES =
%w[hourly daily weekly].freeze
Instance Attribute Summary collapse
-
#baseline_type ⇒ String
Time period type (hourly, daily, weekly).
-
#count ⇒ Integer
Total errors in this period.
-
#error_type ⇒ String
The type of error (e.g., “NoMethodError”).
-
#mean ⇒ Float
Average error count.
-
#percentile_95 ⇒ Float
95th percentile.
-
#percentile_99 ⇒ Float
99th percentile.
-
#period_end ⇒ DateTime
End of the period this baseline covers.
-
#period_start ⇒ DateTime
Start of the period this baseline covers.
-
#platform ⇒ String
Platform (iOS, Android, API, Web).
-
#sample_size ⇒ Integer
Number of periods in the sample.
-
#std_dev ⇒ Float
Standard deviation.
Instance Method Summary collapse
-
#anomaly_level(current_count, sensitivity: 2) ⇒ Symbol?
Check if a given count is anomalous compared to this baseline.
-
#exceeds_baseline?(current_count, sensitivity: 2) ⇒ Boolean
Check if current count is above baseline.
-
#std_devs_above_mean(current_count) ⇒ Float?
Calculate how many standard deviations above mean.
-
#threshold(sensitivity: 2) ⇒ Float?
Get the threshold for anomaly detection.
Instance Attribute Details
#baseline_type ⇒ String
Time period type (hourly, daily, weekly)
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def baseline_type @baseline_type end |
#count ⇒ Integer
Total errors in this period
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def count @count end |
#error_type ⇒ String
The type of error (e.g., “NoMethodError”)
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def error_type @error_type end |
#mean ⇒ Float
Average error count
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def mean @mean end |
#percentile_95 ⇒ Float
95th percentile
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def percentile_95 @percentile_95 end |
#percentile_99 ⇒ Float
99th percentile
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def percentile_99 @percentile_99 end |
#period_end ⇒ DateTime
End of the period this baseline covers
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def period_end @period_end end |
#period_start ⇒ DateTime
Start of the period this baseline covers
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def period_start @period_start end |
#platform ⇒ String
Platform (iOS, Android, API, Web)
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def platform @platform end |
#sample_size ⇒ Integer
Number of periods in the sample
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def sample_size @sample_size end |
#std_dev ⇒ Float
Standard deviation
21 22 23 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 21 def std_dev @std_dev end |
Instance Method Details
#anomaly_level(current_count, sensitivity: 2) ⇒ Symbol?
Check if a given count is anomalous compared to this baseline
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 47 def anomaly_level(current_count, sensitivity: 2) return nil if mean.nil? || std_dev.nil? return nil if current_count <= mean std_devs_above = (current_count - mean) / std_dev case std_devs_above when sensitivity..(sensitivity + 1) :elevated when (sensitivity + 1)..(sensitivity + 2) :high when (sensitivity + 2)..Float::INFINITY :critical else nil end end |
#exceeds_baseline?(current_count, sensitivity: 2) ⇒ Boolean
Check if current count is above baseline
69 70 71 72 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 69 def exceeds_baseline?(current_count, sensitivity: 2) return false if mean.nil? || std_dev.nil? current_count > (mean + (sensitivity * std_dev)) end |
#std_devs_above_mean(current_count) ⇒ Float?
Calculate how many standard deviations above mean
85 86 87 88 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 85 def std_devs_above_mean(current_count) return nil if mean.nil? || std_dev.nil? || std_dev.zero? (current_count - mean) / std_dev end |
#threshold(sensitivity: 2) ⇒ Float?
Get the threshold for anomaly detection
77 78 79 80 |
# File 'app/models/rails_error_dashboard/error_baseline.rb', line 77 def threshold(sensitivity: 2) return nil if mean.nil? || std_dev.nil? mean + (sensitivity * std_dev) end |