1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

Merge branch 'feature-261'

This commit is contained in:
Ruben S. Montero 2010-06-28 17:19:16 +02:00
commit 1d54c60f45
8 changed files with 96 additions and 73 deletions

View File

@ -87,9 +87,10 @@ public:
* Get the 10 least monitored hosts
* @param discovered hosts, map to store the retrieved hosts hids and
* hostnames
* @param host_limit max. number of hosts to monitor at a time
* @return int 0 if success
*/
int discover(map<int, string> * discovered_hosts);
int discover(map<int, string> * discovered_hosts, int host_limit);
/**
* Allocates a given capacity to the host

View File

@ -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

View File

@ -7,7 +7,8 @@
#-------------------------------------------------------------------------------
# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization
#
# VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization
# VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization.
# (use 0 to disable VM monitoring).
#
# VM_DIR: Remote path to store the VM images, it should be shared between all
# the cluster nodes to perform live migrations. This variable is the default
@ -28,9 +29,9 @@
# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
#*******************************************************************************
HOST_MONITORING_INTERVAL = 60
HOST_MONITORING_INTERVAL = 600
VM_POLLING_INTERVAL = 60
VM_POLLING_INTERVAL = 600
#VM_DIR=/srv/cloud/one/var

View File

@ -39,7 +39,7 @@ Host::Host(
im_mad_name(_im_mad_name),
vmm_mad_name(_vmm_mad_name),
tm_mad_name(_tm_mad_name),
last_monitored(time(0)),
last_monitored(0),
host_template(id)
{};

View File

@ -70,7 +70,7 @@ int HostPool::discover_cb(void * _map, int num, char **values, char **names)
/* -------------------------------------------------------------------------- */
int HostPool::discover(map<int, string> * discovered_hosts)
int HostPool::discover(map<int, string> * discovered_hosts, int host_limit)
{
ostringstream sql;
int rc;
@ -80,7 +80,7 @@ int HostPool::discover(map<int, string> * discovered_hosts)
sql << "SELECT oid, im_mad FROM "
<< Host::table << " WHERE state != "
<< Host::DISABLED << " ORDER BY last_mon_time LIMIT 10";
<< Host::DISABLED << " ORDER BY last_mon_time ASC LIMIT " << host_limit;
rc = db->exec(sql,this);

View File

@ -32,11 +32,11 @@ extern "C" void * im_action_loop(void *arg)
NebulaLog::log("InM",Log::INFO,"Information Manager started.");
im = static_cast<InformationManager *>(arg);
im->am.loop(im->timer_period,0);
NebulaLog::log("InM",Log::INFO,"Information Manager stopped.");
return 0;
}
@ -50,30 +50,30 @@ void InformationManager::load_mads(int uid)
ostringstream oss;
const VectorAttribute * vattr;
int rc;
NebulaLog::log("InM",Log::INFO,"Loading Information Manager drivers.");
for(i=0;i<mad_conf.size();i++)
{
vattr = static_cast<const VectorAttribute *>(mad_conf[i]);
oss.str("");
oss << "\tLoading driver: " << vattr->vector_value("NAME");
NebulaLog::log("InM",Log::INFO,oss);
im_mad = new InformationManagerDriver(0,vattr->value(),false,hpool);
rc = add(im_mad);
if ( rc == 0 )
{
oss.str("");
oss.str("");
oss << "\tDriver " << vattr->vector_value("NAME") << " loaded";
NebulaLog::log("InM",Log::INFO,oss);
}
}
}
}
/* -------------------------------------------------------------------------- */
@ -92,7 +92,7 @@ int InformationManager::start()
}
NebulaLog::log("InM",Log::INFO,"Starting Information Manager...");
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
@ -113,14 +113,14 @@ void InformationManager::do_action(const string &action, void * arg)
else if (action == ACTION_FINALIZE)
{
NebulaLog::log("InM",Log::INFO,"Stopping Information Manager...");
MadManager::stop();
MadManager::stop();
}
else
{
ostringstream oss;
oss << "Unknown action name: " << action;
NebulaLog::log("InM", Log::ERROR, oss);
}
}
@ -131,19 +131,22 @@ void InformationManager::do_action(const string &action, void * arg)
void InformationManager::timer_action()
{
static int mark = 0;
int rc;
time_t thetime;
ostringstream oss;
map<int, string> discovered_hosts;
map<int, string>::iterator it;
const InformationManagerDriver * imd;
Host * host;
istringstream iss;
// -------------- Max. number of hosts to monitor. ---------------------
int host_limit = 10;
mark = mark + timer_period;
if ( mark >= 600 )
@ -152,7 +155,7 @@ void InformationManager::timer_action()
mark = 0;
}
rc = hpool->discover(&discovered_hosts);
rc = hpool->discover(&discovered_hosts, host_limit);
if ((rc != 0) || (discovered_hosts.empty() == true))
{
@ -160,55 +163,55 @@ void InformationManager::timer_action()
}
thetime = time(0);
for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++)
{
{
host = hpool->get(it->first,true);
if (host == 0)
{
continue;
}
Host::HostState state = host->get_state();
// TODO: Set apropriate threshold to timeout monitoring
if (( state == Host::MONITORING) &&
(thetime - host->get_last_monitored() >= 600))
{
host->set_state(Host::INIT);
hpool->update(host);
}
if ((state != Host::MONITORING) && (state != Host::DISABLED) &&
(thetime - host->get_last_monitored() >= monitor_period))
{
oss.str("");
oss << "Monitoring host " << host->get_hostname()
oss << "Monitoring host " << host->get_hostname()
<< " (" << it->first << ")";
NebulaLog::log("InM",Log::INFO,oss);
imd = get(it->second);
if (imd == 0)
{
oss.str("");
oss << "Could not find information driver " << it->second;
NebulaLog::log("InM",Log::ERROR,oss);
host->set_state(Host::ERROR);
host->set_state(Host::ERROR);
}
else
{
imd->monitor(it->first,host->get_hostname());
host->set_state(Host::MONITORING);
}
hpool->update(host);
}
host->unlock();
}
host->unlock();
}
}

View File

@ -213,14 +213,18 @@ 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
os << "last_poll <= " << last_poll << " and"
<< " state = " << VirtualMachine::ACTIVE
<< " and ( lcm_state = " << VirtualMachine::RUNNING
<< " or lcm_state = " << VirtualMachine::UNKNOWN << " )";
<< " or lcm_state = " << VirtualMachine::UNKNOWN << " )"
<< " ORDER BY last_poll ASC LIMIT " << vm_limit;
where = os.str();

View File

@ -60,7 +60,15 @@ extern "C" void * vmm_action_loop(void *arg)
NebulaLog::log("VMM",Log::INFO,"Virtual Machine Manager started.");
vmm->am.loop(vmm->timer_period,0);
if ( vmm->poll_period == 0 )
{
NebulaLog::log("VMM",Log::INFO,"VM monitoring is disabled.");
vmm->am.loop(0,0);
}
else
{
vmm->am.loop(vmm->timer_period,0);
}
NebulaLog::log("VMM",Log::INFO,"Virtual Machine Manager stopped.");
@ -804,11 +812,16 @@ void VirtualMachineManager::timer_action()
vector<int> oids;
vector<int>::iterator it;
int rc;
time_t thetime;
ostringstream os;
time_t thetime = time(0);
const VirtualMachineManagerDriver * vmd;
// -------------- Max. number of VMs to monitor. ---------------------
int vm_limit = 5;
mark = mark + timer_period;
if ( mark >= 600 )
@ -817,15 +830,14 @@ void VirtualMachineManager::timer_action()
mark = 0;
}
rc = vmpool->get_running(oids);
// Monitor only VMs that hasn't been monitored for 'poll_period' seconds.
rc = vmpool->get_running(oids, vm_limit, thetime - poll_period);
if ( rc != 0 || oids.empty() )
{
return;
}
thetime = time(0);
for ( it = oids.begin(); it != oids.end(); it++ )
{
vm = vmpool->get(*it,true);
@ -845,28 +857,25 @@ 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();
}
}