diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index ca5ab6d405..8d56e8df3e 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -37,7 +37,7 @@ public: const string& hook_location, const string& remotes_location, vector& restricted_attrs, - int vm_monitoring_history); + time_t monitor_expiration); ~VirtualMachinePool(){}; @@ -133,7 +133,7 @@ public: int update_monitoring( VirtualMachine * vm) { - if ( _vm_monitoring_history <= 0 ) + if ( _monitor_expiration <= 0 ) { return 0; } @@ -201,13 +201,31 @@ public: int dump_monitoring(ostringstream& oss, const string& where); + /** + * Dumps the VM monitoring information for a single VM + * + * @param oss the output stream to dump the pool contents + * @param vmid id of the target VM + * + * @return 0 on success + */ + int dump_monitoring(ostringstream& oss, + int vmid) + { + ostringstream filter; + + filter << "oid = " << vmid; + + return dump_monitoring(oss, filter.str()); + } + /** * Get the size, in seconds, of the historical monitoring information * @return the seconds */ - static const int& vm_monitoring_history() + static time_t monitor_expiration() { - return _vm_monitoring_history; + return _monitor_expiration; }; private: @@ -223,7 +241,7 @@ private: /** * Size, in seconds, of the historical monitoring information */ - static int _vm_monitoring_history; + static time_t _monitor_expiration; }; #endif /*VIRTUAL_MACHINE_POOL_H_*/ diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 96abd83559..2edc71c8f4 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -11,14 +11,14 @@ # # HOST_MONITORING_INTERVAL: Time in seconds between host monitorization. # HOST_PER_INTERVAL: Number of hosts monitored in each interval. -# HOST_MONITORING_HISTORY: Size, in seconds, of the historical monitoring -# information. (use 0 to disable host monitoring history). +# HOST_MONITORING_EXPIRATION_TIME: Time, in seconds, to expire monitoring +# information. Use 0 to disable HOST monitoring recording. # # VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization. -# (use 0 to disable VM monitoring). +# Use 0 to disable VM monitoring. # VM_PER_INTERVAL: Number of VMs monitored in each interval. -# VM_MONITORING_HISTORY: Size, in seconds, of the historical monitoring -# information. (use 0 to disable VM monitoring history). +# VM_MONITORING_EXPIRATION_TIME: Time, in seconds, to expire monitoring +# information. Use 0 to disable VM monitoring recording. # # SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management # scripts. @@ -42,13 +42,13 @@ #MANAGER_TIMER = 30 -HOST_MONITORING_INTERVAL = 600 -#HOST_PER_INTERVAL = 15 -HOST_MONITORING_HISTORY = 86400 +HOST_MONITORING_INTERVAL = 600 +#HOST_PER_INTERVAL = 15 +#HOST_MONITORING_EXPIRATION_TIME = 86400 -VM_POLLING_INTERVAL = 600 -#VM_PER_INTERVAL = 5 -VM_MONITORING_HISTORY = 86400 +VM_POLLING_INTERVAL = 600 +#VM_PER_INTERVAL = 5 +#VM_MONITORING_EXPIRATION_TIME = 86400 SCRIPTS_REMOTE_DIR=/var/tmp/one diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index af9f568121..811c8fce9a 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -263,13 +263,15 @@ void Nebula::start() try { - int vm_monitoring_history; - int host_monitoring_history; - string mac_prefix; int size; + + string mac_prefix; string default_image_type; string default_device_prefix; + time_t expiration_time; + time_t vm_expiration; + time_t host_expiration; vector vm_hooks; vector host_hooks; @@ -284,21 +286,20 @@ void Nebula::start() nebula_configuration->get("VM_RESTRICTED_ATTR", vm_restricted_attrs); nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs); - nebula_configuration->get("VM_MONITORING_HISTORY",vm_monitoring_history); - nebula_configuration->get("HOST_MONITORING_HISTORY",host_monitoring_history); + nebula_configuration->get("VM_MONITORING_EXPIRATION_TIME",vm_expiration); + nebula_configuration->get("HOST_MONITORING_EXPIRATION_TIME",host_expiration); vmpool = new VirtualMachinePool(db, vm_hooks, hook_location, remotes_location, vm_restricted_attrs, - vm_monitoring_history); - + vm_expiration); hpool = new HostPool( db, host_hooks, hook_location, remotes_location, - host_monitoring_history); + host_expiration); nebula_configuration->get("MAC_PREFIX", mac_prefix); nebula_configuration->get("NETWORK_SIZE", size); diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 4888eb4668..7a86acdda2 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -90,10 +90,10 @@ void OpenNebulaTemplate::set_conf_default() #------------------------------------------------------------------------------- # HOST_MONITORING_INTERVAL # HOST_PER_INTERVAL -# HOST_MONITORING_HISTORY +# HOST_MONITORING_EXPIRATION_TIME # VM_POLLING_INTERVAL # VM_PER_INTERVAL -# VM_MONITORING_HISTORY +# VM_MONITORING_EXPIRATION_TIME # PORT # DB # VNC_BASE_PORT @@ -112,10 +112,10 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("HOST_PER_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); - // HOST_MONITORING_HISTORY + // HOST_MONITORING_EXPIRATION_TIME value = "86400"; - attribute = new SingleAttribute("HOST_MONITORING_HISTORY",value); + attribute = new SingleAttribute("HOST_MONITORING_EXPIRATION_TIME",value); conf_default.insert(make_pair(attribute->name(),attribute)); // POLL_INTERVAL @@ -130,10 +130,10 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("VM_PER_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); - // VM_MONITORING_HISTORY + // VM_MONITORING_EXPIRATION_TIME value = "86400"; - attribute = new SingleAttribute("VM_MONITORING_HISTORY",value); + attribute = new SingleAttribute("VM_MONITORING_EXPIRATION_TIME",value); conf_default.insert(make_pair(attribute->name(),attribute)); //XML-RPC Server PORT diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index a56a33f993..0eda165c65 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -581,11 +581,10 @@ void VirtualMachineMonitoring::request_execute( xmlrpc_c::paramList const& paramList, RequestAttributes& att) { - int id = xmlrpc_c::value_int(paramList.getInt(1)); + int id = xmlrpc_c::value_int(paramList.getInt(1)); + int rc; - ostringstream oss; - string where; - int rc; + ostringstream oss; bool auth = vm_authorization(id, 0, att, 0, 0, auth_op); @@ -594,13 +593,7 @@ void VirtualMachineMonitoring::request_execute( return; } - oss << "oid = " << id; - - where = oss.str(); - - oss.str(""); - - rc = (static_cast(pool))->dump_monitoring(oss, where); + rc = (static_cast(pool))->dump_monitoring(oss, id); if ( rc != 0 ) { diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 14bf931a43..ed775328ef 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -744,6 +744,7 @@ int VirtualMachine::update_monitoring(SqlDB * db) string xml_body; string error_str; char * sql_xml; + time_t max_last_poll; sql_xml = db->escape_str(to_xml(xml_body).c_str()); @@ -757,10 +758,11 @@ int VirtualMachine::update_monitoring(SqlDB * db) goto error_xml; } + max_last_poll = last_poll - VirtualMachinePool::monitor_expiration(); + oss << "DELETE FROM " << monit_table - << " WHERE vmid=" << oid - << " AND last_poll < (" << last_poll - << " - " << VirtualMachinePool::vm_monitoring_history() << ")"; + << " WHERE vmid = " << oid + << " AND last_poll < " << max_last_poll; db->exec(oss); diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 9a89fd211a..567fca0c0c 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -24,7 +24,7 @@ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachinePool::_vm_monitoring_history; +time_t VirtualMachinePool::_monitor_expiration; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -35,7 +35,7 @@ VirtualMachinePool::VirtualMachinePool( const string& hook_location, const string& remotes_location, vector& restricted_attrs, - int vm_monitoring_history) + time_t expire_time) : PoolSQL(db, VirtualMachine::table, false) { const VectorAttribute * vattr; @@ -49,6 +49,8 @@ VirtualMachinePool::VirtualMachinePool( bool state_hook = false; + _monitor_expiration = expire_time; + for (unsigned int i = 0 ; i < hook_mads.size() ; i++ ) { vattr = static_cast(hook_mads[i]); @@ -193,8 +195,6 @@ VirtualMachinePool::VirtualMachinePool( // Set restricted attributes VirtualMachineTemplate::set_restricted_attributes(restricted_attrs); - - _vm_monitoring_history = vm_monitoring_history; } /* -------------------------------------------------------------------------- */