mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
feature #261: Added support for limiting the number of VMs processed per monitoring interval.
This commit is contained in:
parent
78ad7f7284
commit
37f8c0d4dc
@ -68,10 +68,15 @@ public:
|
||||
/**
|
||||
* Function to get the IDs of running VMs
|
||||
* @param oids a vector that contains the IDs
|
||||
* @param vm_limit Max. number of VMs returned
|
||||
* @param last_poll Return only VMs which last_poll is less than or equal
|
||||
* to this value.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int get_running(
|
||||
vector<int>& oids);
|
||||
vector<int>& oids,
|
||||
int vm_limit,
|
||||
time_t last_poll);
|
||||
|
||||
/**
|
||||
* Function to get the IDs of pending VMs
|
||||
|
@ -253,14 +253,22 @@ int VirtualMachinePool::allocate (
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::get_running(
|
||||
vector<int>& oids)
|
||||
vector<int>& oids,
|
||||
int vm_limit,
|
||||
time_t last_poll)
|
||||
{
|
||||
ostringstream os;
|
||||
string where;
|
||||
|
||||
os << "state = " << VirtualMachine::ACTIVE
|
||||
// Get all machines that have been monitored ( > 0 ),
|
||||
// but not recently ( <= last_poll ) and...
|
||||
os << "last_poll > 0 and last_poll <= " << last_poll << " and "
|
||||
// ... are running
|
||||
<< "state = " << VirtualMachine::ACTIVE
|
||||
<< " and ( lcm_state = " << VirtualMachine::RUNNING
|
||||
<< " or lcm_state = " << VirtualMachine::UNKNOWN << " )";
|
||||
<< " or lcm_state = " << VirtualMachine::UNKNOWN << " )"
|
||||
// order the results by last_poll, and return only the first 'vm_limit' rows
|
||||
<< " ORDER BY last_poll ASC LIMIT " << vm_limit;
|
||||
|
||||
where = os.str();
|
||||
|
||||
|
@ -805,6 +805,7 @@ void VirtualMachineManager::timer_action()
|
||||
vector<int>::iterator it;
|
||||
int rc;
|
||||
time_t thetime;
|
||||
time_t last_poll;
|
||||
ostringstream os;
|
||||
|
||||
const VirtualMachineManagerDriver * vmd;
|
||||
@ -817,14 +818,23 @@ void VirtualMachineManager::timer_action()
|
||||
mark = 0;
|
||||
}
|
||||
|
||||
rc = vmpool->get_running(oids);
|
||||
// TODO: Move this to oned.conf
|
||||
// Max. number of VMs to monitor.
|
||||
int vm_limit = 10;
|
||||
|
||||
thetime = time(0);
|
||||
|
||||
// Monitor only VMs that hasn't been monitored for 'poll_period' seconds.
|
||||
last_poll = thetime - poll_period;
|
||||
|
||||
rc = vmpool->get_running(oids, vm_limit, last_poll);
|
||||
|
||||
if ( rc != 0 || oids.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
thetime = time(0);
|
||||
|
||||
|
||||
for ( it = oids.begin(); it != oids.end(); it++ )
|
||||
{
|
||||
@ -845,28 +855,26 @@ void VirtualMachineManager::timer_action()
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( (thetime - vm->get_last_poll()) >= poll_period )
|
||||
os.str("");
|
||||
|
||||
os << "Monitoring VM " << *it << ".";
|
||||
NebulaLog::log("VMM", Log::INFO, os);
|
||||
|
||||
vm->set_last_poll(thetime);
|
||||
|
||||
vmd = get(vm->get_vmm_mad());
|
||||
|
||||
if ( vmd == 0 )
|
||||
{
|
||||
os.str("");
|
||||
|
||||
os << "Monitoring VM " << *it << ".";
|
||||
NebulaLog::log("VMM", Log::INFO, os);
|
||||
|
||||
vm->set_last_poll(thetime);
|
||||
|
||||
vmd = get(vm->get_vmm_mad());
|
||||
|
||||
if ( vmd == 0 )
|
||||
{
|
||||
vm->unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
vmd->poll(*it,vm->get_hostname(),vm->get_deploy_id());
|
||||
|
||||
vmpool->update(vm);
|
||||
vm->unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
vmd->poll(*it,vm->get_hostname(),vm->get_deploy_id());
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user