From 9f9057dd797436fa5f5eee25cc3e39d104f2b020 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 2 Nov 2013 18:25:10 +0100 Subject: [PATCH] Wait poll_period since the VM started to run to proactively monitor a VM --- include/VirtualMachine.h | 8 ++++++++ src/vmm/VirtualMachineManager.cc | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 10e2e13a2b..cd93408c2e 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -750,6 +750,14 @@ public: history->running_stime=_stime; }; + /** + * Gets the running start time for the VM + */ + time_t get_running_stime() + { + return history->running_stime; + } + /** * Sets end time of VM running state. * @param _etime time when the running state finished diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 99832cd3ea..42a4d4cb99 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -1456,14 +1456,13 @@ error_common: void VirtualMachineManager::timer_action() { - static int mark = 0; - static int timer_start = time(0); + static int mark = 0; - VirtualMachine * vm; - vector oids; - vector::iterator it; - int rc; - ostringstream os; + VirtualMachine * vm; + vector oids; + vector::iterator it; + int rc; + ostringstream os; time_t thetime = time(0); @@ -1483,13 +1482,6 @@ void VirtualMachineManager::timer_action() // Clear the expired monitoring records vmpool->clean_expired_monitoring(); - // Skip monitoring the first poll_period to allow the Host monitoring to - // gather the VM info - if ( timer_start + poll_period > thetime ) - { - return; - } - // Monitor only VMs that hasn't been monitored for 'poll_period' seconds. rc = vmpool->get_running(oids, vm_limit, thetime - poll_period); @@ -1517,6 +1509,14 @@ void VirtualMachineManager::timer_action() continue; } + // Skip monitoring the first poll_period to allow the Host monitoring to + // gather the VM info + if (vm->get_running_stime() + poll_period > thetime) + { + vm->unlock(); + continue; + } + os.str(""); os << "Monitoring VM " << *it << ".";