1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-06 12:58:18 +03:00

bug #766: New monitoring states for the Hosts

This commit is contained in:
Ruben S. Montero 2012-05-18 00:14:18 +02:00
parent 88d90c0f61
commit dabd5702a4
3 changed files with 54 additions and 23 deletions

View File

@ -37,11 +37,12 @@ public:
enum HostState
{
INIT = 0, /**< Initial state for enabled hosts. */
MONITORING = 1, /**< The host is being monitored. */
MONITORED = 2, /**< The host has been successfully monitored. */
ERROR = 3, /**< An error ocurrer while monitoring the host. */
DISABLED = 4 /**< The host is disabled won't be monitored. */
INIT = 0, /**< Initial state for enabled hosts. */
MONITORING_MONITORED = 1, /**< Monitoring the host (from monitored). */
MONITORED = 2, /**< The host has been successfully monitored. */
ERROR = 3, /**< An error ocurrer while monitoring the host. */
DISABLED = 4, /**< The host is disabled won't be monitored. */
MONITORING_ERROR = 5 /**< Monitoring the host (from error). */
};
/**
@ -68,6 +69,15 @@ public:
return state != DISABLED;
}
/**
* Check if the host is being monitored
* @return true if the host is enabled
*/
bool isMonitoring() const
{
return ((state == MONITORING_ERROR) || (state==MONITORING_MONITORED));
}
/**
* Updates the Host's last_monitored time stamp.
* @param success if the monitored action was successfully performed
@ -158,6 +168,21 @@ public:
this->state = state;
};
/**
* Sets the corresponding monitoring state based on the actual host state
*/
void set_monitoring_state()
{
if ( state == ERROR )
{
state = MONITORING_ERROR;
}
else if ( state == MONITORED )
{
state = MONITORING_MONITORED;
}
};
/**
* Retrives last time the host was monitored
* @return time_t last monitored time
@ -168,13 +193,10 @@ public:
};
// ------------------------------------------------------------------------
// Share functions
// Share functions. Returns the value associated with each host share
// metric
// ------------------------------------------------------------------------
/**
*
*
*/
int get_share_running_vms()
{
return host_share.running_vms;
@ -318,8 +340,8 @@ private:
string vnm_mad_name;
/**
* If Host State= MONITORED last time it got fully monitored or 1 Jan 1970
* Host State = MONITORING last time it got a signal to be monitored
* If Host State = MONITORED last time it got fully monitored or 1 Jan 1970
* Host State = MONITORING* last time it got a signal to be monitored
*/
time_t last_monitored;

View File

@ -121,6 +121,11 @@ private:
*/
friend void * im_action_loop(void *arg);
/**
* Time in seconds to expire a monitoring action (10 minutes)
*/
static const time_t monitor_expire;
/**
* Returns a pointer to a Information Manager MAD. The driver is
* searched by its name and owned by gwadmin with uid=0.

View File

@ -20,6 +20,9 @@
#include <sys/types.h>
#include <sys/stat.h>
const time_t InformationManager::monitor_expire = 600;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -136,9 +139,11 @@ void InformationManager::timer_action()
static int mark = 0;
int rc;
time_t thetime;
time_t now;
ostringstream oss;
struct stat sb;
map<int, string> discovered_hosts;
map<int, string>::iterator it;
@ -147,6 +152,8 @@ void InformationManager::timer_action()
Host * host;
istringstream iss;
time_t monitor_length;
mark = mark + timer_period;
if ( mark >= 600 )
@ -162,9 +169,7 @@ void InformationManager::timer_action()
return;
}
thetime = time(0);
struct stat sb;
now = time(0);
if (stat(remotes_location.c_str(), &sb) == -1)
{
@ -183,23 +188,22 @@ void InformationManager::timer_action()
continue;
}
Host::HostState state = host->get_state();
monitor_length = now - host->get_last_monitored();
// TODO: Set apropriate threshold to timeout monitoring
if (( state == Host::MONITORING) &&
(thetime - host->get_last_monitored() >= 600))
if (host->isMonitoring() && (monitor_length >= monitor_expire))
{
host->set_state(Host::INIT);
hpool->update(host);
}
if ((state != Host::MONITORING) && (state != Host::DISABLED) &&
(thetime - host->get_last_monitored() >= monitor_period))
if ( host->isEnabled() && !(host->isMonitoring()) &&
(monitor_length >= monitor_period))
{
oss.str("");
oss << "Monitoring host " << host->get_name()
<< " (" << it->first << ")";
NebulaLog::log("InM",Log::INFO,oss);
imd = get(it->second);
@ -224,7 +228,7 @@ void InformationManager::timer_action()
imd->monitor(it->first,host->get_name(),update_remotes);
host->set_state(Host::MONITORING);
host->set_monitoring_state();
}
hpool->update(host);