Class: FnordMetric::TimeseriesWidget

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

Direct Known Subclasses

TimelineWidget

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
15
16
17
18
19
20
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 3

def self.execute(namespace, event)
  resp = if event["cmd"] == "values_at"
    {
      :cmd => :values_at,
      :gauges => event["gauges"].map{ |gkey|
        vals = namespace.gauges[gkey.to_sym].values_in(event["since"]..event["until"])
        { :key => gkey, :vals => vals }
      }
    }
  end

  return false unless resp

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

Instance Method Details

#dataObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 22

def data    
  super.merge(
    :series => series,
    :gauges => gauges.map(&:name),
    :start_timestamp => ticks.first,
    :end_timestamp => ticks.last,
    :autoupdate => (@opts[:autoupdate] || 60),
    :include_current => !!@opts[:include_current],
    :default_style => (@opts[:plot_style] || 'line'),
    :async_chart => true,
    :tick => tick
  )
end

#has_tick?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 48

def has_tick?
  true
end

#seriesObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 36

def series
  colors = FnordMetric::COLORS.dup
  
  gauges.map do |gauge|
    { 
      :name => gauge.name, 
      :data => [{:x => ticks.first, :y => 0}], 
      :color => colors.unshift(colors.pop).first 
    }
  end
end