Class: Streamdal::Counter
- Inherits:
-
Object
- Object
- Streamdal::Counter
- Defined in:
- lib/metrics.rb
Instance Attribute Summary collapse
-
#aud ⇒ Object
Returns the value of attribute aud.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#last_updated ⇒ Object
Returns the value of attribute last_updated.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #incr(val) ⇒ Object
-
#initialize(name, aud, labels = {}, value = 0.0) ⇒ Counter
constructor
A new instance of Counter.
- #reset ⇒ Object
- #val ⇒ Object
Constructor Details
#initialize(name, aud, labels = {}, value = 0.0) ⇒ Counter
Returns a new instance of Counter.
7 8 9 10 11 12 13 14 |
# File 'lib/metrics.rb', line 7 def initialize(name, aud, labels = {}, value = 0.0) @name = name @aud = aud @labels = labels @value = value @last_updated = Time.now @value_mtx = Mutex.new end |
Instance Attribute Details
#aud ⇒ Object
Returns the value of attribute aud.
5 6 7 |
# File 'lib/metrics.rb', line 5 def aud @aud end |
#labels ⇒ Object
Returns the value of attribute labels.
5 6 7 |
# File 'lib/metrics.rb', line 5 def labels @labels end |
#last_updated ⇒ Object
Returns the value of attribute last_updated.
5 6 7 |
# File 'lib/metrics.rb', line 5 def last_updated @last_updated end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/metrics.rb', line 5 def name @name end |
Instance Method Details
#incr(val) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/metrics.rb', line 16 def incr(val) @value_mtx.synchronize do @value += val @last_updated = Time.now end end |
#reset ⇒ Object
23 24 25 26 27 |
# File 'lib/metrics.rb', line 23 def reset @value_mtx.synchronize do @value = 0.0 end end |
#val ⇒ Object
29 30 31 32 33 |
# File 'lib/metrics.rb', line 29 def val @value_mtx.synchronize do @value end end |