class Spectator::Gauge

A meter with a single value that can only be sampled at a point in time. A typical example is a queue size.

Public Class Methods

new(id) click to toggle source

Initialize a new instance of a Gauge with the given id

# File lib/spectator/gauge.rb, line 11
def initialize(id)
  @id = id
  @value = AtomicNumber.new(Float::NAN)
end

Public Instance Methods

get() click to toggle source

Get the current value

# File lib/spectator/gauge.rb, line 17
def get
  @value.get
end
measure() click to toggle source

Get the current value, and reset it

# File lib/spectator/gauge.rb, line 27
def measure
  [Measure.new(@id.with_default_stat('gauge'),
               @value.get_and_set(Float::NAN))]
end
set(value) click to toggle source

Set the current value to the number specified

# File lib/spectator/gauge.rb, line 22
def set(value)
  @value.set(value)
end
to_s() click to toggle source

A string representation of this gauge, useful for debugging purposes

# File lib/spectator/gauge.rb, line 33
def to_s
  "Gauge{id=#{@id}, value=#{@value.get}}"
end