Class: Mammoth::DispatchMetrics
- Inherits:
-
Object
- Object
- Mammoth::DispatchMetrics
- Defined in:
- lib/mammoth/dispatch_metrics.rb
Overview
Thread-safe in-process counters populated by Mammoth's CDC core observer.
The registry deliberately stores CDC core metric names and tags. Rendering those counters for a specific backend remains an observability concern.
Constant Summary collapse
- INSTANCE =
Process-wide dispatch metrics used by the default observer and snapshot.
new
Instance Method Summary collapse
-
#increment(name, tags = {}) ⇒ Integer
Increment a canonical CDC core metric.
-
#initialize ⇒ DispatchMetrics
constructor
Create an empty dispatch metric registry.
-
#reset! ⇒ self
Clear all counters.
-
#snapshot ⇒ Array<Hash>
Return an immutable point-in-time copy of all counters.
Constructor Details
#initialize ⇒ DispatchMetrics
Create an empty dispatch metric registry.
10 11 12 13 |
# File 'lib/mammoth/dispatch_metrics.rb', line 10 def initialize @mutex = Mutex.new @counters = Hash.new(0) end |
Instance Method Details
#increment(name, tags = {}) ⇒ Integer
Increment a canonical CDC core metric.
23 24 25 26 |
# File 'lib/mammoth/dispatch_metrics.rb', line 23 def increment(name, = {}) key = [name.to_s.freeze, ()] @mutex.synchronize { @counters[key] += 1 } end |
#reset! ⇒ self
Clear all counters.
Intended for process lifecycle management and isolated tests.
44 45 46 47 |
# File 'lib/mammoth/dispatch_metrics.rb', line 44 def reset! @mutex.synchronize { @counters.clear } self end |
#snapshot ⇒ Array<Hash>
Return an immutable point-in-time copy of all counters.
31 32 33 34 35 36 37 |
# File 'lib/mammoth/dispatch_metrics.rb', line 31 def snapshot @mutex.synchronize do @counters.map do |(name, ), value| { name: name, tags: .to_h, value: value } end end end |