Class: FnordMetric::ToplistWidget
- Inherits:
-
Widget
- Object
- Widget
- FnordMetric::ToplistWidget
show all
- Defined in:
- lib/fnordmetric/widgets/toplist_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
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
|
# File 'lib/fnordmetric/widgets/toplist_widget.rb', line 3
def self.execute(namespace, event)
t = Time.now.to_i
return false unless event["gauge"]
resp = if event["cmd"] == "values_for"
{
:cmd => :values_for,
:gauge => event["gauge"],
:values => execute_values_for(namespace.gauges[event["gauge"].to_sym], t),
:count => namespace.gauges[event["gauge"].to_sym].field_values_total(t)
}
end
return false unless resp
resp.merge(
:class => "widget_response",
:widget_key => event["widget_key"]
)
end
|
.execute_values_for(gauge, time) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/fnordmetric/widgets/toplist_widget.rb', line 25
def self.execute_values_for(gauge, time)
gauge.field_values_at(time).sort do |a,b|
a.first.to_i <=> b.first.to_i
end.map do |a|
[a.first, a.second.to_i]
end
end
|
Instance Method Details
#data ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/fnordmetric/widgets/toplist_widget.rb', line 33
def data
super.merge(
:gauges => data_gauges,
:autoupdate => (@opts[:autoupdate] || 0),
:render_target => @opts[:render_target],
:ticks => @opts[:ticks],
:click_callback => @opts[:click_callback],
:async_chart => true,
:tick => tick
).tap do |dat|
dat.merge!(
:gauges => @opts[:_gauges]
) if dat[:ticks]
end
end
|
#data_gauges ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/fnordmetric/widgets/toplist_widget.rb', line 49
def data_gauges
Hash.new.tap do |hash|
gauges.each do |g|
hash[g.name] = {
:tick => g.tick,
:title => g.title
}
end
end
end
|
#has_tick? ⇒ Boolean
60
61
62
|
# File 'lib/fnordmetric/widgets/toplist_widget.rb', line 60
def has_tick?
false
end
|