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.
5 6 7 8 9 10 11 12 |
# File 'lib/metrics.rb', line 5 def initialize(name, aud, labels = {}, value = 0.0) @name = name @aud = aud @labels = labels @value = 0 @last_updated = Time::now @value_mtx = Mutex.new end |
Instance Attribute Details
#aud ⇒ Object
Returns the value of attribute aud.
3 4 5 |
# File 'lib/metrics.rb', line 3 def aud @aud end |
#labels ⇒ Object
Returns the value of attribute labels.
3 4 5 |
# File 'lib/metrics.rb', line 3 def labels @labels end |
#last_updated ⇒ Object
Returns the value of attribute last_updated.
3 4 5 |
# File 'lib/metrics.rb', line 3 def last_updated @last_updated end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/metrics.rb', line 3 def name @name end |
Instance Method Details
#incr(val) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/metrics.rb', line 14 def incr(val) @value_mtx.synchronize do @value = @value + val @last_updated = Time::now end end |
#reset ⇒ Object
21 22 23 24 25 |
# File 'lib/metrics.rb', line 21 def reset @value_mtx.synchronize do @value = 0.0 end end |
#val ⇒ Object
27 28 29 30 31 |
# File 'lib/metrics.rb', line 27 def val @value_mtx.synchronize do @value end end |