mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-08 21:17:43 +03:00
Feature #1279: Clean expired monitoring records in timer_action.
This saves a lot of calls to the DB, and also cleans old entries for objects that are not monitored (VM in suspend/stop state, or hosts in disabled state).
This commit is contained in:
parent
8b46745a8a
commit
2071d62b39
@ -121,14 +121,6 @@ public:
|
||||
*/
|
||||
int update_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for this Host
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Retrives host state
|
||||
* @return HostState code number
|
||||
@ -423,14 +415,6 @@ private:
|
||||
string error_str;
|
||||
return insert_replace(db, true, error_str);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for all Hosts
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int clean_all_monitoring(SqlDB * db);
|
||||
};
|
||||
|
||||
#endif /*HOST_H_*/
|
||||
|
@ -168,8 +168,6 @@ public:
|
||||
return -1;
|
||||
}
|
||||
|
||||
clean_monitoring(host);
|
||||
|
||||
return PoolSQL::drop(objsql, error_msg);
|
||||
};
|
||||
|
||||
@ -247,24 +245,11 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for this host
|
||||
* Deletes the expired monitoring entries for all hosts
|
||||
*
|
||||
* @param host pointer to the virtual machine object
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring(Host * host)
|
||||
{
|
||||
return host->clean_monitoring(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the size, in seconds, of the historical monitoring information
|
||||
* @return the seconds
|
||||
*/
|
||||
static time_t monitor_expiration()
|
||||
{
|
||||
return _monitor_expiration;
|
||||
};
|
||||
int clean_expired_monitoring();
|
||||
|
||||
private:
|
||||
|
||||
@ -292,10 +277,7 @@ private:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring()
|
||||
{
|
||||
return Host::clean_all_monitoring(db);
|
||||
};
|
||||
int clean_all_monitoring();
|
||||
|
||||
/**
|
||||
* Size, in seconds, of the historical monitoring information
|
||||
|
@ -905,22 +905,6 @@ private:
|
||||
*/
|
||||
int update_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries.
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for all VMs
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int clean_all_monitoring(SqlDB * db);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Attribute Parser
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -139,29 +139,21 @@ public:
|
||||
}
|
||||
|
||||
return vm->update_monitoring(db);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for this VM
|
||||
* Deletes the expired monitoring entries for all VMs
|
||||
*
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring(
|
||||
VirtualMachine * vm)
|
||||
{
|
||||
return vm->clean_monitoring(db);
|
||||
};
|
||||
int clean_expired_monitoring();
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for all VMs
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring()
|
||||
{
|
||||
return VirtualMachine::clean_all_monitoring(db);
|
||||
};
|
||||
int clean_all_monitoring();
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualMachine pool
|
||||
@ -229,15 +221,6 @@ public:
|
||||
return dump_monitoring(oss, filter.str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size, in seconds, of the historical monitoring information
|
||||
* @return the seconds
|
||||
*/
|
||||
static time_t monitor_expiration()
|
||||
{
|
||||
return _monitor_expiration;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* Factory method to produce VM objects
|
||||
|
@ -668,8 +668,6 @@ int DispatchManager::finalize(
|
||||
vm->set_state(VirtualMachine::DONE);
|
||||
vmpool->update(vm);
|
||||
|
||||
vmpool->clean_monitoring(vm);
|
||||
|
||||
vm->log("DiM", Log::INFO, "New VM state is DONE.");
|
||||
break;
|
||||
|
||||
|
@ -125,8 +125,6 @@ void DispatchManager::done_action(int vid)
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vmpool->clean_monitoring(vm);
|
||||
|
||||
vm->log("DiM", Log::INFO, "New VM state is DONE");
|
||||
|
||||
vm->release_network_leases();
|
||||
|
@ -208,8 +208,6 @@ int Host::update_monitoring(SqlDB * db)
|
||||
string error_str;
|
||||
char * sql_xml;
|
||||
|
||||
time_t max_mon_time;
|
||||
|
||||
sql_xml = db->escape_str(to_xml(xml_body).c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
@ -222,15 +220,6 @@ int Host::update_monitoring(SqlDB * db)
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
max_mon_time = last_monitored - HostPool::monitor_expiration();
|
||||
|
||||
oss << "DELETE FROM " << monit_table
|
||||
<< " WHERE hid=" << oid
|
||||
<< " AND last_mon_time < " << max_mon_time;
|
||||
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << monit_table << " ("<< monit_db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< last_monitored << ","
|
||||
@ -261,36 +250,6 @@ error_common:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::clean_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << monit_table << " WHERE hid=" << oid;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::clean_all_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << monit_table;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
@ -46,7 +46,7 @@ HostPool::HostPool(SqlDB* db,
|
||||
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
clean_monitoring();
|
||||
clean_all_monitoring();
|
||||
}
|
||||
|
||||
// ------------------ Initialize Hooks for the pool ----------------------
|
||||
@ -326,3 +326,42 @@ int HostPool::dump_monitoring(
|
||||
|
||||
return PoolSQL::dump(oss, "MONITORING_DATA", cmd);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::clean_expired_monitoring()
|
||||
{
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rc;
|
||||
time_t max_mon_time;
|
||||
ostringstream oss;
|
||||
|
||||
max_mon_time = time(0) - _monitor_expiration;
|
||||
|
||||
oss << "DELETE FROM " << Host::monit_table
|
||||
<< " WHERE last_mon_time < " << max_mon_time;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::clean_all_monitoring()
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << Host::monit_table;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -155,6 +155,9 @@ void InformationManager::timer_action()
|
||||
mark = 0;
|
||||
}
|
||||
|
||||
// Clear the expired monitoring records
|
||||
hpool->clean_expired_monitoring();
|
||||
|
||||
rc = hpool->discover(&discovered_hosts, host_limit);
|
||||
|
||||
if ((rc != 0) || (discovered_hosts.empty() == true))
|
||||
|
@ -729,7 +729,6 @@ int VirtualMachine::update_monitoring(SqlDB * db)
|
||||
string xml_body;
|
||||
string error_str;
|
||||
char * sql_xml;
|
||||
time_t max_last_poll;
|
||||
|
||||
sql_xml = db->escape_str(to_xml(xml_body).c_str());
|
||||
|
||||
@ -743,15 +742,6 @@ int VirtualMachine::update_monitoring(SqlDB * db)
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
max_last_poll = last_poll - VirtualMachinePool::monitor_expiration();
|
||||
|
||||
oss << "DELETE FROM " << monit_table
|
||||
<< " WHERE vmid = " << oid
|
||||
<< " AND last_poll < " << max_last_poll;
|
||||
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << monit_table << " ("<< monit_db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< last_poll << ","
|
||||
@ -785,36 +775,6 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::clean_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << monit_table << " WHERE vmid=" << oid;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::clean_all_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << monit_table;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::add_history(
|
||||
int hid,
|
||||
const string& hostname,
|
||||
|
@ -53,7 +53,7 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
clean_monitoring();
|
||||
clean_all_monitoring();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0 ; i < hook_mads.size() ; i++ )
|
||||
@ -318,6 +318,45 @@ int VirtualMachinePool::dump_acct(ostringstream& oss,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::clean_expired_monitoring()
|
||||
{
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
time_t max_last_poll;
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
max_last_poll = time(0) - _monitor_expiration;
|
||||
|
||||
oss << "DELETE FROM " << VirtualMachine::monit_table
|
||||
<< " WHERE last_poll < " << max_last_poll;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::clean_all_monitoring()
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << VirtualMachine::monit_table;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::dump_monitoring(
|
||||
ostringstream& oss,
|
||||
const string& where)
|
||||
|
@ -1105,6 +1105,9 @@ void VirtualMachineManager::timer_action()
|
||||
mark = 0;
|
||||
}
|
||||
|
||||
// Clear the expired monitoring records
|
||||
vmpool->clean_expired_monitoring();
|
||||
|
||||
// Monitor only VMs that hasn't been monitored for 'poll_period' seconds.
|
||||
rc = vmpool->get_running(oids, vm_limit, thetime - poll_period);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user