Class: Cpu

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

Class Method Summary collapse

Class Method Details

.axes_defaultsObject



83
84
85
# File 'lib/app/models/cpu.rb', line 83

def self.axes_defaults
  []
end

.chart_data(options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/app/models/cpu.rb', line 8

def self.chart_data(options = {})
  charts = []
  charts << self.cpu_chart(options)
  return charts
end

.cpu_aggregate(options) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/app/models/cpu.rb', line 68

def self.cpu_aggregate(options)
  #data = Cpu.where( { :timestamp => {:$gte => options[:start],:$lt => options[:end]} , :cpu_id => 'cpu', :host_id => options[:host_id], :plugin_id => options[:plugin_id]} ).order_by(timestamp: asc).all

  data = Cpu.where( :timestamp.gte => options[:start]).
             where( :timestamp.lt => options[:end]).
             where( :cpu_id => 'cpu').
      where( :host_id => options[:host_id]).
      where( :plugin_id => options[:plugin_id] ).order_by(timestamp: :asc)
  data
end

.cpu_chart(options) ⇒ Object



14
15
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
57
58
59
60
61
62
63
# File 'lib/app/models/cpu.rb', line 14

def self.cpu_chart(options)
  cpu_utilization = {
             :value_axes => [
                 { 
	    :name => "valueAxis1",
	    :title => 'Cpu utilization in %',
	    :position => 'left',
	    :min_max_multiplier => 1,
	    :stack_type => '100%',
                          :include_guides_in_min_max => 'true',
	    :grid_alpha => 0.1
	  }
	],
             :graph_data => [],
      :category_field => 'timestamp',
      :graphs => [],
      :title => "Host CPU usage",
      :title_size => 20
    }

  #CHOOSE HERE which
  # TODO ADD ALL TYPES
  graphs = {
    'system' =>  { :value_axis => 'valueAxis1', :line_color => "#FF0000", :balloon_text => "[[title]]: ([[percents]]%)", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line' },
    'nice' => { :line_color => '#FF3300' },
    'user' => { :line_color => '#FF7700' },
    'iowait' => { :line_color => '#FFaa00' },
    'irq' => { :line_color => '#FFdd00' },
    'softirq' => { :line_color => '#FFFF00' },
    'idle' => {:line_color => '#00FF00' }
  }
  prev = nil
  self.cpu_aggregate(options).each do |data|
    if prev.nil? then
      prev = data
      next
    end
    temp = {"timestamp" => data[:timestamp]}
    graphs.each_key {|g| temp[g] = data[g] - prev[g]}
    cpu_utilization[:graph_data] << temp
    prev = data
  end

  graphs.each_pair do |graph, properties|
    #TODO value_axis
    #TODO merge set values with default
    cpu_utilization[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :line_color => properties[:line_color],  :balloon_text => "[[title]]: ([[percents]]%)", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line', :title => graph}
  end
  cpu_utilization
end

.cpu_detailed(options) ⇒ Object



65
66
# File 'lib/app/models/cpu.rb', line 65

def self.cpu_detailed(options)
end

.graphs_defaultsObject



79
80
81
# File 'lib/app/models/cpu.rb', line 79

def self.graphs_defaults
 []
end