Commit 7990dab6 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

say hello to fraction gauges

parent 291716a1
Loading
Loading
Loading
Loading

doc/minimal_example.rb

0 → 100644
+26 −0
Original line number Diff line number Diff line
$: << ::File.expand_path("../../../fnordmetric/lib/", __FILE__)
require "fnordmetric"

FnordMetric.namespace :fn do

  timeseries_gauge :unicorns_seen,
    :tick => 4.seconds,
    :calculate => :average,
    :series => [:num_unicorns]


  event :unicorn_seen do
    incr :unicorns_seen, :num_unicorns, rand(5)
  end

end

Thread.new do 
  api = FnordMetric::API.new
  loop do
    api.event(:_type => :unicorn_seen)
    sleep rand(10)/10.to_f
  end
end

FnordMetric.standalone
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ module FnordMetric
  end

  def self.error(msg)
    log "[ERROR] #{msg}"
    log "[ERROR] #{msg}"; nil
  end

  def self.error!(msg)
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ protected
  end

  def error!(msg)
    FnordMetric.error!(msg)
    FnordMetric.error(msg)
  end


+16 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@ class FnordMetric::Gauge
    (@opts[:tick] || @opts[:resolution] || 3600).to_i
  end

  def retention
    tick * 10 # FIXPAUL!
  end

  def tick_at(time)    
    (time/tick.to_f).floor*tick
  end
@@ -46,6 +50,10 @@ class FnordMetric::Gauge
    ticks_in(_range).map{ |_t| tick_key(_t, _append) }
  end

  def retention_key(_time, _append=nil)
    key([((_time/retention.to_f).floor*retention).to_s, _append])
  end

  def two_dimensional?
    !@opts[:three_dimensional]
  end
@@ -66,6 +74,10 @@ class FnordMetric::Gauge
    !!@opts[:average]
  end

  def has_series?
    false
  end

  def redis
    @redis ||= EM::Hiredis.connect(FnordMetric.options[:redis_url]) # FIXPAUL
  end
@@ -74,4 +86,8 @@ class FnordMetric::Gauge
    @sync_redis ||= Redis.new # FIXPAUL
  end

  def error!(msg)
    FnordMetric.error(msg)
  end
  
end
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
@@ -48,10 +48,6 @@ module FnordMetric::GaugeCalculations
    end
  end

  # def values_in(range, opts={}, &block)
  #   values_at((tick_at(range.first)..range.last).step(tick))
  # end

  def calculate_value(_v, _t, opts, block)
    block = @@avg_per_count_proc if average?
    #block = @@count_per_session_proc if unique?
Loading