Class: Rubino::Metrics::Counter
- Inherits:
-
Object
- Object
- Rubino::Metrics::Counter
- Defined in:
- lib/rubino/metrics.rb
Overview
Monotonic counter keyed by label set. Thread-safe via internal mutex.
Instance Attribute Summary collapse
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #each ⇒ Object
-
#increment(by: 1, **labels) ⇒ Object
Add ‘by` to the counter for the given label set (default 1).
-
#initialize(name, help) ⇒ Counter
constructor
A new instance of Counter.
- #type ⇒ Object
Constructor Details
#initialize(name, help) ⇒ Counter
Returns a new instance of Counter.
24 25 26 27 28 29 |
# File 'lib/rubino/metrics.rb', line 24 def initialize(name, help) @name = name @help = help @values = Hash.new(0) @mutex = Mutex.new end |
Instance Attribute Details
#help ⇒ Object (readonly)
Returns the value of attribute help.
22 23 24 |
# File 'lib/rubino/metrics.rb', line 22 def help @help end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/rubino/metrics.rb', line 22 def name @name end |
Instance Method Details
#each ⇒ Object
36 37 38 |
# File 'lib/rubino/metrics.rb', line 36 def each(&) @mutex.synchronize { @values.dup }.each(&) end |
#increment(by: 1, **labels) ⇒ Object
Add ‘by` to the counter for the given label set (default 1).
32 33 34 |
# File 'lib/rubino/metrics.rb', line 32 def increment(by: 1, **labels) @mutex.synchronize { @values[labels] += by } end |
#type ⇒ Object
40 |
# File 'lib/rubino/metrics.rb', line 40 def type = :counter |