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 / before_send / sampling), spediti con successo, falliti (rete o status
non-2xx) e, tra i falliti, quanti per timeout di rete. Rendono visibili i fallimenti silenziosi
del trasporto fire-and-forget. timeout è un sotto-conteggio di failed (un timeout resta un
fallimento d'invio): li teniamo distinti per isolare i problemi di connettività dai non-2xx.
CloseYourIt.stats.to_h # => { enqueued: 12, dropped: 0, sent: 11, failed: 1, timeout: 1 }
Constant Summary collapse
- COUNTERS =
%i[enqueued dropped sent failed timeout].freeze
Instance Method Summary collapse
- #[](name) ⇒ Object
- #increment(name) ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #reset! ⇒ Object
- #to_h ⇒ Object (also: #snapshot)
Constructor Details
Instance Method Details
#[](name) ⇒ Object
26 27 28 |
# File 'lib/closeyourit/stats.rb', line 26 def [](name) @counters.fetch(name).value end |
#increment(name) ⇒ Object
20 21 22 23 24 |
# File 'lib/closeyourit/stats.rb', line 20 def increment(name) counter = @counters.fetch(name) counter.increment counter.value end |
#reset! ⇒ Object
39 40 41 42 |
# File 'lib/closeyourit/stats.rb', line 39 def reset! @counters.each_value { |counter| counter.value = 0 } self end |
#to_h ⇒ Object Also known as: snapshot
30 31 32 |
# File 'lib/closeyourit/stats.rb', line 30 def to_h @counters.transform_values(&:value) end |