Class: Memory

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

Class Method Summary collapse

Class Method Details

.chart_data(options = {}) ⇒ Object



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

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

.graphsObject



46
47
48
49
50
51
52
53
54
# File 'lib/app/models/memory.rb', line 46

def self.graphs
  {
    :used => { :line_color => '#FF3300' },
    :cached => {:line_color => '#FFFF00' },
    :buffers => {:line_color => '#FFaa33' },
    :free => {:line_color => '#00FF00' },
    :swap_used => {:line_color => '#00FFFF' }
  }
end

.memory_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
# File 'lib/app/models/memory.rb', line 16

def self.memory_chart(options)
  chart = self.chart_structure({:title => "Host memory usage", :value_axis => { :title => "Memory size in KB"}})
  #TODO - get fields from above DRY
  chart[:graph_data] = Memory.where(:timestamp.gte => options[:start]).
                              where(:timestamp.lt => options[:end]).
		where(:host_id => options[:host_id]).
		where(:plugin_id => options[:plugin_id]).order_by(timestamp: :asc)

  guides = []
  host_facts = Facts.get_latest_facts_for_host(options[:host_id])
  unless host_facts.nil?
    memory_total_bytes = host_facts['facts']['memory']['system']['total_bytes']
    memory_total_kibytes = memory_total_bytes/1024
    guide = {}
    require 'ruby-units'
    guide[:value] = memory_total_kibytes
    guide[:value_axis] = 'valueAxis1'
    guide[:line_color] = "#FF0000"
    guide[:line_thickness] = 1
    guide[:dash_length] = 5
    guide[:label] = "Total physical memory: #{memory_total_kibytes}KiB (by facter)"
    guide[:inside] = true
    guide[:line_alpha] = 1
    guide[:position] = 'bottom'
    guides << guide
  end
  chart[:guides] = guides
  chart
end