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
21
22
23
24
25
26
27
28
# 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|
        _gauge = namespace.gauges[gkey.to_sym]
        unless _gauge
          return { :error => "gauge not found: #{gkey}" }
        end

        t_since = FnordMetric::Util.parse_time(event["since"].to_s)
        t_until = FnordMetric::Util.parse_time(event["until"].to_s)

        vals = _gauge.values_in(t_since..t_until)
        { :key => gkey, :vals => vals, :title => _gauge.title }
      }
    }
  end

  return false unless resp

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

Instance Method Details

#dataObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 30

def data
  super.merge(
    :series => series,
    :gauges => gauges.map(&:name),
    :start_timestamp => ticks.first,
    :end_timestamp => ticks.last,
    :xticks => (@opts[:xticks] || 30),
    :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)


58
59
60
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 58

def has_tick?
  true
end

#seriesObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fnordmetric/widgets/timeseries_widget.rb', line 45

def series
  colors = FnordMetric::COLORS.dup

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