Class: SolidObserver::Services::CacheStats::StabilityData::EventCounts
- Inherits:
-
Object
- Object
- SolidObserver::Services::CacheStats::StabilityData::EventCounts
- Defined in:
- lib/solid_observer/services/cache_stats.rb
Instance Attribute Summary collapse
-
#error_count ⇒ Object
readonly
Returns the value of attribute error_count.
-
#latest_recorded_at ⇒ Object
readonly
Returns the value of attribute latest_recorded_at.
-
#slow_count ⇒ Object
readonly
Returns the value of attribute slow_count.
Instance Method Summary collapse
-
#initialize ⇒ EventCounts
constructor
A new instance of EventCounts.
- #record(recorded_at:, error_class:, duration:) ⇒ Object
- #state ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ EventCounts
Returns a new instance of EventCounts.
126 127 128 129 130 |
# File 'lib/solid_observer/services/cache_stats.rb', line 126 def initialize @error_count = 0 @slow_count = 0 @latest_recorded_at = nil end |
Instance Attribute Details
#error_count ⇒ Object (readonly)
Returns the value of attribute error_count.
124 125 126 |
# File 'lib/solid_observer/services/cache_stats.rb', line 124 def error_count @error_count end |
#latest_recorded_at ⇒ Object (readonly)
Returns the value of attribute latest_recorded_at.
124 125 126 |
# File 'lib/solid_observer/services/cache_stats.rb', line 124 def latest_recorded_at @latest_recorded_at end |
#slow_count ⇒ Object (readonly)
Returns the value of attribute slow_count.
124 125 126 |
# File 'lib/solid_observer/services/cache_stats.rb', line 124 def slow_count @slow_count end |
Instance Method Details
#record(recorded_at:, error_class:, duration:) ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/solid_observer/services/cache_stats.rb', line 132 def record(recorded_at:, error_class:, duration:) kind = event_kind(error_class: error_class, duration: duration) return unless kind @latest_recorded_at = [latest_recorded_at, recorded_at].compact.max @error_count += 1 if kind == :error @slow_count += 1 if kind == :slow end |
#state ⇒ Object
141 142 143 144 145 146 |
# File 'lib/solid_observer/services/cache_stats.rb', line 141 def state return :critical if error_count.positive? return :degraded if slow_count.positive? :stable end |
#to_h ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/solid_observer/services/cache_stats.rb', line 148 def to_h { available: true, state: state, error_count: error_count, slow_count: slow_count, latest_recorded_at: latest_recorded_at } end |