1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #3718: New template for MONITORING data, it can accomodate any

data, and support the general OpenNebula Template format.
This commit is contained in:
Ruben S. Montero 2015-06-23 21:52:10 +02:00
parent 5f1d630fc6
commit 685a46365d
8 changed files with 124 additions and 161 deletions

View File

@ -18,6 +18,7 @@
#define VIRTUAL_MACHINE_H_
#include "VirtualMachineTemplate.h"
#include "VirtualMachineMonitorInfo.h"
#include "PoolSQL.h"
#include "History.h"
#include "Image.h"
@ -385,7 +386,7 @@ public:
* Updates VM dynamic information (id).
* @param _deploy_id the VMM driver specific id
*/
void set_deploy_id(const string& _deploy_id)
void set_deploy_id (const string& _deploy_id)
{
deploy_id = _deploy_id;
};
@ -393,19 +394,8 @@ public:
/**
* Updates VM dynamic information (usage counters), and updates last_poll,
* and copies it to history record for acct.
* @param _memory Kilobytes used by the VM (total)
* @param _cpu used by the VM (rate)
* @param _net_tx transmitted bytes (total)
* @param _net_rx received bytes (total)
*/
void update_info(
int _memory,
int _cpu,
long long _net_tx,
long long _net_rx,
long long _disk_actual,
long long _disk_virtual,
const map<string, string> &custom);
int update_info(const string& monitor_data);
/**
* Clears the VM monitor information: usage counters, last_poll,
@ -413,9 +403,18 @@ public:
*/
void reset_info()
{
map<string,string> empty;
last_poll = time(0);
update_info(0, 0, -1, -1, -1, -1, empty);
monitoring.clear();
set_vm_info();
clear_template_monitor_error();
}
const VirtualMachineMonitorInfo& get_info() const
{
return monitoring;
}
/**
@ -1733,24 +1732,25 @@ private:
*/
map<int, Snapshots *> snapshots;
// -------------------------------------------------------------------------
// Logging & Dirs
// -------------------------------------------------------------------------
/**
* User template to store custom metadata. This template can be updated
*/
VirtualMachineTemplate * user_obj_template;
/**
* Monitoring information for the VM
*/
VirtualMachineMonitorInfo monitoring;
/**
* Log class for the virtual machine, it writes log messages in
* $ONE_LOCATION/var/$VID/vm.log
* or, in case that OpenNebula is installed in root
* /var/log/one/$VM_ID.log
* For the syslog... TODO
* For the syslog it will use the predefined /var/log/ locations
*/
Log * _log;
/**
* User template to store custom metadata. This template can be updated
*
*/
VirtualMachineTemplate * user_obj_template;
// *************************************************************************
// DataBase implementation (Private)

View File

@ -157,22 +157,22 @@ class AcctHelper < OpenNebulaHelper::OneHelper
column :NET_RX, "Data received from the network", :size=>6 do |d|
# NET is measured in bytes, unit_to_str expects KBytes
OpenNebulaHelper.unit_to_str(d["VM"]["NET_RX"].to_i / 1024.0, {})
OpenNebulaHelper.unit_to_str(d["VM"]["MONITORING/NETRX"].to_i / 1024.0, {})
end
column :NET_TX, "Data sent to the network", :size=>6 do |d|
# NET is measured in bytes, unit_to_str expects KBytes
OpenNebulaHelper.unit_to_str(d["VM"]["NET_TX"].to_i / 1024.0, {})
OpenNebulaHelper.unit_to_str(d["VM"]["MONITORING/NETTX"].to_i / 1024.0, {})
end
column :DISK_ACTUAL, "Total disk size used", :size=>6 do |d|
# DISK size is measured in mb, unit_to_str expects KBytes
OpenNebulaHelper.unit_to_str(d["VM"]["DISK_ACTUAL_SIZE"].to_i * 1024.0, {})
OpenNebulaHelper.unit_to_str(d["VM"]["MONITORING/DISK_ACTUAL_SIZE"].to_i * 1024.0, {})
end
column :DISK_VIRTUAL, "Total disk virtual size used", :size=>6 do |d|
# DISK size is measured in mb, unit_to_str expects KBytes
OpenNebulaHelper.unit_to_str(d["VM"]["DISK_VIRTUAL_SIZE"].to_i * 1024.0, {})
OpenNebulaHelper.unit_to_str(d["VM"]["MONITORING/DISK_VIRTUAL_SIZE"].to_i * 1024.0, {})
end
default :VID, :HOSTNAME, :ACTION, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX, :DISK_ACTUAL, :DISK_VIRTUAL
end

View File

@ -503,12 +503,12 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE MONITORING",false)
poll_attrs = {
"USED MEMORY" => "MEMORY",
"USED CPU" => "CPU",
"NET_TX" => "NET_TX",
"NET_RX" => "NET_RX",
"DISK SIZE (ACTUAL)" => "DISK_ACTUAL_SIZE",
"DISK SIZE (VIRTUAL)" => "DISK_VIRTUAL_SIZE"
"USED MEMORY" => "MONITORING/USEDMEMORY",
"USED CPU" => "MONITORING/USEDCPU",
"NET_TX" => "MONITORING/NETTX",
"NET_RX" => "MONITORING/NETRX",
"DISK SIZE (ACTUAL)" => "MONITORING/DISK_ACTUAL_SIZE",
"DISK SIZE (VIRTUAL)" => "MONITORING/DISK_VIRTUAL_SIZE"
}
poll_attrs.each { |k,v|

View File

@ -535,19 +535,15 @@ module OpenNebula
# the requested xpath expressions, and an Array of 'timestamp, value'.
#
# @example
# vm.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
# vm.monitoring( ['MONITORING/USEDCPU', 'MONITORING/NETTX'] )
#
# { "NET_TX" =>
# [["1337264510", "210"],
# ["1337264553", "220"],
# ["1337264584", "230"]],
# "TEMPLATE/CUSTOM_PROBE" =>
# [],
# "CPU" =>
# [["1337264510", "0"],
# ["1337264553", "0"],
# ["1337264584", "0"]]
# {
# "MONITORING/USEDCPU"=>[["1435085098", "47"], ["1435085253", "5"],
# ["1435085410", "48"], ["1435085566", "3"], ["1435088136", "2"]],
# "MONITORING/NETTX"=>[["1435085098", "0"], ["1435085253", "50"],
# ["1435085410", "50"], ["1435085566", "50"], ["1435085723", "50"]]
# }
#
def monitoring(xpath_expressions)
return super(VM_METHODS[:monitoring], 'VM',
'LAST_POLL', xpath_expressions)

View File

@ -132,23 +132,24 @@ module OpenNebula
# and an Array of 'timestamp, value'.
#
# @example
# vm_pool.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )
# vm_pool.monitoring( ['MONITORING/USEDCPU', 'MONITORING/NETTX'] )
#
# {"1"=>
# {"CPU"=>
# [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
# "NET_TX"=>
# [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
# "TEMPLATE/CUSTOM_PROBE"=>
# []},
# {"3"=>
# {
# "MONITORING/USEDCPU"=>[["1435085098", "47"], ["1435085253", "5"],
# ["1435085410", "48"], ["1435085566", "3"], ["1435088136", "2"]],
# "MONITORING/NETTX"=>[["1435085098", "0"], ["1435085253", "50"],
# ["1435085410", "50"], ["1435085566", "50"], ["1435085723", "50"]]
# },
# "43" =>
# {
# "MONITORING/USEDCPU"=>[["1435085098", "47"], ["1435085253", "5"],
# ["1435085410", "48"], ["1435085566", "3"], ["1435088136", "2"]],
# "MONITORING/NETTX"=>[["1435085098", "0"], ["1435085253", "50"],
# ["1435085410", "50"], ["1435085566", "50"], ["1435085723", "50"]]
# }
# }
#
# "0"=>
# {"CPU"=>
# [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
# "NET_TX"=>
# [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
# "TEMPLATE/CUSTOM_PROBE"=>
# []}}
def monitoring(xpath_expressions, filter_flag=INFO_ALL)
return super(VM_POOL_METHODS[:monitoring],
'VM', 'LAST_POLL', xpath_expressions, filter_flag)

View File

@ -58,12 +58,6 @@ VirtualMachine::VirtualMachine(int id,
stime(time(0)),
etime(0),
deploy_id(""),
memory(0),
cpu(0),
net_tx(0),
net_rx(0),
disk_actual(0),
disk_virtual(0),
history(0),
previous_history(0),
_log(0)
@ -3664,6 +3658,7 @@ string& VirtualMachine::to_xml_extended(string& xml, int n_history) const
{
string template_xml;
string user_template_xml;
string monitoring_xml;
string history_xml;
string perm_xml;
string snap_xml;
@ -3687,12 +3682,7 @@ string& VirtualMachine::to_xml_extended(string& xml, int n_history) const
<< "<STIME>" << stime << "</STIME>"
<< "<ETIME>" << etime << "</ETIME>"
<< "<DEPLOY_ID>" << deploy_id << "</DEPLOY_ID>"
<< "<MEMORY>" << memory << "</MEMORY>"
<< "<CPU>" << cpu << "</CPU>"
<< "<NET_TX>" << net_tx << "</NET_TX>"
<< "<NET_RX>" << net_rx << "</NET_RX>"
<< "<DISK_ACTUAL_SIZE>" << disk_actual << "</DISK_ACTUAL_SIZE>"
<< "<DISK_VIRTUAL_SIZE>"<< disk_virtual<< "</DISK_VIRTUAL_SIZE>"
<< monitoring.to_xml(monitoring_xml)
<< obj_template->to_xml(template_xml)
<< user_obj_template->to_xml(user_template_xml);
@ -3763,13 +3753,6 @@ int VirtualMachine::from_xml(const string &xml_str)
rc += xpath(etime, "/VM/ETIME", 0);
rc += xpath(deploy_id, "/VM/DEPLOY_ID","");
rc += xpath(memory, "/VM/MEMORY", 0);
rc += xpath(cpu, "/VM/CPU", 0);
rc += xpath(net_tx, "/VM/NET_TX", 0);
rc += xpath(net_rx, "/VM/NET_RX", 0);
rc += xpath(disk_actual, "/VM/DISK_ACTUAL_SIZE", 0);
rc += xpath(disk_virtual,"/VM/DISK_VIRTUAL_SIZE", 0);
// Permissions
rc += perms_from_xml();
@ -3798,6 +3781,20 @@ int VirtualMachine::from_xml(const string &xml_str)
ObjectXML::free_nodes(content);
content.clear();
// Virtual Machine Monitoring
ObjectXML::get_nodes("/VM/MONITORING", content);
if (content.empty())
{
return -1;
}
rc += monitoring.from_xml_node(content[0]);
ObjectXML::free_nodes(content);
content.clear();
// Virtual Machine user template
ObjectXML::get_nodes("/VM/USER_TEMPLATE", content);
@ -3876,57 +3873,40 @@ string VirtualMachine::get_system_dir() const
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::update_info(
int _memory,
int _cpu,
long long _net_tx,
long long _net_rx,
long long _disk_actual,
long long _disk_virtual,
const map<string, string> &custom)
int VirtualMachine::update_info(const string& monitor_data)
{
map<string, string>::const_iterator it;
int rc;
string error;
ostringstream oss;
last_poll = time(0);
if (_memory != -1)
{
memory = _memory;
}
rc = monitoring.update(monitor_data, error);
if (_cpu != -1)
if ( rc != 0)
{
cpu = _cpu;
}
oss << "Ignoring monitoring information, error:" << error
<< ". Monitor information was: " << monitor_data;
if (_net_tx != -1)
{
net_tx = _net_tx;
}
NebulaLog::log("VMM", Log::ERROR, oss);
if (_net_rx != -1)
{
net_rx = _net_rx;
}
set_template_error_message(oss.str());
if (_disk_actual != -1)
{
disk_actual = _disk_actual;
}
log("VMM", Log::ERROR, oss);
if (_disk_virtual != -1)
{
disk_virtual = _disk_virtual;
}
for (it = custom.begin(); it != custom.end(); it++)
{
replace_template_attribute(it->first, it->second);
return -1;
}
set_vm_info();
clear_template_monitor_error();
oss << "VM " << oid << " successfully monitored: " << monitor_data;
NebulaLog::log("VMM", Log::DEBUG, oss);
return 0;
};
/* -------------------------------------------------------------------------- */

View File

@ -596,64 +596,50 @@ void VirtualMachineManagerDriver::process_poll(
VirtualMachine* vm,
const string& monitor_str)
{
int rc;
int cpu;
int memory;
long long net_tx;
long long net_rx;
long long dactual;
long long dvirtual;
char state;
map<string, string> custom;
ostringstream oss;
char state;
Nebula &ne = Nebula::instance();
LifeCycleManager* lcm = ne.get_lcm();
VirtualMachinePool* vmpool = ne.get_vmpool();
/* ---------------------------------------------------------------------- */
/* Parse VM info */
/* ---------------------------------------------------------------------- */
rc = parse_vm_info(monitor_str, cpu, memory, net_tx, net_rx, dactual,
dvirtual, state, custom);
if (rc == -1) //Parse error, ignore this monitor data
{
oss << "Ignoring monitoring information, parse error."
<< " Monitor information was: "
<< monitor_str;
NebulaLog::log("VMM", Log::ERROR, oss);
vm->set_template_error_message(oss.str());
vm->log("VMM", Log::ERROR, oss);
vmpool->update(vm);
return;
}
oss << "VM " << vm->get_oid() << " successfully monitored: " << monitor_str;
NebulaLog::log("VMM", Log::DEBUG, oss);
/* ---------------------------------------------------------------------- */
/* Update VM info only for VMs in ACTIVE */
/* ---------------------------------------------------------------------- */
if (vm->get_state() == VirtualMachine::ACTIVE)
{
vm->update_info(memory, cpu, net_tx, net_rx, dactual, dvirtual, custom);
if (vm->update_info(monitor_str) == 0)
{
vmpool->update_history(vm);
vmpool->update_monitoring(vm);
}
vmpool->update(vm);
vmpool->update_history(vm);
const VirtualMachineMonitorInfo &minfo = vm->get_info();
vmpool->update_monitoring(vm);
state = minfo.get_state();
}
else
{
VirtualMachineMonitorInfo minfo;
string error;
if (minfo.update(monitor_str, error) != 0)
{
ostringstream oss;
oss << "Ignoring monitoring information, error:" << error
<< ". Monitor information was: " << monitor_str;
NebulaLog::log("VMM", Log::ERROR, oss);
return;
};
state = minfo.get_state();
}
/* ---------------------------------------------------------------------- */

View File

@ -180,13 +180,13 @@ class DummyDriver < VirtualMachineDriver
end
prev_nettx = 0
if msg.elements["VM/NET_TX"]
prev_nettx = msg.elements["VM/NET_TX"].text.to_i
if msg.elements["VM/MONITORING/NET_TX"]
prev_nettx = msg.elements["VM/MONITORING/NET_TX"].text.to_i
end
prev_netrx = 0
if msg.elements["VM/NET_RX"]
prev_netrx = msg.elements["VM/NET_RX"].text.to_i
if msg.elements["VM/MONITORING/NET_RX"]
prev_netrx = msg.elements["VM/MONITORING/NET_RX"].text.to_i
end
# monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL"