Class: Streamdal::Counter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#audObject

Returns the value of attribute aud.



5
6
7
# File 'lib/metrics.rb', line 5

def aud
  @aud
end

#labelsObject

Returns the value of attribute labels.



5
6
7
# File 'lib/metrics.rb', line 5

def labels
  @labels
end

#last_updatedObject

Returns the value of attribute last_updated.



5
6
7
# File 'lib/metrics.rb', line 5

def last_updated
  @last_updated
end

#nameObject

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

#resetObject



23
24
25
26
27
# File 'lib/metrics.rb', line 23

def reset
  @value_mtx.synchronize do
    @value = 0.0
  end
end

#valObject



29
30
31
32
33
# File 'lib/metrics.rb', line 29

def val
  @value_mtx.synchronize do
    @value
  end
end