B #4793: Fix DS VM monitoring

* Merge VM DB monitor information with previous record.
    * DS sends monitor data to monitord socket
    * Fix VM monitor template merging for "local" disks

co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
This commit is contained in:
Ruben S. MonteroandPavel Czerný committed 2020-05-26 19:41:45 +02:00
1 parent bf1946fe76
commit 4702edee46
6 files changed
+117 -39

No files matched your search

+8 -2
View File
@@ -117,13 +117,19 @@ public:
/**
* Sets the monitor information of the VM.
* @param oid VM id
* @param result
* @param tmpl monitoring template
*/
void monitor_vm(int oid,
const std::string &deploy_id,
const Template &tmpl);
/**
* Sets the monitor information of the VM.
* @param deploy_id Wild VM deploy_id
* @param tmpl monitoring template
*/
void monitor_wild_vm(const std::string &deploy_id,
const Template &tmpl);
/**
* Receive start monitor failure/success from driver
* @param oid host id
+5
View File
@@ -53,6 +53,11 @@ public:
*/
int update_monitoring(const VirtualMachineMonitorInfo& vm);
/**
* Read last monitoring from DB
*/
bool get_monitoring(int vmid, VirtualMachineMonitorInfo& vm);
/**
* Gets a VM ID by its deploy_id
* @param deploy_id to search the id for
+32
View File
@@ -62,6 +62,38 @@ int VMRPCPool::update_monitoring(const VirtualMachineMonitorInfo& monitoring)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool VMRPCPool::get_monitoring(int vmid, VirtualMachineMonitorInfo& vm)
{
ostringstream cmd;
string monitor_str;
cmd << "SELECT " << one_db::vm_monitor_table << ".body FROM "
<< one_db::vm_monitor_table
<< " WHERE vmid = " << vmid
<< " AND last_poll=(SELECT MAX(last_poll) FROM "
<< one_db::vm_monitor_table
<< " WHERE vmid = " << vmid << ")";
string_cb cb(1);
cb.set_callback(&monitor_str);
int rc = db->exec_rd(cmd, &cb);
cb.unset_callback();
if (rc == 0 && !monitor_str.empty())
{
vm.from_xml(monitor_str);
return true;
}
return false;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VMRPCPool::get_vmid(const string& deploy_id)
{
int rc;
+26 -13
View File
@@ -307,7 +307,6 @@ void HostMonitorManager::update_last_monitor(int oid)
/* -------------------------------------------------------------------------- */
void HostMonitorManager::monitor_vm(int oid,
const string& uuid,
const Template &tmpl)
{
if (!is_leader)
@@ -315,20 +314,11 @@ void HostMonitorManager::monitor_vm(int oid,
return;
}
if (oid < 0)
{
// Wild VM, check if it is imported to OpenNebula
oid = vmpool->get_vmid(uuid);
if (oid < 0)
{
// Not imported VM, ignore monitoring
return;
}
}
VirtualMachineMonitorInfo monitoring(oid, time(nullptr));
//Get previous monitor info to merge with new data
vmpool->get_monitoring(oid, monitoring);
if (monitoring.from_template(tmpl) != 0)
{
string str;
@@ -349,6 +339,29 @@ void HostMonitorManager::monitor_vm(int oid,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HostMonitorManager::monitor_wild_vm(const string& deploy_id,
const Template &tmpl)
{
if (!is_leader)
{
return;
}
// Wild VM, check if it is imported to OpenNebula
int oid = vmpool->get_vmid(deploy_id);
if (oid < 0)
{
// Not imported VM, ignore monitoring
return;
}
monitor_vm(oid, tmpl);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HostMonitorManager::start_monitor_failure(int oid)
{
if (!is_leader)
@@ -68,12 +68,12 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg)
return;
}
map<string, pair<int, Template>> vms_templ;
map<int, Template> vms_templ;
vector<VectorAttribute*> vms;
tmpl.get("VM", vms);
// Merge all attributes by deploy_id
// Merge all attributes by ID
for (const auto& vm : vms)
{
int id = -1;
@@ -90,35 +90,47 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg)
auto monitor_plain = one_util::base64_decode(monitor_b64);
if (monitor_plain != nullptr)
if (monitor_plain == nullptr)
{
Template mon_tmpl;
NebulaLog::error("MDP", "Error decoding VM monitor attribute: "
+ monitor_b64);
continue;
}
rc = mon_tmpl.parse(*monitor_plain, &error_msg);
Template mon_tmpl;
if (rc != 0)
{
NebulaLog::error("MDP", "Error parsing VM monitor attribute: "
+ *monitor_plain + ", error: " + error_msg);
rc = mon_tmpl.parse(*monitor_plain, &error_msg);
delete monitor_plain;
free(error_msg);
continue;
}
if (rc != 0)
{
NebulaLog::error("MDP", "Error parsing VM monitor attribute: "
+ *monitor_plain + ", error: " + error_msg);
delete monitor_plain;
auto it = vms_templ.find(deploy_id);
free(error_msg);
continue;
}
delete monitor_plain;
if (id < 0)
{
// Wild VM, no need to merge storage monitor data
hm->monitor_wild_vm(deploy_id, mon_tmpl);
}
else
{
// OpenNebula VM, merge templates with same ID
auto it = vms_templ.find(id);
if (it == vms_templ.end())
{
vms_templ.insert(make_pair(std::move(deploy_id),
make_pair(id, std::move(mon_tmpl))));
vms_templ[id] = std::move(mon_tmpl);
}
else
{
it->second.second.merge(&mon_tmpl);
it->second.merge(&mon_tmpl);
}
}
}
@@ -126,7 +138,7 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg)
// Process all monitoring templates
for (const auto& vm : vms_templ)
{
hm->monitor_vm(vm.second.first, vm.first, vm.second.second);
hm->monitor_vm(vm.first, vm.second);
}
}
@@ -247,7 +259,7 @@ void MonitorDriverProtocol::_state_vm(message_t msg)
*/
void MonitorDriverProtocol::_start_monitor(message_t msg)
{
NebulaLog::debug("MDP", "Received start monitor for host " +
NebulaLog::ddebug("MDP", "Received start monitor for host " +
to_string(msg->oid()) + ": " + msg->payload());
if (msg->status() != "SUCCESS")