Commit 6ccbf9c9 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

distribution gauge: calculate min, max, mean, etc

parent 7c288def
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -31,3 +31,25 @@ class Range
  end

end

class Array

  def mean
    inject(&:+).to_f / size
  end

  alias :average :mean

  def median
    42 # FIXPAUL!
  end

  def range
    42 # FIXPAUL!
  end

  def mode
    42 # FIXPAUL!
  end
  
end
 No newline at end of file
+21 −1
Original line number Diff line number Diff line
@@ -8,11 +8,31 @@ class FnordMetric::DistributionGauge < FnordMetric::Gauge
    #@num_max =

    @histogram = FnordMetric::Histogram.new
    @values = []

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

    tick_keys(interval, :histogram).each do |tkey|
      sync_redis.hgetall(tkey).each do |_val, _count|        
        @histogram[_val] += _count.to_i
        _count = _count.to_f

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

        if _count < @mmm_timeseries[tkey][:min]
          @mmm_timeseries[tkey][:min] = _count
        end

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

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

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

    render_page(:distribution_gauge)
+15 −13
Original line number Diff line number Diff line
@@ -14,28 +14,28 @@
  .headbar
    %h2 Histogram: #{@opts[:title]}

  .resizable.right(data-width="40" style="border-left:1px solid #ddd; height:500px;")
  .resizable.right.resize_min_full_height(data-width="40" style="border-left:1px solid #ddd;")
    .clearfix
      %h2(style="margin:20px 0 -3px 20px;") Value Distribution
      .numbers_container.resizable.numbers_pad_bottom(data-width="50")
        .number
          %span.desc Mean (Avg.)
          %span.value.ui_value{:"data-value" => @values.mean }
        .number
          %span.desc Minimum
          %span.value= @histogram.min
          %span.value.ui_value{:"data-value" => @values.min }
        .number
          %span.desc Maximum
          %span.value= @histogram.max
        .number
          %span.desc Mean (Average)
          %span.value= 0
          %span.value.ui_value{:"data-value" => @values.max }
        .number
          %span.desc Median
          %span.value= 0
          %span.value.ui_value{:"data-value" => @values.median }
        .number
          %span.desc Range
          %span.value= 0
          %span.value.ui_value{:"data-value" => @values.range }
        .number
          %span.desc Mode
          %span.value= 0
          %span.value.ui_value{:"data-value" => @values.mode }

    %hr

@@ -43,18 +43,20 @@
      %h2(style="margin:20px 0 -3px 20px;") Standard Deviation


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

  .resizable(data-width="60" style="margin-top:10px;")
    %div(style="margin-top:10px;")

      .headbar.small
      Average, Min and Max over Time
        Mean, Min and Max over Time



:gaugejs

  FnordMetric.ui.resizable('.report_view');
  FnordMetric.util.format('.report_view');

  FnordMetric.widgets.barsWidget().render({
    title: "Histogram: Number of #{key_nouns.last}",