Module: Wurk::Metrics::ProcessCounters
- Defined in:
- lib/wurk/metrics/process_counters.rb
Overview
In-memory counters for events with no Redis key of their own, exposed by Metrics::Prometheus. Per process: under a swarm, a scrape sees only the child that owns the health port.
A labelled series is keyed [name, label] and read back with #labelled.
#set stores a gauge under the same table.
Class Method Summary collapse
- .increment(name, by = 1) ⇒ Object
-
.labelled(name) ⇒ Object
{ label => value }for every[name, label]key. - .reset! ⇒ Object
- .set(name, value) ⇒ Object
- .value(name) ⇒ Object
Class Method Details
.increment(name, by = 1) ⇒ Object
16 17 18 |
# File 'lib/wurk/metrics/process_counters.rb', line 16 def increment(name, by = 1) @lock.synchronize { @counts[name] += by } end |
.labelled(name) ⇒ Object
{ label => value } for every [name, label] key.
29 30 31 32 33 34 35 |
# File 'lib/wurk/metrics/process_counters.rb', line 29 def labelled(name) @lock.synchronize do @counts.each_with_object({}) do |(key, value), out| out[key[1]] = value if key.is_a?(::Array) && key[0] == name end end end |
.reset! ⇒ Object
37 38 39 |
# File 'lib/wurk/metrics/process_counters.rb', line 37 def reset! @lock.synchronize { @counts.clear } end |
.set(name, value) ⇒ Object
20 21 22 |
# File 'lib/wurk/metrics/process_counters.rb', line 20 def set(name, value) @lock.synchronize { @counts[name] = value } end |
.value(name) ⇒ Object
24 25 26 |
# File 'lib/wurk/metrics/process_counters.rb', line 24 def value(name) @lock.synchronize { @counts[name] } end |