Class: Atatus::Metrics::Metric Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

Counter, Gauge, Timer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, initial_value: nil, tags: nil, reset_on_collect: false) ⇒ Metric

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Metric.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/atatus/metrics/metric.rb', line 24

def initialize(
  key,
  initial_value: nil,
  tags: nil,
  reset_on_collect: false
)
  @key = key
  @initial_value = initial_value
  @value = initial_value
  @tags = tags
  @reset_on_collect = reset_on_collect
  @mutex = Mutex.new
end

Instance Attribute Details

#initial_valueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/atatus/metrics/metric.rb', line 38

def initial_value
  @initial_value
end

#keyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/atatus/metrics/metric.rb', line 38

def key
  @key
end

#tagsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/atatus/metrics/metric.rb', line 38

def tags
  @tags
end

#valueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/atatus/metrics/metric.rb', line 38

def value
  @value
end

Instance Method Details

#collectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/atatus/metrics/metric.rb', line 56

def collect
  @mutex.synchronize do
    collected = @value

    return nil if collected.is_a?(Float) && !collected.finite?

    @value = initial_value if reset_on_collect?

    return nil if reset_on_collect? && collected == 0

    collected
  end
end

#reset!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/atatus/metrics/metric.rb', line 44

def reset!
  self.value = initial_value
end

#reset_on_collect?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


52
53
54
# File 'lib/atatus/metrics/metric.rb', line 52

def reset_on_collect?
  @reset_on_collect
end

#tags?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


48
49
50
# File 'lib/atatus/metrics/metric.rb', line 48

def tags?
  !!tags&.any?
end