Sha256: d680b60bf136b85c0246414dee72c222fcdf8455314c0b54395b5086afc967ca

Contents?: true

Size: 801 Bytes

Versions: 24

Compression:

Stored size: 801 Bytes

Contents

require "cabin/namespace"
require "cabin/metric"
require "thread"

class Cabin::Metrics::Counter
  include Cabin::Metric

  # A new Counter. 
  #
  # Counters can be incremented and decremented only by 1 at a time..
  public
  def initialize
    @inspectables = [ :@value ]
    @value = 0
    @lock = Mutex.new
  end # def initialize

  # increment this counter
  def incr
    @lock.synchronize { @value += 1 }
    emit
  end # def incr

  # decrement this counter
  def decr
    @lock.synchronize { @value -= 1 }
    emit
  end # def decr

  # Get the value of this metric.
  public
  def value
    return @lock.synchronize { @value }
  end # def value

  public
  def to_hash
    return @lock.synchronize do
      { :value => @value }
    end
  end # def to_hash
end # class Cabin::Metrics::Counter

Version data entries

24 entries across 22 versions & 6 rubygems

Version Path
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/cabin-0.8.1/lib/cabin/metrics/counter.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/cabin-0.8.1/lib/cabin/metrics/counter.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/counter.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/counter.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/counter.rb
cabin-0.9.0 lib/cabin/metrics/counter.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/counter.rb
cabin-0.8.1 lib/cabin/metrics/counter.rb
cabin-0.8.0 lib/cabin/metrics/counter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/cabin-0.7.2/lib/cabin/metrics/counter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/counter.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.2/lib/cabin/metrics/counter.rb
logstash-codec-json-2.0.3 vendor/gems/cabin-0.7.2/lib/cabin/metrics/counter.rb
cabin-0.7.2 lib/cabin/metrics/counter.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/counter.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/counter.rb
cabin-0.7.1 lib/cabin/metrics/counter.rb
cabin-0.6.1 lib/cabin/metrics/counter.rb
cabin-0.6.0 lib/cabin/metrics/counter.rb
cabin-0.5.0 lib/cabin/metrics/counter.rb