Class: CloseYourIt::Stats
- Inherits:
-
Object
- Object
- CloseYourIt::Stats
- Defined in:
- lib/closeyourit/stats.rb
Overview
Contatori diagnostici thread-safe del client: quanti eventi sono stati accodati, scartati (coda piena), spediti con successo o falliti (rete o status non-2xx). Servono a rendere visibili i fallimenti silenziosi del trasporto fire-and-forget.
CloseYourIt.stats.to_h # => { enqueued: 12, dropped: 0, sent: 11, failed: 1 }
Constant Summary collapse
- COUNTERS =
%i[enqueued dropped sent failed].freeze
Instance Method Summary collapse
- #[](name) ⇒ Object
- #increment(name) ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #reset! ⇒ Object
- #to_h ⇒ Object
Constructor Details
Instance Method Details
#[](name) ⇒ Object
24 25 26 |
# File 'lib/closeyourit/stats.rb', line 24 def [](name) @counters.fetch(name).value end |
#increment(name) ⇒ Object
18 19 20 21 22 |
# File 'lib/closeyourit/stats.rb', line 18 def increment(name) counter = @counters.fetch(name) counter.increment counter.value end |
#reset! ⇒ Object
32 33 34 35 |
# File 'lib/closeyourit/stats.rb', line 32 def reset! @counters.each_value { |counter| counter.value = 0 } self end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/closeyourit/stats.rb', line 28 def to_h @counters.transform_values(&:value) end |