mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
Feature #1279: Add one.host.monitoring and one.hostpool.monitoring methods, new host_monitoring table
This commit is contained in:
parent
bb4d39baf5
commit
14d30d826c
@ -113,6 +113,22 @@ public:
|
||||
**/
|
||||
int update_info(string &parse_str);
|
||||
|
||||
/**
|
||||
* Inserts the last monitoring, and deletes old monitoring entries.
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries.
|
||||
*
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int clean_monitoring(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Retrives host state
|
||||
* @return HostState code number
|
||||
@ -355,6 +371,12 @@ private:
|
||||
|
||||
static const char * table;
|
||||
|
||||
static const char * monit_db_names;
|
||||
|
||||
static const char * monit_db_bootstrap;
|
||||
|
||||
static const char * monit_table;
|
||||
|
||||
/**
|
||||
* Execute an INSERT or REPLACE Sql query.
|
||||
* @param db The SQL DB
|
||||
@ -370,9 +392,15 @@ private:
|
||||
*/
|
||||
static int bootstrap(SqlDB * db)
|
||||
{
|
||||
ostringstream oss_host(Host::db_bootstrap);
|
||||
int rc;
|
||||
|
||||
return db->exec(oss_host);
|
||||
ostringstream oss_host(Host::db_bootstrap);
|
||||
ostringstream oss_monit(Host::monit_db_bootstrap);
|
||||
|
||||
rc = db->exec(oss_host);
|
||||
rc += db->exec(oss_monit);
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -197,6 +197,55 @@ public:
|
||||
return PoolSQL::search(oids, Host::table, where);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumps the host monitoring information entries in XML format. A filter
|
||||
* can be also added to the query.
|
||||
*
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_monitoring(ostringstream& oss,
|
||||
const string& where);
|
||||
|
||||
/**
|
||||
* Inserts the last monitoring, and deletes old monitoring entries for this
|
||||
* host
|
||||
*
|
||||
* @param host pointer to the host object
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_monitoring(Host * host)
|
||||
{
|
||||
if ( _host_monitoring_history <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return host->update_monitoring(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for this host
|
||||
*
|
||||
* @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 const int& host_monitoring_history()
|
||||
{
|
||||
return _host_monitoring_history;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
@ -217,6 +266,11 @@ private:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int discover_cb(void * _map, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Size, in seconds, of the historical monitoring information
|
||||
*/
|
||||
static int _host_monitoring_history;
|
||||
};
|
||||
|
||||
#endif /*HOST_POOL_H_*/
|
||||
|
@ -68,6 +68,26 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostMonitoring : public RequestManagerHost
|
||||
{
|
||||
public:
|
||||
HostMonitoring():
|
||||
RequestManagerHost("HostMonitoring",
|
||||
"Returns the host monitoring records",
|
||||
"A:si")
|
||||
{
|
||||
auth_op = AuthRequest::USE;
|
||||
};
|
||||
|
||||
~HostMonitoring(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -238,6 +238,31 @@ public:
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostPoolMonitoring : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
||||
HostPoolMonitoring():
|
||||
RequestManagerPoolInfoFilter("HostPoolMonitoring",
|
||||
"Returns the host monitoring records",
|
||||
"A:s")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = PoolObjectSQL::HOST;
|
||||
};
|
||||
|
||||
~HostPoolMonitoring(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupPoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
@ -147,7 +147,6 @@ public:
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @return 0 on success
|
||||
*/
|
||||
|
||||
int clean_monitoring(
|
||||
VirtualMachine * vm)
|
||||
{
|
||||
|
@ -69,6 +69,14 @@ const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
|
||||
"last_mon_time INTEGER, uid INTEGER, gid INTEGER, owner_u INTEGER, "
|
||||
"group_u INTEGER, other_u INTEGER, UNIQUE(name))";
|
||||
|
||||
|
||||
const char * Host::monit_table = "host_monitoring";
|
||||
|
||||
const char * Host::monit_db_names = "hid, last_mon_time, body";
|
||||
|
||||
const char * Host::monit_db_bootstrap = "CREATE TABLE IF NOT EXISTS "
|
||||
"host_monitoring (hid INTEGER, last_mon_time INTEGER, body TEXT, "
|
||||
"PRIMARY KEY(hid, last_mon_time))";
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@ -153,7 +161,7 @@ error_hostname:
|
||||
goto error_generic;
|
||||
|
||||
error_generic:
|
||||
error_str = "Error inserting Group in DB.";
|
||||
error_str = "Error inserting Host in DB.";
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
@ -188,6 +196,83 @@ int Host::update_info(string &parse_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::update_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
string xml_body;
|
||||
string error_str;
|
||||
char * sql_xml;
|
||||
|
||||
sql_xml = db->escape_str(to_xml(xml_body).c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
{
|
||||
goto error_body;
|
||||
}
|
||||
|
||||
if ( validate_xml(sql_xml) != 0 )
|
||||
{
|
||||
goto error_xml;
|
||||
}
|
||||
|
||||
oss << "DELETE FROM " << monit_table
|
||||
<< " WHERE hid=" << oid
|
||||
<< " AND last_mon_time < (" << last_monitored
|
||||
<< " - " << HostPool::host_monitoring_history() << ")";
|
||||
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << monit_table << " ("<< monit_db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< last_monitored << ","
|
||||
<< "'" << sql_xml << "')";
|
||||
|
||||
db->free_str(sql_xml);
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
|
||||
error_xml:
|
||||
db->free_str(sql_xml);
|
||||
|
||||
error_str = "could not transform the Host to XML.";
|
||||
|
||||
goto error_common;
|
||||
|
||||
error_body:
|
||||
error_str = "could not insert the Host in the DB.";
|
||||
|
||||
error_common:
|
||||
oss.str("");
|
||||
oss << "Error updating Host monitoring information, " << error_str;
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR, oss);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
@ -29,11 +29,16 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::_host_monitoring_history;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
HostPool::HostPool(SqlDB* db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
int host_monitoring_history) // TODO
|
||||
int host_monitoring_history)
|
||||
: PoolSQL(db, Host::table, true)
|
||||
{
|
||||
// ------------------ Initialize Hooks for the pool ----------------------
|
||||
@ -143,6 +148,8 @@ HostPool::HostPool(SqlDB* db,
|
||||
|
||||
add_hook(hook);
|
||||
}
|
||||
|
||||
_host_monitoring_history = host_monitoring_history;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -290,3 +297,26 @@ int HostPool::discover(map<int, string> * discovered_hosts, int host_limit)
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::dump_monitoring(
|
||||
ostringstream& oss,
|
||||
const string& where)
|
||||
{
|
||||
ostringstream cmd;
|
||||
|
||||
cmd << "SELECT " << Host::monit_table << ".body FROM " << Host::monit_table
|
||||
<< " INNER JOIN " << Host::table
|
||||
<< " WHERE hid = oid";
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
cmd << " AND " << where;
|
||||
}
|
||||
|
||||
cmd << " ORDER BY hid, " << Host::monit_table << ".last_mon_time;";
|
||||
|
||||
return PoolSQL::dump(oss, "MONITORING_DATA", cmd);
|
||||
}
|
||||
|
@ -128,6 +128,7 @@ void InformationManagerDriver::protocol(
|
||||
host->touch(true);
|
||||
|
||||
hpool->update(host);
|
||||
hpool->update_monitoring(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
|
@ -306,6 +306,8 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
// Host Methods
|
||||
xmlrpc_c::methodPtr host_enable(new HostEnable());
|
||||
xmlrpc_c::methodPtr host_monitoring(new HostMonitoring());
|
||||
xmlrpc_c::methodPtr host_pool_monitoring(new HostPoolMonitoring());
|
||||
|
||||
// Image Methods
|
||||
xmlrpc_c::methodPtr image_persistent(new ImagePersistent());
|
||||
@ -373,8 +375,10 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.host.allocate", host_allocate);
|
||||
RequestManagerRegistry.addMethod("one.host.delete", host_delete);
|
||||
RequestManagerRegistry.addMethod("one.host.info", host_info);
|
||||
RequestManagerRegistry.addMethod("one.host.monitoring", host_monitoring);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info);
|
||||
RequestManagerRegistry.addMethod("one.hostpool.monitoring", host_pool_monitoring);
|
||||
|
||||
/* Group related methods */
|
||||
RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
|
||||
|
@ -67,3 +67,40 @@ void HostEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HostMonitoring::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
oss << "oid = " << id;
|
||||
|
||||
where = oss.str();
|
||||
|
||||
oss.str("");
|
||||
|
||||
rc = (static_cast<HostPool *>(pool))->dump_monitoring(oss, where);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -163,6 +163,7 @@ void VirtualMachinePoolMonitoring::request_execute(
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@ -176,6 +177,32 @@ void HostPoolInfo::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void HostPoolMonitoring::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
where_filter(att, ALL, -1, -1, "", "", where);
|
||||
|
||||
rc = (static_cast<HostPool *>(pool))->dump_monitoring(oss, where);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void GroupPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
|
Loading…
Reference in New Issue
Block a user