Sha256: 9f765fa6ba5f418a230def20f36a52d7f7856aca35e0468323c34b8a856879c0

Contents?: true

Size: 1.33 KB

Versions: 24

Compression:

Stored size: 1.33 KB

Contents

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

class Cabin::Metrics::Histogram
  include Cabin::Metric

  # A new Histogram. 
  public
  def initialize
    @lock = Mutex.new
    @inspectables = [ :@total, :@min, :@max, :@count, :@mean ]

    # Histogram should track many things, including:
    # - percentiles (50, 75, 90, 95, 99?)
    # - median
    # - max
    # - min
    # - total sum
    #
    # Sliding values of all of these?
    @total = 0
    @min = nil
    @max = nil
    @count = 0
    @mean = 0.0
  end # def initialize

  public
  def record(value)
    @lock.synchronize do
      @count += 1
      @total += value
      if @min.nil? or value < @min
        @min = value
      end
      if @max.nil? or value > @max
        @max = value
      end
      @mean = @total / @count
      # TODO(sissel): median
      # TODO(sissel): percentiles
    end
    emit
  end # def record

  # This is a very poor way to access the metric data.
  # TODO(sissel): Need to figure out a better interface.
  public
  def value
    return @lock.synchronize { @count }
  end # def value

  public
  def to_hash
    return @lock.synchronize do
      { 
        :count => @count,
        :total => @total,
        :min => @min,
        :max => @max,
        :mean => @mean,
      }
    end
  end # def to_hash
end # class Cabin::Metrics::Histogram

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/histogram.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/cabin-0.8.1/lib/cabin/metrics/histogram.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/histogram.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/histogram.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/cabin-0.8.1/lib/cabin/metrics/histogram.rb
cabin-0.9.0 lib/cabin/metrics/histogram.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/histogram.rb
cabin-0.8.1 lib/cabin/metrics/histogram.rb
cabin-0.8.0 lib/cabin/metrics/histogram.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/histogram.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/histogram.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/cabin-0.7.2/lib/cabin/metrics/histogram.rb
logstash-codec-json-2.0.3 vendor/gems/cabin-0.7.2/lib/cabin/metrics/histogram.rb
cabin-0.7.2 lib/cabin/metrics/histogram.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/histogram.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/cabin-0.7.1/lib/cabin/metrics/histogram.rb
cabin-0.7.1 lib/cabin/metrics/histogram.rb
cabin-0.6.1 lib/cabin/metrics/histogram.rb
cabin-0.6.0 lib/cabin/metrics/histogram.rb
cabin-0.5.0 lib/cabin/metrics/histogram.rb