diff --git a/src/oca/ruby/opennebula/host_pool.rb b/src/oca/ruby/opennebula/host_pool.rb index 8cf44c28ed..907ee92d3b 100644 --- a/src/oca/ruby/opennebula/host_pool.rb +++ b/src/oca/ruby/opennebula/host_pool.rb @@ -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) diff --git a/src/oca/ruby/opennebula/virtual_machine_pool.rb b/src/oca/ruby/opennebula/virtual_machine_pool.rb index c09bd66c66..8c7c6b0acc 100644 --- a/src/oca/ruby/opennebula/virtual_machine_pool.rb +++ b/src/oca/ruby/opennebula/virtual_machine_pool.rb @@ -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? diff --git a/src/rm/RequestManagerPoolInfoFilter.cc b/src/rm/RequestManagerPoolInfoFilter.cc index 0b9f5b590a..736fbc364b 100644 --- a/src/rm/RequestManagerPoolInfoFilter.cc +++ b/src/rm/RequestManagerPoolInfoFilter.cc @@ -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(); diff --git a/src/scheduler/include/MonitorXML.h b/src/scheduler/include/MonitorXML.h index cfa7451420..c98ce20ec3 100644 --- a/src/scheduler/include/MonitorXML.h +++ b/src/scheduler/include/MonitorXML.h @@ -94,7 +94,7 @@ protected: { try { - client->call("one.hostpool.monitoring", "i", &result, 1); + client->call("one.hostpool.monitoring", "i", &result, 0); return 0; }