Class: FnordMetric::DistributionGauge

Inherits:
Gauge
  • Object
show all
Defined in:
lib/fnordmetric/gauges/distribution_gauge.rb

Instance Method Summary collapse

Methods inherited from Gauge

#average?, #error!, #group, #has_series?, #initialize, #key, #key_nouns, #name, #progressive?, #redis, #retention, #retention_key, #sync_redis, #three_dimensional?, #tick, #tick_at, #tick_key, #tick_keys, #title, #two_dimensional?, #unique?, #unit

Methods included from GaugeRendering

#render_to_event

Methods included from GaugeValidations

#validate_series!

Methods included from GaugeModifiers

#assure_has_series!, #assure_non_progressive!, #assure_series_exists!, #assure_three_dimensional!, #assure_two_dimensional!, #incr, #incr_avg, #incr_denominator, #incr_field, #incr_field_by, #incr_fraction, #incr_numerator, #incr_tick, #incr_uniq, #parse_numeric, #set_field, #set_value

Methods included from GaugeCalculations

#calculate_value, #field_values_at, #field_values_total, #fraction_values_in, #ticks_in, #value_at, #values_at, #values_in

Constructor Details

This class inherits a constructor from FnordMetric::Gauge

Instance Method Details

#execute(cmd, context, *args) ⇒ Object



60
61
62
63
# File 'lib/fnordmetric/gauges/distribution_gauge.rb', line 60

def execute(cmd, context, *args)
  return observe(context, args.first) if cmd == :observe
  FnordMetric.error("gauge '#{name}': unknown command: #{cmd}")
end

#render(namespace, event) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fnordmetric/gauges/distribution_gauge.rb', line 3

def render(namespace, event)
  @interval = parse_interval(event["interval"])
  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

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

  ticks_in(@interval, tick, 1).each do |_tick|
    tkey = tick_key(_tick, :histogram)

    sync_redis.hgetall(tkey).each do |_val, _count|
      _count = _count.to_f
      _val = _val.to_f * @opts[:value_scale]

      @samples += _count

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

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

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

      @mmm_timeseries[_tick][:avg] += [_val] * _count
    end
  end

  if @opts[:value_ranges]
    @histogram_mode = @opts[:value_ranges]
  else
    @histogram_mode = [23, @histogram.max || 1].min
  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

#renderable?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fnordmetric/gauges/distribution_gauge.rb', line 65

def renderable?
  true
end