1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-03 01:17:41 +03:00

F 5147#: improve monitoring API calls performance (#370)

This commit is contained in:
Christian González 2020-10-28 17:12:27 +01:00 committed by GitHub
parent 6395b3f891
commit 93e7c7677c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 138 additions and 74 deletions

View File

@ -235,10 +235,11 @@ public:
*
* @param oss the output stream to dump the pool contents
* @param where filter for the objects, defaults to all
* @param seconds Retrieve monitor records in the last seconds
*
* @return 0 on success
*/
int dump_monitoring(std::string& oss, const std::string& where);
int dump_monitoring(std::string& oss, const std::string& where, const int seconds);
/**
* Dumps the HOST monitoring information for a single HOST
@ -254,7 +255,7 @@ public:
filter << "oid = " << hostid;
return dump_monitoring(oss, filter.str());
return dump_monitoring(oss, filter.str(), -1);
}
/**

View File

@ -319,10 +319,11 @@ public:
*
* @param oss the output stream to dump the pool contents
* @param where filter for the objects, defaults to all
* @param seconds Retrieve monitor records in the last seconds
*
* @return 0 on success
*/
int dump_monitoring(std::string& oss, const std::string& where);
int dump_monitoring(std::string& oss, const std::string& where, const int seconds);
/**
* Dumps the VM monitoring information for a single VM
@ -338,7 +339,7 @@ public:
filter << "oid = " << vmid;
return dump_monitoring(oss, filter.str());
return dump_monitoring(oss, filter.str(), -1);
}
/**

View File

@ -159,20 +159,72 @@ int HostPool::update(PoolObjectSQL * objsql)
int HostPool::dump_monitoring(
string& oss,
const string& where)
const string& where,
const int seconds)
{
ostringstream cmd;
cmd << "SELECT " << one_db::host_monitor_table << ".body FROM "
<< one_db::host_monitor_table << " INNER JOIN " << one_db::host_table
<< " ON hid = oid";
if ( !where.empty() )
switch(seconds)
{
cmd << " WHERE " << where;
}
case 0: //Get last monitor value
/*
* SELECT host_monitoring.body
* FROM host_monitoring
* INNER JOIN (
* SELECT hid, MAX(last_mon_time) as last_mon_time
* FROM host_monitoring
* GROUP BY hid
* ) lmt on lmt.hid = host_monitoring.hid AND lmt.last_mon_time = host_monitoring.last_mon_time
* INNER JOIN host_pool ON host_monitoring.hid = oid
* ORDER BY oid;
*/
cmd << "SELECT " << one_db::host_monitor_table << ".body "
<< "FROM " << one_db::host_monitor_table << " INNER JOIN ("
<< "SELECT hid, MAX(last_mon_time) as last_mon_time FROM "
<< one_db::host_monitor_table << " GROUP BY hid) as lmt "
<< "ON lmt.hid = " << one_db::host_monitor_table << ".hid "
<< "AND lmt.last_mon_time = " << one_db::host_monitor_table
<< ".last_mon_time INNER JOIN " << one_db::host_table
<< " ON " << one_db::host_monitor_table << ".hid = oid";
cmd << " ORDER BY hid, " << one_db::host_monitor_table << ".last_mon_time;";
if ( !where.empty() )
{
cmd << " WHERE " << where;
}
cmd << " ORDER BY oid";
break;
case -1: //Get all monitoring
cmd << "SELECT " << one_db::host_monitor_table << ".body FROM "
<< one_db::host_monitor_table << " INNER JOIN " << one_db::host_table
<< " ON hid = oid";
if ( !where.empty() )
{
cmd << " WHERE " << where;
}
cmd << " ORDER BY hid, " << one_db::host_monitor_table << ".last_mon_time;";
break;
default: //Get monitor in last s seconds
cmd << "SELECT " << one_db::host_monitor_table << ".body FROM "
<< one_db::host_monitor_table << " INNER JOIN " << one_db::host_table
<< " ON hid = oid WHERE " << one_db::host_monitor_table
<< ".last_mon_time > " << time(nullptr) - seconds;
if ( !where.empty() )
{
cmd << " AND " << where;
}
cmd << " ORDER BY hid, " << one_db::host_monitor_table << ".last_mon_time;";
break;
}
return PoolSQL::dump(oss, "MONITORING_DATA", cmd);
}

View File

@ -540,9 +540,10 @@ void VirtualMachinePoolMonitoring::request_execute(
string oss;
string where;
string and_clause = "";
int rc;
int seconds = -1;
if ( filter_flag < GROUP )
{
att.resp_msg = "Incorrect filter_flag";
@ -552,33 +553,12 @@ void VirtualMachinePoolMonitoring::request_execute(
if (paramList.size() > 2)
{
ostringstream oss;
int s = xmlrpc_c::value_int(paramList.getInt(2));
switch (s)
{
case 0: //Get last monitor value
oss << one_db::vm_monitor_table << ".last_poll = "
<< "(SELECT MAX(last_poll) FROM " << one_db::vm_monitor_table
<< " AS t WHERE t.vmid = " << one_db::vm_monitor_table << ".vmid)";
and_clause = oss.str();
break;
case -1: //Get all monitoring
and_clause = "";
break;
default: //Get monitor in last s seconds
oss << one_db::vm_monitor_table << ".last_poll > " << time(nullptr) - s;
and_clause = oss.str();
break;
}
seconds = xmlrpc_c::value_int(paramList.getInt(2));
}
where_filter(att, filter_flag, -1, -1, and_clause, "", false, false, false, where);
where_filter(att, filter_flag, -1, -1, "", "", false, false, false, where);
rc = (static_cast<VirtualMachinePool *>(pool))->dump_monitoring(oss, where);
rc = (static_cast<VirtualMachinePool *>(pool))->dump_monitoring(oss, where, seconds);
if ( rc != 0 )
{
@ -760,41 +740,19 @@ void HostPoolMonitoring::request_execute(
{
string oss;
string where;
string and_clause = "";
int rc;
int seconds = -1;
if (paramList.size() > 1)
{
ostringstream oss;
int s = xmlrpc_c::value_int(paramList.getInt(1));
switch (s)
{
case 0: //Get last monitor value
oss << one_db::host_monitor_table << ".last_mon_time = "
<< "(SELECT MAX(last_mon_time) FROM " << one_db::host_monitor_table
<< " AS t WHERE t.hid = " << one_db::host_monitor_table << ".hid)";
and_clause = oss.str();
break;
case -1: //Get all monitoring
and_clause = "";
break;
default: //Get monitor in last s seconds
oss << one_db::host_monitor_table << ".last_mon_time > " << time(nullptr) - s;
and_clause = oss.str();
break;
}
and_clause = oss.str();
seconds = xmlrpc_c::value_int(paramList.getInt(1));
}
where_filter(att, ALL, -1, -1, and_clause, "", false, false, false, where);
where_filter(att, ALL, -1, -1, "", "", false, false, false, where);
rc = (static_cast<HostPool *>(pool))->dump_monitoring(oss, where);
rc = (static_cast<HostPool *>(pool))->dump_monitoring(oss, where, seconds);
if ( rc != 0 )
{

View File

@ -326,20 +326,72 @@ int VirtualMachinePool::dump_showback(string& oss,
int VirtualMachinePool::dump_monitoring(
string& oss,
const string& where)
const string& where,
const int seconds)
{
ostringstream cmd;
cmd << "SELECT " << one_db::vm_monitor_table << ".body FROM "
<< one_db::vm_monitor_table
<< " INNER JOIN " << one_db::vm_table << " ON vmid = oid";
if ( !where.empty() )
switch (seconds)
{
cmd << " WHERE " << where;
}
case 0: //Get last monitor value
/*
* SELECT vm_monitoring.body
* FROM vm_monitoring
* INNER JOIN (
* SELECT vmid, MAX(last_poll) as last_poll
* FROM vm_monitoring
* GROUP BY vmid
* ) lpt on lpt.vmid = vm_monitoring.vmid AND lpt.last_poll = vm_monitoring.last_poll
* INNER JOIN vm_pool ON vm_monitoring.vmid = oid
* ORDER BY oid;
*/
cmd << "SELECT " << one_db::vm_monitor_table << ".body "
<< "FROM " << one_db::vm_monitor_table << " INNER JOIN ("
<< "SELECT vmid, MAX(last_poll) as last_poll FROM "
<< one_db::vm_monitor_table << " GROUP BY vmid) as lpt "
<< "ON lpt.vmid = " << one_db::vm_monitor_table << ".vmid "
<< "AND lpt.last_poll = " << one_db::vm_monitor_table
<< ".last_poll INNER JOIN " << one_db::vm_table
<< " ON " << one_db::vm_monitor_table << ".vmid = oid";
cmd << " ORDER BY vmid, " << one_db::vm_monitor_table << ".last_poll;";
if ( !where.empty() )
{
cmd << " WHERE " << where;
}
cmd << " ORDER BY oid";
break;
case -1: //Get all monitoring
cmd << "SELECT " << one_db::vm_monitor_table << ".body FROM "
<< one_db::vm_monitor_table << " INNER JOIN " << one_db::vm_table
<< " ON vmid = oid";
if ( !where.empty() )
{
cmd << " WHERE " << where;
}
cmd << " ORDER BY vmid, " << one_db::vm_monitor_table << ".last_poll;";
break;
default: //Get monitor in last s seconds
cmd << "SELECT " << one_db::vm_monitor_table << ".body FROM "
<< one_db::vm_monitor_table << " INNER JOIN " << one_db::vm_table
<< " ON vmid = oid WHERE " << one_db::vm_monitor_table
<< ".last_poll > " << time(nullptr) - seconds;
if ( !where.empty() )
{
cmd << " ANS " << where;
}
cmd << " ORDER BY vmid, " << one_db::vm_monitor_table << ".last_poll;";
break;
}
return PoolSQL::dump(oss, "MONITORING_DATA", cmd);
}