Sha256: 4424a4f12e6d267e99ff31898e693efd34e14a737d98cab303cea9dec7d4a185

Contents?: true

Size: 827 Bytes

Versions: 3

Compression:

Stored size: 827 Bytes

Contents

require 'spectator/atomic_number'
require 'spectator/measure'

module Spectator
  # A meter with a single value that can only be sampled at a point in time.
  # A typical example is a queue size.
  class Gauge
    # Initialize a new instance of a Gauge with the given id
    def initialize(id)
      @id = id
      @value = AtomicNumber.new(Float::NAN)
    end

    # Get the current value
    def get
      @value.get
    end

    # Set the current value to the number specified
    def set(value)
      @value.set(value)
    end

    # Get the current value, and reset it
    def measure
      [Measure.new(@id.with_stat('gauge'), @value.get_and_set(Float::NAN))]
    end

    # A string representation of this gauge, useful for debugging purposes
    def to_s
      "Gauge{id=#{@id}, value=#{@value.get}}"
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
netflix-spectator-rb-0.1.3 lib/spectator/gauge.rb
netflix-spectator-rb-0.1.1 lib/spectator/gauge.rb
spectator-rb-0.1.0 lib/spectator/gauge.rb