Class: Atatus::Metrics::Metric Private
- Inherits:
-
Object
- Object
- Atatus::Metrics::Metric
- 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.
Instance Attribute Summary collapse
- #initial_value ⇒ Object readonly private
- #key ⇒ Object readonly private
- #tags ⇒ Object readonly private
- #value ⇒ Object private
Instance Method Summary collapse
- #collect ⇒ Object private
-
#initialize(key, initial_value: nil, tags: nil, reset_on_collect: false) ⇒ Metric
constructor
private
A new instance of Metric.
- #reset! ⇒ Object private
- #reset_on_collect? ⇒ Boolean private
- #tags? ⇒ Boolean private
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 = @reset_on_collect = reset_on_collect @mutex = Mutex.new end |
Instance Attribute Details
#initial_value ⇒ Object (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 |
#key ⇒ Object (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 |
#tags ⇒ Object (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 end |
#value ⇒ 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.
38 39 40 |
# File 'lib/atatus/metrics/metric.rb', line 38 def value @value end |
Instance Method Details
#collect ⇒ 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.
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.
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.
48 49 50 |
# File 'lib/atatus/metrics/metric.rb', line 48 def !!&.any? end |