Class: FnordMetric::NumbersWidget

Inherits:
Widget
  • Object
show all
Defined in:
lib/fnordmetric/widgets/numbers_widget.rb

Instance Attribute Summary

Attributes inherited from Widget

#gauges, #tick

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Widget

#add_gauges, #default_range, #ensure_has_tick!, #error!, #include_current?, #initialize, #range, #render, #ticks, #title, #token

Constructor Details

This class inherits a constructor from FnordMetric::Widget

Class Method Details

.execute(namespace, event) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/fnordmetric/widgets/numbers_widget.rb', line 3

def self.execute(namespace, event)
  resp = if event["cmd"] == "values_for"
    execute_values_for(namespace.gauges[event["gauge"].to_sym], event) 
  end

  return false unless resp

  resp.merge(
    :class => "widget_response",
    :widget_key => event["widget_key"]
  )
end

.execute_values_for(gauge, event) ⇒ Object



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
# File 'lib/fnordmetric/widgets/numbers_widget.rb', line 16

def self.execute_values_for(gauge, event)
  _t = Time.now.to_i

  values = {}.tap do |out|
    event["offsets"].each do |off|
      if off.to_s.starts_with?("s")
        offset = 0
        span = (gauge.tick * off.to_s[1..-1].to_i)
        values = gauge.values_in((_t-span).._t+gauge.tick)
        value = values.values.compact.map(&:to_i).sum
      else
        offset = off.to_i * gauge.tick
        span = gauge.tick
        value = gauge.value_at(_t-offset)
      end

      out["#{gauge.name}-#{offset}-#{span}"]  = { 
        :value => value,
        :desc  => "$formatOffset(#{offset}, #{span})"
      }
    end
  end

  { "cmd" => "values_for", 
    "series" => gauge.name, 
    "values" => values }
end

Instance Method Details

#dataObject



44
45
46
47
48
49
50
# File 'lib/fnordmetric/widgets/numbers_widget.rb', line 44

def data
  super.merge(
    :series => gauges.map(&:name),
    :offsets => (@opts[:offsets] || [0, 1, "s30"]),
    :autoupdate => (@opts[:autoupdate] || 60)
  )
end

#has_tick?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/fnordmetric/widgets/numbers_widget.rb', line 52

def has_tick?
  false
end