Commit 08c6fd95 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

/:dashboard/gauge/:name?at=time-time&sum=true api

parent a6556c2d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -65,7 +65,8 @@ class FnordMetric::App < Sinatra::Base
      { (_t = gauge.tick_at(params[:at].to_i)) => gauge.value_at(_t) }
    elsif params[:at] && params[:at] =~ /^([0-9]+)-([0-9]+)$/
      _range = params[:at].split("-").map(&:to_i)
      gauge.values_in(_range.first.._range.last)
      _values = gauge.values_in(_range.first.._range.last)
      params[:sum] ? { :sum => _values.values.compact.map(&:to_i).sum } : _values
    else
      { (_t = gauge.tick_at(Time.now.to_i-gauge.tick)) => gauge.value_at(_t) }
    end    
+10 −4
Original line number Diff line number Diff line
@@ -442,10 +442,16 @@ describe "app" do
    end

    it "should return the right answer for: /metric/:name?at=timestamp-timstamp" do  
      get "/foospace/gauge/testgauge?at=1323691199-1323691201", :at => 18.hours.ago.to_i.to_s
      JSON.parse(last_response.body).keys.length.should == 2
      JSON.parse(last_response.body)["1323687600"] == 18
      JSON.parse(last_response.body)["1323691200"] == 23
      get "/foospace/gauge/testgauge?at=1323691199-1323701201"
      JSON.parse(last_response.body).keys.length.should == 4
      JSON.parse(last_response.body)["1323687600"].to_i.should == 18
      JSON.parse(last_response.body)["1323691200"].to_i.should == 23
    end

    it "should return the right answer for: /metric/:name?at=timestamp-timstamp&sum=true" do  
      get "/foospace/gauge/testgauge?at=1323691199-1323701201&sum=true"
      JSON.parse(last_response.body).keys.length.should == 1
      JSON.parse(last_response.body)["sum"].to_i.should == 18+23
    end

  end