Commit 25c88af6 authored by Tadas Sce's avatar Tadas Sce
Browse files

Add option for precision in histogram labels

parent 2e7ec7d5
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5,12 +5,14 @@ class FnordMetric::DistributionGauge < FnordMetric::Gauge
    colors = ["#2F635E", "#606B36", "#727070", "#936953", "#CD645A", "#FACE4F", "#42436B"]

    @opts[:value_scale] ||= 1
    @opts[:precision]   ||= 1

    #@num_min =
    #@num_max =

    @histogram = FnordMetric::Histogram.new
    @values = []
    @histogram.set_opts(@opts)

    @samples = 0

+12 −5
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ class FnordMetric::Histogram < Hash
    super{ |h,k| h[k]=0 }
  end

  def set_opts(opts = {})
    @opts = opts
  end

  def [](key)
  	super(key.to_f)
  end
@@ -35,11 +39,14 @@ class FnordMetric::Histogram < Hash
    histogram(windows).to_a.sort do |a, b|
      a[0].first <=> b[0].first
    end.map do |r, v|
      [r.size == 1.0 ? r.last.to_s :
        "#{r.first.round(1).to_s}-#{r.last.round(1).to_s}", v.to_i]
      [r.size == 1.0 ? r.last.to_s : json_value(r), v.to_i]
    end.to_json
  end

  def json_value(r)
    "#{r.first.round(@opts[:precision]).to_s}-#{r.last.round(@opts[:precision]).to_s}"
  end

private

  def histogram_windows(windows)