Class: Rubino::Metrics::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/metrics.rb

Overview

Monotonic counter keyed by label set. Thread-safe via internal mutex.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#helpObject (readonly)

Returns the value of attribute help.



22
23
24
# File 'lib/rubino/metrics.rb', line 22

def help
  @help
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/rubino/metrics.rb', line 22

def name
  @name
end

Instance Method Details

#eachObject



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

#typeObject



40
# File 'lib/rubino/metrics.rb', line 40

def type = :counter