Commit 92f537ae authored by Paul Asmuth's avatar Paul Asmuth
Browse files

distribution gauge: render min, mean, max over time

parent 6ccbf9c9
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -11,30 +11,35 @@ class FnordMetric::DistributionGauge < FnordMetric::Gauge
    @values = []

    @mmm_timeseries = Hash.new do |h,k| 
      h[k] = { :min => (1.0/0), :max => 0, :avg => [] }
      h[k] = { :min => nil, :max => 0, :avg => [] }
    end

    tick_keys(interval, :histogram).each do |tkey|
    ticks_in(interval).each do |_tick|
      tkey = tick_key(_tick, :histogram)

      sync_redis.hgetall(tkey).each do |_val, _count|        
        _count = _count.to_f
        _val = _val.to_f

        @histogram[_val] += _count
        @values << _count
        @values << _val

        if _count < @mmm_timeseries[tkey][:min]
          @mmm_timeseries[tkey][:min] = _count
        if !@mmm_timeseries[_tick][:min] || (_val < @mmm_timeseries[_tick][:min])
          @mmm_timeseries[_tick][:min] = _val
        end

        if _count > @mmm_timeseries[tkey][:max]
          @mmm_timeseries[tkey][:max] = _count
        if _val > @mmm_timeseries[_tick][:max]
          @mmm_timeseries[_tick][:max] = _val
        end

        @mmm_timeseries[tkey][:avg] << _count
        @mmm_timeseries[_tick][:avg] << _val
      end

      @mmm_timeseries[tkey][:avg] = @mmm_timeseries[tkey][:avg].average
    end

    @mmm_timeseries_arr = @mmm_timeseries.to_a
      .map{ |k,v| [k, Hash[v.map{ |vk, vv| [vk, (vv.is_a?(Numeric) || vv.is_a?(Array)) ? vv : 0 ] }]] }
      .sort{ |a,b| a.first.to_i <=> b.first.to_i}

    render_page(:distribution_gauge)
  end

+41 −17
Original line number Diff line number Diff line
@@ -11,12 +11,21 @@
    / %li{"data-tab" => "Export"}
    /   %a{:href => "#"} Export


  .resizable.right.resize_min_full_height(data-width="40" style="border-left:1px solid #ddd;")
    .headbar
      %h2 Standard Deviation


  .resizable(data-width="60")
    .headbar
      %h2 Histogram: #{@opts[:title]}

  .resizable.right.resize_min_full_height(data-width="40" style="border-left:1px solid #ddd;")
    .widget_histogram_bars
    %br

    .clearfix
      %h2(style="margin:20px 0 -3px 20px;") Value Distribution
      .headbar.small Value Distribution
      .numbers_container.resizable.numbers_pad_bottom(data-width="50")
        .number
          %span.desc Mean (Avg.)
@@ -37,20 +46,10 @@
          %span.desc Mode
          %span.value.ui_value{:"data-value" => @values.mode }

    %hr

    .clearfix
      %h2(style="margin:20px 0 -3px 20px;") Standard Deviation


  .resizable(data-width="60")
    .widget_histogram_bars

    %div(style="margin-top:10px;")

      .headbar.small
        Mean, Min and Max over Time
    
    .headbar
      %h2 Mean, Min and Max over Time
    .widget_mmm_timeseries


:gaugejs
@@ -68,5 +67,30 @@
  });


  FnordMetric.widgets.timeseriesWidget().render({
    title: "#{key_nouns.last}",
    elem: $('.widget_mmm_timeseries'),
    height: 260,
    no_headbar: true,
    default_style: 'line',
    series_resolutions: #{@zooms.to_json},
    series: [      
      { 
        name: 'Max',
        color: "#{FnordMetric::COLORS[-2]}",
        data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:max]} }.to_json}
      },
      { 
        name: 'Min',
        color: "#{FnordMetric::COLORS[-3]}",
        data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:min]} }.to_json}
      },
      { 
        name: 'Mean',
        color: "#{FnordMetric::COLORS[-1]}",
        data: #{@mmm_timeseries_arr.map{|t,v| {:x=>t.to_i,:y=>v[:avg].average} }.to_json}
      }
    ]
  });

  
 No newline at end of file
+7 −3
Original line number Diff line number Diff line
@@ -130,9 +130,13 @@ FnordMetric.widgets.realtimeValueWidget = function(){
    }

    function drawLayout(){
      if(!opts.no_headbar){
        $(opts.elem).append( $('<div></div>').attr('class', 'headbar').append(
          $('<h2></h2>').html(opts.title)
      ) ).append(
        ));
      }
 
      $(opts.elem).append(
        $('<div></div>').attr('id', 'container-'+widget_uid).css({
          height: opts.height + 6,
          marginBottom: 20,
+5 −2
Original line number Diff line number Diff line
@@ -97,8 +97,8 @@ FnordMetric.widgets.timeseriesWidget = function(){
    }

    function draw_layout(){
      $(opts.elem)
        .append(
     if(!opts.no_headbar){
        $(opts.elem).append(
          $('<div></div>')
            .addClass('headbar')
            .append($('<h2></h2>').html(opts.title))
@@ -146,6 +146,9 @@ FnordMetric.widgets.timeseriesWidget = function(){
              )
            )
        )
      }

      $(opts.elem)
        .append(
          $('<div></div>')
            .addClass('legend')