Commit da6dc69e authored by Paul Asmuth's avatar Paul Asmuth
Browse files

histogram class

parent 985a9e4b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -156,6 +156,8 @@ require "fnordmetric/widget"
require "fnordmetric/widgets/timeseries_widget"
require "fnordmetric/widgets/numbers_widget"

require "fnordmetric/histogram"




+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@ class FnordMetric::Gauge
    key([(progressive? ? :progressive : tick_at(_time).to_s), _append])
  end

  def tick_keys(_range, _append=nil)
    ticks_in(_range).map{ |_t| tick_key(_t, _append) }
  end

  def two_dimensional?
    !@opts[:three_dimensional]
  end
+13 −1
Original line number Diff line number Diff line
@@ -4,6 +4,18 @@ class FnordMetric::DistributionGauge < FnordMetric::Gauge
    interval = parse_interval(event["interval"])
    colors = ["#2F635E", "#606B36", "#727070", "#936953", "#CD645A", "#FACE4F", "#42436B"]

    @opts[:histogram] = (@opts[:histogram] || 20).to_i
    #@num_min =
    #@num_max =

    @histogram = FnordMetric::Histogram.new

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

    render_page(:distribution_gauge)
  end

+45 −0
Original line number Diff line number Diff line
class FnordMetric::Histogram < Hash

  def initialize
    super{ |h,k| h[k]=0 }
  end

  def [](key)
  	super(key.to_f)
  end

  def []=(key, val)
  	super(key.to_f, val)
  end

  def min
  	keys.sort.first.to_i
  end

  def max
    keys.sort.last.to_i
  end

  def histogram(windows)
    Hash[histogram_windows(windows).map{ |w| [w,0] }].tap do |histo|
      self.each do |k,v|
        histo.detect do |win, wval|          
          histo[win] += v if win.include?(k)
        end
      end
    end
  end

private

  def histogram_windows(windows)
    window = (max - min) / windows

    (windows - 1).times.inject([min]) do |a,w| 
      a << a.last + window
    end.map do |swindow|
      (swindow..(swindow+window))
    end    
  end

end
 No newline at end of file
+2 −0
Original line number Diff line number Diff line

-> hashwithindifferentaccess

-> FnordMetric::Timeseries (min/max, values, punchcard, to_histogram etc)

-> timeseries-gauge/widget: set resolution via "tick buttons" 
-> timeseries-gauge: realtime tab w/ moving average
-> timeseries-widget: render with stroke=3 + points if xticks < 100
Loading