mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-09 14:03:20 +09:00
Feature #1279: Individual VM & Host monitoring methods in Ruby OCA
This commit is contained in:
1 parent
dfcb2eb166
commit
f65f995cc4
3 files changed
+102
-13
No files matched your search
@@ -25,11 +25,12 @@ module OpenNebula
|
||||
|
||||
|
||||
HOST_METHODS = {
|
||||
:info => "host.info",
|
||||
:allocate => "host.allocate",
|
||||
:delete => "host.delete",
|
||||
:enable => "host.enable",
|
||||
:update => "host.update"
|
||||
:info => "host.info",
|
||||
:allocate => "host.allocate",
|
||||
:delete => "host.delete",
|
||||
:enable => "host.enable",
|
||||
:update => "host.update",
|
||||
:monitoring => "host.monitoring"
|
||||
}
|
||||
|
||||
HOST_STATES=%w{INIT MONITORING MONITORED ERROR DISABLED}
|
||||
@@ -112,6 +113,30 @@ module OpenNebula
|
||||
super(HOST_METHODS[:update], new_template)
|
||||
end
|
||||
|
||||
# Retrieves this Host's monitoring data from OpenNebula
|
||||
#
|
||||
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
||||
# elements to retrieve. For example:
|
||||
# ['HOST_SHARE/FREE_CPU', 'HOST_SHARE/RUNNING_VMS', 'TEMPLATE/CUSTOM_PROBE']
|
||||
#
|
||||
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
||||
# the requested xpath expressions, and an Array of [timestamp, value].
|
||||
# For example:
|
||||
#
|
||||
# { "HOST_SHARE/RUNNING_VMS" =>
|
||||
# [["1337266000", "1"],
|
||||
# ["1337266044", "1"],
|
||||
# ["1337266088", "3"]],
|
||||
# "HOST_SHARE/FREE_CPU" =>
|
||||
# [["1337266000", "800"],
|
||||
# ["1337266044", "800"],
|
||||
# ["1337266088", "800"]]
|
||||
# }
|
||||
def monitoring(xpath_expressions)
|
||||
return super(HOST_METHODS[:monitoring], 'HOST',
|
||||
'LAST_MON_TIME', xpath_expressions)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Host information
|
||||
#######################################################################
|
||||
|
||||
@@ -255,6 +255,45 @@ module OpenNebula
|
||||
return rc
|
||||
end
|
||||
|
||||
|
||||
# Retrieves this Element's monitoring data from OpenNebula
|
||||
#
|
||||
# @param xml_method [String] the name of the XML-RPC method
|
||||
# @param root_elem [String] Root for each individual PoolElement
|
||||
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
||||
# elements to retrieve.
|
||||
#
|
||||
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
||||
# the requested xpath expressions, and an Array of [timestamp, value].
|
||||
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(xml_method, @pe_id)
|
||||
|
||||
if ( OpenNebula.is_error?(rc) )
|
||||
return rc
|
||||
end
|
||||
|
||||
xmldoc = XMLElement.new
|
||||
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
||||
|
||||
hash = {}
|
||||
timestamps = xmldoc.retrieve_elements(
|
||||
root_elem + '/' + timestamp_elem)
|
||||
|
||||
xpath_expressions.each { |xpath|
|
||||
xpath_values = xmldoc.retrieve_elements(root_elem + '/' + xpath)
|
||||
|
||||
if ( xpath_values.nil? )
|
||||
hash[xpath] = []
|
||||
else
|
||||
hash[xpath] = timestamps.zip(xpath_values)
|
||||
end
|
||||
}
|
||||
|
||||
return hash
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
# Creates new element specifying its id
|
||||
|
||||
@@ -25,14 +25,15 @@ module OpenNebula
|
||||
|
||||
|
||||
VM_METHODS = {
|
||||
:info => "vm.info",
|
||||
:allocate => "vm.allocate",
|
||||
:action => "vm.action",
|
||||
:migrate => "vm.migrate",
|
||||
:deploy => "vm.deploy",
|
||||
:savedisk => "vm.savedisk",
|
||||
:chown => "vm.chown",
|
||||
:chmod => "vm.chmod",
|
||||
:info => "vm.info",
|
||||
:allocate => "vm.allocate",
|
||||
:action => "vm.action",
|
||||
:migrate => "vm.migrate",
|
||||
:deploy => "vm.deploy",
|
||||
:savedisk => "vm.savedisk",
|
||||
:chown => "vm.chown",
|
||||
:chmod => "vm.chmod",
|
||||
:monitoring => "vm.monitoring"
|
||||
}
|
||||
|
||||
VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
|
||||
@@ -275,6 +276,30 @@ module OpenNebula
|
||||
group_m, group_a, other_u, other_m, other_a)
|
||||
end
|
||||
|
||||
# Retrieves this VM's monitoring data from OpenNebula
|
||||
#
|
||||
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
||||
# elements to retrieve. For example:
|
||||
# ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE']
|
||||
#
|
||||
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
||||
# the requested xpath expressions, and an Array of [timestamp, value].
|
||||
# For example:
|
||||
#
|
||||
# { "NET_TX" =>
|
||||
# [["1337264510", "210"],
|
||||
# ["1337264553", "220"],
|
||||
# ["1337264584", "230"]],
|
||||
# "CPU" =>
|
||||
# [["1337264510", "0"],
|
||||
# ["1337264553", "0"],
|
||||
# ["1337264584", "0"]]
|
||||
# }
|
||||
def monitoring(xpath_expressions)
|
||||
return super(VM_METHODS[:monitoring], 'VM',
|
||||
'LAST_POLL', xpath_expressions)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get VirtualMachine information
|
||||
#######################################################################
|
||||
|
||||
Reference in new issue
Block a user