Class: Xen

Inherits:
Object
  • Object
show all
Includes:
Graphs::AreaNotStackedChart, Mongoid::Attributes::Dynamic, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/app/models/xen.rb

Class Method Summary collapse

Class Method Details

.axes_defaultsObject



96
97
98
# File 'lib/app/models/xen.rb', line 96

def self.axes_defaults
  []
end

.chart_data(options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/app/models/xen.rb', line 10

def self.chart_data(options = {})
  charts = []

  charts << self.memory_chart(options)
end

.graphs_defaultsObject



92
93
94
# File 'lib/app/models/xen.rb', line 92

def self.graphs_defaults
 []
end

.memory_chart(options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/app/models/xen.rb', line 57

def self.memory_chart(options)
  memory = {
             :value_axes => [
                 { 
	    :name => "valueAxis1",
	    :title => 'Memory in KB',
	    :position => 'left',
	    :stack_type => 'regular',
	    :grid_alpha => 0.07,
	    :min_max_multiplier => 1,
                          :include_guides_in_min_max => 'true'
	  }
	],
      :category_field => 'timestamp',
             :graph_data => [],
      :graphs => [],
      :title => "XEN memory usage",
      :title_size => 20
    }
  graphs = []
  all_stats = Xen.where( {:timestamp => { :$gte => options[:start],:$lt => options[:end]}, :host_id => options[:host_id], :plugin_id => options[:plugin_id] }).order(:timestamp).group_by{|u| u.domain}
  tmp = {}
  Xen.where( {:timestamp => { :$gte => options[:start],:$lt => options[:end]}, :host_id => options[:host_id], :plugin_id => options[:plugin_id] }).order(:timestamp).group_by{|u| u.domain}.each_pair do |domain,stats|
    stats.each do |stat|
      tmp[stat['timestamp']] ||= { 'timestamp' => stat['timestamp'] }
      tmp[stat['timestamp']] = tmp[stat['timestamp']].merge!({ stat['domain'] => stat['memory']})
    end
  end
  memory[:graph_data] = tmp.values
  all_stats.keys.each do |domain|
    memory[:graphs] << { :value_axis => 'valueAxis1', :value_field => domain, :balloon_text => "[[title]]: [[value]] KB", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 1, :graph_type => 'line' }
  end
  memory
end

.vbd_chart(options) ⇒ 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/app/models/xen.rb', line 16

def self.vbd_chart(options)
  memory = {
             :value_axes => [
                 { 
	    :name => "valueAxis1",
	    :title => 'Memory in KB',
	    :position => 'left',
	    :stack_type => 'regular',
	    :grid_alpha => 0.07,
	    :min_max_multiplier => 1,
                          :include_guides_in_min_max => 'true'
	  }
	],
      :category_field => 'timestamp',
             :graph_data => [],
      :graphs => [],
      :title => "XEN memory usage",
      :title_size => 20
    }
  graphs = []
  # TODO - why use periods in this query
  Xen.where(:timestamp.gte => options[:start]).
      where(:timestamp.lt => options[:end]).
	where(:ip_address => options[:ip_address]).
	where(:hostname => options[:hostname]).
	group('UNIX_TIMESTAMP(timestamp) div 60, domain').
	order_by(:timestamp).select('FROM_UNIXTIME((UNIX_TIMESTAMP(timestamp) div 60) *60,\'%Y-%m-%d %H:%i:%S\') as period_start, domain,max(memory) as memory').group_by{|u| u.period_start}.each_pair do |period_start, domains|
   tmp = { :year => period_start.to_datetime.to_i * 1000 }
   #TODO sort
   domains.each do |domain|
     tmp[domain.domain] = domain.memory
     graphs << domain.domain  unless graphs.include?(domain.domain)
   end
   memory[:graph_data] << tmp
 end
  graphs.each do |graph|
    #TODO value_axis
    memory[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :balloon_text => "[[title]]: [[value]] KB", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 1, :graph_type => 'line' }
  end
  memory
end