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.



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

#audObject

Returns the value of attribute aud.



3
4
5
# File 'lib/metrics.rb', line 3

def aud
  @aud
end

#labelsObject

Returns the value of attribute labels.



3
4
5
# File 'lib/metrics.rb', line 3

def labels
  @labels
end

#last_updatedObject

Returns the value of attribute last_updated.



3
4
5
# File 'lib/metrics.rb', line 3

def last_updated
  @last_updated
end

#nameObject

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

#resetObject



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

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

#valObject



27
28
29
30
31
# File 'lib/metrics.rb', line 27

def val
  @value_mtx.synchronize do
    @value
  end
end