class ElasticAPM::Metrics::Metric
@api private
def collect
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
def initialize(
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
def reset!
def reset! self.value = initial_value end
def reset_on_collect?
def reset_on_collect? @reset_on_collect end
def tags?
def tags? !!tags&.any? end
def value=(value)
def value=(value) @mutex.synchronize { @value = value } end