Class: FnordMetric::ToplistGauge

Inherits:
Gauge
  • Object
show all
Defined in:
lib/fnordmetric/gauges/toplist_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



21
22
23
24
# File 'lib/fnordmetric/gauges/toplist_gauge.rb', line 21

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

def render(namespace, event)
  @interval = parse_interval(event["interval"])

  @toplist = FnordMetric::Toplist.new
  @all_ticks = ticks_in(@interval, tick, 1)

  @all_ticks.each do |_tick|
    field_values_at(_tick, :limit => top_k, :append => :toplist).each do |*args|
      item, count = args.flatten[0..1] # what the fnord... ~paul
      @toplist.incr_item(_tick, item, count)
    end
  end

  @toplist.total = @all_ticks.inject(0){ |s,t| s + sync_redis.get(tick_key(t, :total)).to_i }

  render_page(:toplist_gauge)
end

#renderable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fnordmetric/gauges/toplist_gauge.rb', line 26

def renderable?
  true
end