Class: FnordMetric::TimeseriesGauge

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

Instance Method Summary collapse

Methods inherited from Gauge

#average?, #error!, #group, #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_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

#initialize(opts) ⇒ TimeseriesGauge

Returns a new instance of TimeseriesGauge.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fnordmetric/gauges/timeseries_gauge.rb', line 3

def initialize(opts)
  super(opts)
  
  @opts[:series] = @opts[:series].map(&:to_sym)

  if @opts[:calculate]
    unless [:sum, :average, :progressive_sum].include?(@opts[:calculate].to_sym)
      raise "unknown calculate option: #{@opts[:calculate]}"
    end
    @calculate = @opts[:calculate].to_sym
  end 

  @calculate ||= :sum
  @calculate_proc = lambda{ |c,d| d > 0 ? (c/d.to_f).round(2) : c }
end

Instance Method Details

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



46
47
48
49
50
51
52
# File 'lib/fnordmetric/gauges/timeseries_gauge.rb', line 46

def execute(cmd, context, *args)
  return incr(context, *args) if cmd == :incr
  return incr_numerator(context, *args) if cmd == :incr_numerator
  return incr_denominator(context, *args) if cmd == :incr_denominator

  FnordMetric.error("gauge '#{name}': unknown command: #{cmd}")
end

#has_series?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fnordmetric/gauges/timeseries_gauge.rb', line 58

def has_series?
  true
end

#render(namespace, event) ⇒ Object



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
# File 'lib/fnordmetric/gauges/timeseries_gauge.rb', line 19

def render(namespace, event)
  @interval = parse_interval(event["interval"])
  colors = FnordMetric::COLORS.dup

  @series = Hash.new
  @zooms  = FnordMetric::TICKS[tick, @interval.size]

  @total = 0

  @opts[:series].each do |series|
    ts = FnordMetric::Timeseries.new

    fraction_values_in(@interval, series).each do |time, frac|
      @total += frac.first # FIXPAUL
      ts.incr_fraction(time, *frac)
    end

    @series[series] = { 
      :color => colors.unshift(colors.pop).first,
      :data => Hash[@zooms.map{ |int| [int, ts.timeseries(@interval, int) ] }],
      :timeseries => ts
    }
  end

  render_page(:timeseries_gauge)
end

#renderable?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fnordmetric/gauges/timeseries_gauge.rb', line 54

def renderable?
  true
end