Class: One2Influx::VirtualMachine
- Defined in:
- lib/one2influx/one_object/virtual_machine.rb
Overview
Representation of ONE virtual machine
Instance Attribute Summary
Attributes inherited from OneObject
Instance Method Summary collapse
-
#get_MEMORY_PERC ⇒ float
Computes percentage usage of memory for virtual machine.
-
#initialize(xml, client, parent_host) ⇒ VirtualMachine
constructor
A new instance of VirtualMachine.
Methods inherited from OneObject
#method_missing, #serialize_as_points
Constructor Details
#initialize(xml, client, parent_host) ⇒ VirtualMachine
Returns a new instance of VirtualMachine.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/one2influx/one_object/virtual_machine.rb', line 8 def initialize(xml, client, parent_host) # Load configuration @tag_names = $CFG.storage[:vm][:tags] @metric_names = $CFG.storage[:vm][:metrics] @custom_metric_names = $CFG.storage[:vm][:cust_metrics] # Assign tags inherited from parent host @tags = Hash.new $CFG.storage[:vm][:inh_tags].each do |name, value| @tags[name] = parent_host.[value.to_sym] end super(xml, client) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class One2Influx::OneObject
Instance Method Details
#get_MEMORY_PERC ⇒ float
Computes percentage usage of memory for virtual machine.
Values might go over 1.0 as there is an overhead
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/one2influx/one_object/virtual_machine.rb', line 25 def get_MEMORY_PERC template_id = @doc.xpath('//TEMPLATE').first if template_id.nil? || template_id.content.nil? $LOG.error "Unable to get metric 'MEMORY_PERC' in #{self.class}." return end template_id = template_id.content template = OpenNebula::Template.new(OpenNebula::Template.build_xml(template_id), @client) rc = template.info raise rc. if OpenNebula.is_error?(rc) doc = Nokogiri::XML(template.to_xml) ni_element = doc.xpath('//TEMPLATE/MEMORY').first puts @metrics if ni_element.nil? || @metrics[:MEMORY].nil? $LOG.error "Unable to get metric 'MEMORY_PERC' in #{self.class}." return end # Convert //TEMPLATE/MEMORY from MB to kB as //VM/CPU is in kB max_mem = ni_element.content.to_f * 1000.0 @metrics[:MEMORY].to_f / max_mem end |