Commit 17cbf2ee authored by Paul Asmuth's avatar Paul Asmuth
Browse files

core: imeplemented zero-config _avg and _set gauges

parent f73afea5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -71,6 +71,10 @@ private
    @event[:_time].to_i
  end

  def type
    @event[:_type].to_sym
  end

protected

  def fetch_gauge(_gauge)
+21 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ FnordMetric::TICKS = lambda{ |tick, span| [tick, 60, 300, 1200, 3600, 86400]

FnordMetric::DEFAULT_PROC = lambda{ |arg| }

FnordMetric::ZERO_CONFIG_TYPES = [:_incr, :_decr, :_avg, :_min, :_max]
FnordMetric::ZERO_CONFIG_TYPES = [:_incr, :_decr, :_avg, :_min, :_max, :_set]

FnordMetric::ZERO_CONFIG_HANDLER = proc {
  if data[:gauge]
@@ -30,8 +30,26 @@ FnordMetric::ZERO_CONFIG_HANDLER = proc {
    namespace.gauges[gauge_key]
  else
    namespace.opt_gauge(gauge_key,
      :tick => data[:flush_interval].to_i)
      :tick => data[:flush_interval].to_i,
      :average => (type == :_avg))
  end

  case type

    when :_set
      set_value gauge, data[:value]

    when :_incr
      incr_tick gauge, data[:value]

    when :_decr
      FnordMetric.error("_decr is not yet implemented")

    when :_avg
      incr_avg gauge, data[:value]

    when :_min, :_max
      FnordMetric.error("_min/_max is not yet implemented")

  end
}
+2 −2
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ class FnordMetric::Namespace

    @handlers = Hash.new.with_indifferent_access

    ZERO_CONFIG_TYPES.each do |type|
      opt_event(type, &ZERO_CONFIG_HANDLER)
    FnordMetric::ZERO_CONFIG_TYPES.each do |type|
      opt_event(type, &FnordMetric::ZERO_CONFIG_HANDLER)
    end
  end

+59 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ describe FnordMetric::GaugeModifiers do
      @namespace.ready!(@redis_wrap)
    end

    it "should create and increment a zero-config gauge by 1" do
    it "should create and increment zero-config gauges" do
      @namespace.announce(
        :_type => "_incr",
        :_eid  => 1234,
@@ -46,6 +46,64 @@ describe FnordMetric::GaugeModifiers do
      )

      @redis.hget(gauge_key, "1360584960").should == "53"
      @namespace.gauges[:"sales-per-second"].value_at(1360584961).should == "53"
    end

    it "should create and set zero-config gauges" do
      @namespace.announce(
        :_type => "_set",
        :_eid  => 1234,
        :_time => 1360584960,
        :value => 123,
        :gauge => "sales-per-second-set",
        :flush_interval => 10
      )

      @namespace.gauges[:"sales-per-second-set"].should be_a(Gauge)

      gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-set-10"
      @redis.hget(gauge_key, "1360584960").should == "123"

      @namespace.announce(
        :_type => "_set",
        :_eid  => 1234,
        :_time => 1360584960,
        :value => 555,
        :gauge => "sales-per-second-set",
        :flush_interval => 10
      )

      @redis.hget(gauge_key, "1360584960").should == "555"
      @namespace.gauges[:"sales-per-second-set"].value_at(1360584961).should == "555"
    end

    it "should create and increment-average zero-config gauges" do
      @namespace.announce(
        :_type => "_avg",
        :_eid  => 1234,
        :_time => 1360584960,
        :value => 5,
        :gauge => "sales-per-second-avg",
        :flush_interval => 10
      )

      @namespace.gauges[:"sales-per-second-avg"].should be_a(Gauge)
      @namespace.gauges[:"sales-per-second-avg"].average?.should be_true

      gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-avg-10"
      @redis.hget(gauge_key, "1360584960").should == "5"

      @namespace.announce(
        :_type => "_avg",
        :_eid  => 1234,
        :_time => 1360584960,
        :value => 10,
        :gauge => "sales-per-second-avg",
        :flush_interval => 10
      )

      @redis.hget(gauge_key, "1360584960").should == "15"
      @namespace.gauges[:"sales-per-second-avg"].value_at(1360584961).should == 7.5
    end

  end
+4 −15
Original line number Diff line number Diff line
@@ -62,31 +62,20 @@ describe FnordMetric::Namespace do
  describe "registering event handlers" do

    it "should register an event handler" do
      @namespace.handlers.length.should == 0
      @namespace.handlers.length.should == ZERO_CONFIG_TYPES.size
      @namespace.event(:foobar){}
      @namespace.event(:fnordbar){}
      @namespace.handlers["foobar"].length.should == 1
      @namespace.handlers["fnordbar"].length.should == 1
      @namespace.handlers.length.should == 2
      @namespace.handlers.length.should == ZERO_CONFIG_TYPES.size + 2
    end

    it "should register an event handler and create a context"
    it "should register an event handler and pass options"
    it "should register an event handler and pass gauges"

    it "should announce an event to the correct handler" do
      pending("finish this")
    # block_called = false
    # FnordMetric::Dashboard.new(:title => 'My Dashboard') do |dash|
    #    block_called = true
    #    dash.should be_a(FnordMetric::Dashboard)
    #  end
    #  block_called.should be_true
    end

    it "should announce an event to the correct handler"
    it "should announce an event to multiple handlers"
    it "should announce an event to the wildcard handler"

  end

  it "should create a new session on announce if _session is set" do
+1 −1

File changed.

Contains only whitespace changes.

+2 −2

File changed.

Contains only whitespace changes.

Loading