Sha256: 459e155b6614c40028c428ecd1538bbab0b38ef461f37c61299714479a9b7b93

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

class FnordMetric::Gauge
  
  include FnordMetric::GaugeCalculations

  def initialize(opts)
    opts.fetch(:key) && opts.fetch(:key_prefix)
    @opts = opts
  end

  def tick
    (@opts[:tick] || 3600).to_i
  end

  def tick_at(time)    
    (time/tick.to_f).floor*tick
  end

  def name
    @opts[:key]
  end

  def title
    @opts[:title] || name
  end
  
  def key(_append=nil)
    [@opts[:key_prefix], "gauge", name, tick, _append].flatten.compact.join("-")
  end

  def tick_key(_time, _append=nil)
    key([(progressive? ? :progressive : tick_at(_time).to_s), _append])
  end

  def two_dimensional?
    !@opts[:three_dimensional]
  end

  def three_dimensional?
    !!@opts[:three_dimensional]
  end

  def progressive?
    !!@opts[:progressive]
  end

  def unique?
    !!@opts[:unique]
  end

  def average?
    !!@opts[:average]
  end

  def add_redis(_redis)
    @opts[:redis] = _redis
  end

  def ticks_in(r)
    (((r.last-r.first)/tick.to_f).ceil+1).times.map{ |n| tick_at(r.first + tick*(n-1)) }
  end

  def values_in(range)
    values_at(ticks_in(range))
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fnordmetric-0.7.5 lib/fnordmetric/gauge.rb
fnordmetric-0.7.4 lib/fnordmetric/gauge.rb
fnordmetric-0.7.3 lib/fnordmetric/gauge.rb
fnordmetric-0.7.1 lib/fnordmetric/gauge.rb
fnordmetric-0.7.0 lib/fnordmetric/gauge.rb
fnordmetric-0.6.6 lib/fnordmetric/gauge.rb
fnordmetric-0.6.5 lib/fnordmetric/gauge.rb
fnordmetric-0.6.4 lib/fnordmetric/gauge.rb
fnordmetric-0.6.3 lib/fnordmetric/gauge.rb
fnordmetric-0.6.2 lib/fnordmetric/gauge.rb
fnordmetric-0.6.1 lib/fnordmetric/gauge.rb
fnordmetric-0.6.0 lib/fnordmetric/gauge.rb
fnordmetric-0.5.9 lib/fnordmetric/gauge.rb
fnordmetric-0.5.8 lib/fnordmetric/gauge.rb
fnordmetric-0.5.7 lib/fnordmetric/gauge.rb
fnordmetric-0.5.6 lib/fnordmetric/gauge.rb
fnordmetric-0.5.5 lib/fnordmetric/gauge.rb
fnordmetric-0.5.4 lib/fnordmetric/gauge.rb
fnordmetric-0.5.3 lib/fnordmetric/gauge.rb
fnordmetric-0.5.2 lib/fnordmetric/gauge.rb