diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index d0edcdb8fd..6b039ef09b 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -301,8 +301,9 @@ public: /** * Updates VM dynamic information (usage counters), and updates last_poll, * and copies it to history record for acct. + * @param update_db true if the VM table needs to be updated. */ - int update_info(const string& monitor_data); + int update_info(const string& monitor_data, bool& update_db); /** * Clears the VM monitor information usage counters (MEMORY, CPU), @@ -970,8 +971,9 @@ public: /** * Deletes the error message from the template (ERROR_MONITOR) * @param message Message string + * @return the number of ERROR_MONITOR attributes removed */ - void clear_template_monitor_error(); + int clear_template_monitor_error(); // ------------------------------------------------------------------------ // Timers & Requirements diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index 55ce0aaf16..a6ec1226c6 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -74,19 +74,16 @@ public: * * @param id VM id * @param monitor_str String returned by the poll driver call - * @param update_db write data to DB (or keep it in memory) */ - static void process_poll(int id, const string &monitor_str, bool update_db); + static void process_poll(int id, const string &monitor_str); /** * Updates the VM with the information gathered by the drivers * * @param vm VM to update, must be locked * @param monitor_str String returned by the poll driver call - * @param update_db write data to DB (or keep it in memory) */ - static void process_poll(VirtualMachine* vm, const string &monitor_str, - bool update_db); + static void process_poll(VirtualMachine* vm, const string &monitor_str); /** * Check if action is supported for imported VMs diff --git a/src/im/MonitorThread.cc b/src/im/MonitorThread.cc index 157741b5c5..db5f611b9d 100644 --- a/src/im/MonitorThread.cc +++ b/src/im/MonitorThread.cc @@ -282,7 +282,7 @@ void MonitorThread::do_message() continue; } - VirtualMachineManagerDriver::process_poll(vm, itm->second, true); + VirtualMachineManagerDriver::process_poll(vm, itm->second); vm->unlock(); } diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index 07976525e3..a6df129089 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -606,6 +606,8 @@ static void monitor_action(istringstream& is, int id, const string& result) { + static unsigned int tics = 10; + string dsinfo64; string *dsinfo = 0; @@ -690,6 +692,18 @@ static void monitor_action(istringstream& is, ds->unlock(); + oss << "Datastore " << ds_name << " (" << id << ") successfully monitored."; + + NebulaLog::log("ImM", Log::DEBUG, oss); + + //Process VM disk information every 10 monitor actions + if ( tics++ < 10 ) + { + return; + } + + tics = 0; + vector vm_disk_info; vector::iterator it; @@ -706,13 +720,9 @@ static void monitor_action(istringstream& is, continue; } - VirtualMachineManagerDriver::process_poll(vm_id, poll_info, false); + VirtualMachineManagerDriver::process_poll(vm_id, poll_info); } - oss << "Datastore " << ds_name << " (" << id << ") successfully monitored."; - - NebulaLog::log("ImM", Log::DEBUG, oss); - return; } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index c588171a46..af334a1115 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2179,13 +2179,15 @@ int VirtualMachine::from_xml(const string &xml_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachine::update_info(const string& monitor_data) +int VirtualMachine::update_info(const string& monitor_data, bool& update_db) { int rc; string error; ostringstream oss; + update_db = false; + last_poll = time(0); rc = monitoring.update(monitor_data, error); @@ -2201,12 +2203,14 @@ int VirtualMachine::update_info(const string& monitor_data) log("VMM", Log::ERROR, oss); + update_db = true; + return -1; } set_vm_info(); - clear_template_monitor_error(); + update_db = clear_template_monitor_error() > 0; oss << "VM " << oid << " successfully monitored: " << monitor_data; @@ -2340,9 +2344,9 @@ void VirtualMachine::set_template_monitor_error(const string& message) /* -------------------------------------------------------------------------- */ -void VirtualMachine::clear_template_monitor_error() +int VirtualMachine::clear_template_monitor_error() { - user_obj_template->erase("ERROR_MONITOR"); + return user_obj_template->erase("ERROR_MONITOR"); } /* -------------------------------------------------------------------------- */ diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 661200868f..2cd330e6ac 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -661,7 +661,7 @@ void VirtualMachineManagerDriver::protocol(const string& message) const string monitor_str; getline(is, monitor_str); - process_poll(vm, monitor_str, true); + process_poll(vm, monitor_str); } else { @@ -684,10 +684,7 @@ void VirtualMachineManagerDriver::protocol(const string& message) const /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineManagerDriver::process_poll( - int id, - const string &monitor_str, - bool update_db) +void VirtualMachineManagerDriver::process_poll(int id,const string& monitor_str) { // Get the VM from the pool VirtualMachine* vm = Nebula::instance().get_vmpool()->get(id,true); @@ -697,7 +694,7 @@ void VirtualMachineManagerDriver::process_poll( return; } - process_poll(vm, monitor_str, update_db); + process_poll(vm, monitor_str); vm->unlock(); } @@ -705,10 +702,8 @@ void VirtualMachineManagerDriver::process_poll( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineManagerDriver::process_poll( - VirtualMachine* vm, - const string& monitor_str, - bool update_db) +void VirtualMachineManagerDriver::process_poll(VirtualMachine* vm, + const string& monitor_str) { char state; @@ -723,17 +718,17 @@ void VirtualMachineManagerDriver::process_poll( if (vm->get_state() == VirtualMachine::ACTIVE) { - int rc = vm->update_info(monitor_str); + bool update_db; - if ( update_db ) + if (vm->update_info(monitor_str, update_db) == 0) { - if ( rc == 0) - { - vmpool->update_history(vm); + vmpool->update_history(vm); - vmpool->update_monitoring(vm); - } + vmpool->update_monitoring(vm); + } + if (update_db) + { vmpool->update(vm); }