Class: Tracekit::Metrics::Counter
- Inherits:
-
Object
- Object
- Tracekit::Metrics::Counter
- Defined in:
- lib/tracekit/metrics/counter.rb
Overview
Counter metric - monotonically increasing value Used for tracking totals like request counts, error counts, etc.
Instance Method Summary collapse
-
#add(value) ⇒ Object
Adds a value to the counter.
-
#inc ⇒ Object
Increments the counter by 1.
-
#initialize(name, tags, registry) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(name, tags, registry) ⇒ Counter
Returns a new instance of Counter.
8 9 10 11 12 13 14 |
# File 'lib/tracekit/metrics/counter.rb', line 8 def initialize(name, , registry) @name = name @tags = || {} @registry = registry @value = 0.0 @mutex = Mutex.new end |
Instance Method Details
#add(value) ⇒ Object
Adds a value to the counter
23 24 25 26 27 28 29 30 |
# File 'lib/tracekit/metrics/counter.rb', line 23 def add(value) raise ArgumentError, "Counter values must be non-negative" if value < 0 @mutex.synchronize do @value += value @registry.record_metric(@name, "counter", @value, @tags) end end |
#inc ⇒ Object
Increments the counter by 1
17 18 19 |
# File 'lib/tracekit/metrics/counter.rb', line 17 def inc add(1.0) end |