1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-20 10:50:08 +03:00

M #-: Make last monitor API call work with MySQL

This commit is contained in:
Ruben S. Montero 2020-06-04 19:30:19 +02:00
parent c41e987cd6
commit 085914fd6a
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
4 changed files with 41 additions and 24 deletions

View File

@ -99,8 +99,8 @@ module OpenNebula
# Retrieves the monitoring data for all the Hosts in the pool, in XML
#
# @param [Integer] num Optional number of monitoring records to be
# retrieved. If nill all records are retrieved
# @param [Integer] num Optional Retrieve monitor records in the last num
# seconds. 0 just the last record, -1 or nil all records
#
# @return [String] VM monitoring data, in XML
def monitoring_xml(num = nil)

View File

@ -199,8 +199,8 @@ module OpenNebula
#
# @param [Integer] filter_flag Optional filter flag to retrieve all or
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE.
# @param [Integer] num Optional number of monitoring records to be
# retrieved. If nill all records are retrieved
# @param [Integer] num Optional Retrieve monitor records in the last num
# seconds. 0 just the last record, -1 or nil all records
# @return [String] VM monitoring data, in XML
def monitoring_xml(filter_flag=INFO_ALL, num=nil)
return @client.call(VM_POOL_METHODS[:monitoring], filter_flag) if num.nil?

View File

@ -512,19 +512,27 @@ void VirtualMachinePoolMonitoring::request_execute(
if (paramList.size() > 2)
{
ostringstream oss;
int num_rows = xmlrpc_c::value_int(paramList.getInt(2));
int s = xmlrpc_c::value_int(paramList.getInt(2));
oss << one_db::vm_monitor_table << ".last_poll in "
<< "(select last_poll from " << one_db::vm_monitor_table << " as t "
<< "where t.vmid = " << one_db::vm_monitor_table << ".vmid "
<< "ORDER by last_poll DESC";
if (num_rows != -1)
switch (s)
{
oss << " LIMIT " << num_rows << ")";
}
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();
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;
}
}
where_filter(att, filter_flag, -1, -1, and_clause, "", false, false, false, where);
@ -718,17 +726,26 @@ void HostPoolMonitoring::request_execute(
if (paramList.size() > 1)
{
ostringstream oss;
int num_rows = xmlrpc_c::value_int(paramList.getInt(1));
int s = xmlrpc_c::value_int(paramList.getInt(1));
oss << one_db::host_monitor_table << ".last_mon_time in "
<< "(select last_mon_time "
<< "from " << one_db::host_monitor_table << " as t "
<< "where t.hid = " << one_db::host_monitor_table << ".hid "
<< "ORDER by last_mon_time DESC";
if (num_rows != -1)
switch (s)
{
oss << " LIMIT " << num_rows << ")";
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();

View File

@ -94,7 +94,7 @@ protected:
{
try
{
client->call("one.hostpool.monitoring", "i", &result, 1);
client->call("one.hostpool.monitoring", "i", &result, 0);
return 0;
}