mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-06 12:58:18 +03:00
Feature #1279: Add one.vm.monitoring and one.vmpool.monitoring
methods, new vm_monitoring table
This commit is contained in:
parent
ed0a502dc4
commit
bb4d39baf5
@ -38,7 +38,8 @@ public:
|
||||
HostPool(SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location);
|
||||
const string& remotes_location,
|
||||
int host_monitoring_history);
|
||||
|
||||
~HostPool(){};
|
||||
|
||||
|
@ -132,6 +132,31 @@ public:
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachinePoolMonitoring : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachinePoolMonitoring():
|
||||
RequestManagerPoolInfoFilter("VirtualMachinePoolMonitoring",
|
||||
"Returns the virtual machine monitoring records",
|
||||
"A:si")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = PoolObjectSQL::VM;
|
||||
};
|
||||
|
||||
~VirtualMachinePoolMonitoring(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplatePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
@ -143,6 +143,29 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineMonitoring : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachineMonitoring():
|
||||
RequestManagerVirtualMachine("VirtualMachineMonitoring",
|
||||
"Returns the virtual machine monitoring records",
|
||||
"A:si")
|
||||
{
|
||||
auth_op = AuthRequest::USE;
|
||||
};
|
||||
|
||||
~VirtualMachineMonitoring(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -838,9 +838,11 @@ private:
|
||||
int rc;
|
||||
|
||||
ostringstream oss_vm(VirtualMachine::db_bootstrap);
|
||||
ostringstream oss_monit(VirtualMachine::monit_db_bootstrap);
|
||||
ostringstream oss_hist(History::db_bootstrap);
|
||||
|
||||
rc = db->exec(oss_vm);
|
||||
rc += db->exec(oss_monit);
|
||||
rc += db->exec(oss_hist);
|
||||
|
||||
return rc;
|
||||
@ -895,6 +897,22 @@ private:
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Attribute Parser
|
||||
// -------------------------------------------------------------------------
|
||||
@ -971,6 +989,12 @@ protected:
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
||||
static const char * monit_table;
|
||||
|
||||
static const char * monit_db_names;
|
||||
|
||||
static const char * monit_db_bootstrap;
|
||||
|
||||
/**
|
||||
* Reads the Virtual Machine (identified with its OID) from the database.
|
||||
* @param db pointer to the db
|
||||
|
@ -32,11 +32,12 @@ class VirtualMachinePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachinePool(SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs);
|
||||
VirtualMachinePool(SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
int vm_monitoring_history);
|
||||
|
||||
~VirtualMachinePool(){};
|
||||
|
||||
@ -122,6 +123,37 @@ public:
|
||||
return vm->update_previous_history(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the last monitoring, and deletes old monitoring entries for this
|
||||
* VM
|
||||
*
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_monitoring(
|
||||
VirtualMachine * vm)
|
||||
{
|
||||
if ( _vm_monitoring_history <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return vm->update_monitoring(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all monitoring entries for this VM
|
||||
*
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @return 0 on success
|
||||
*/
|
||||
|
||||
int clean_monitoring(
|
||||
VirtualMachine * vm)
|
||||
{
|
||||
return vm->clean_monitoring(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualMachine pool
|
||||
* @return 0 on success
|
||||
@ -157,6 +189,28 @@ public:
|
||||
const string& where,
|
||||
int time_start,
|
||||
int time_end);
|
||||
|
||||
/**
|
||||
* Dumps the VM 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);
|
||||
|
||||
/**
|
||||
* Get the size, in seconds, of the historical monitoring information
|
||||
* @return the seconds
|
||||
*/
|
||||
static const int& vm_monitoring_history()
|
||||
{
|
||||
return _vm_monitoring_history;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* Factory method to produce VM objects
|
||||
@ -166,6 +220,11 @@ private:
|
||||
{
|
||||
return new VirtualMachine(-1,-1,-1,"","",0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Size, in seconds, of the historical monitoring information
|
||||
*/
|
||||
static int _vm_monitoring_history;
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_MACHINE_POOL_H_*/
|
||||
|
@ -11,10 +11,14 @@
|
||||
#
|
||||
# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization.
|
||||
# HOST_PER_INTERVAL: Number of hosts monitored in each interval.
|
||||
# HOST_MONITORING_HISTORY: Size, in seconds, of the historical monitoring
|
||||
# information. (use 0 to disable host monitoring history).
|
||||
#
|
||||
# VM_POLLING_INTERVAL: Time in seconds between virtual machine monitorization.
|
||||
# (use 0 to disable VM monitoring).
|
||||
# VM_PER_INTERVAL: Number of VMs monitored in each interval.
|
||||
# VM_MONITORING_HISTORY: Size, in seconds, of the historical monitoring
|
||||
# information. (use 0 to disable VM monitoring history).
|
||||
#
|
||||
# SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management
|
||||
# scripts.
|
||||
@ -40,10 +44,11 @@
|
||||
|
||||
HOST_MONITORING_INTERVAL = 600
|
||||
#HOST_PER_INTERVAL = 15
|
||||
HOST_MONITORING_HISTORY = 86400
|
||||
|
||||
VM_POLLING_INTERVAL = 600
|
||||
#VM_PER_INTERVAL = 5
|
||||
|
||||
VM_MONITORING_HISTORY = 86400
|
||||
|
||||
SCRIPTS_REMOTE_DIR=/var/tmp/one
|
||||
|
||||
|
@ -668,6 +668,8 @@ 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,6 +125,8 @@ 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();
|
||||
|
@ -32,7 +32,8 @@
|
||||
HostPool::HostPool(SqlDB* db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location)
|
||||
const string& remotes_location,
|
||||
int host_monitoring_history) // TODO
|
||||
: PoolSQL(db, Host::table, true)
|
||||
{
|
||||
// ------------------ Initialize Hooks for the pool ----------------------
|
||||
|
@ -155,7 +155,7 @@ protected:
|
||||
{
|
||||
vector<const Attribute *> hook;
|
||||
|
||||
return new HostPool(db,hook,"./", "./");
|
||||
return new HostPool(db,hook,"./", "./", 0);
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
host_hooks.push_back(hook);
|
||||
|
||||
|
||||
return new HostPool(db, host_hooks, hook_location, var_location);
|
||||
return new HostPool(db, host_hooks, hook_location, var_location, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -263,6 +263,8 @@ void Nebula::start()
|
||||
|
||||
try
|
||||
{
|
||||
int vm_monitoring_history;
|
||||
int host_monitoring_history;
|
||||
string mac_prefix;
|
||||
int size;
|
||||
string default_image_type;
|
||||
@ -282,12 +284,21 @@ void Nebula::start()
|
||||
nebula_configuration->get("VM_RESTRICTED_ATTR", vm_restricted_attrs);
|
||||
nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs);
|
||||
|
||||
nebula_configuration->get("VM_MONITORING_HISTORY",vm_monitoring_history);
|
||||
nebula_configuration->get("HOST_MONITORING_HISTORY",host_monitoring_history);
|
||||
|
||||
vmpool = new VirtualMachinePool(db,
|
||||
vm_hooks,
|
||||
hook_location,
|
||||
remotes_location,
|
||||
vm_restricted_attrs);
|
||||
hpool = new HostPool(db, host_hooks, hook_location, remotes_location);
|
||||
vm_restricted_attrs,
|
||||
vm_monitoring_history);
|
||||
|
||||
hpool = new HostPool( db,
|
||||
host_hooks,
|
||||
hook_location,
|
||||
remotes_location,
|
||||
host_monitoring_history);
|
||||
|
||||
nebula_configuration->get("MAC_PREFIX", mac_prefix);
|
||||
nebula_configuration->get("NETWORK_SIZE", size);
|
||||
|
@ -90,8 +90,10 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
#-------------------------------------------------------------------------------
|
||||
# HOST_MONITORING_INTERVAL
|
||||
# HOST_PER_INTERVAL
|
||||
# HOST_MONITORING_HISTORY
|
||||
# VM_POLLING_INTERVAL
|
||||
# VM_PER_INTERVAL
|
||||
# VM_PER_INTERVAL
|
||||
# VM_MONITORING_HISTORY
|
||||
# PORT
|
||||
# DB
|
||||
# VNC_BASE_PORT
|
||||
@ -110,6 +112,12 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
attribute = new SingleAttribute("HOST_PER_INTERVAL",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// HOST_MONITORING_HISTORY
|
||||
value = "86400";
|
||||
|
||||
attribute = new SingleAttribute("HOST_MONITORING_HISTORY",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// POLL_INTERVAL
|
||||
value = "600";
|
||||
|
||||
@ -122,6 +130,12 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
attribute = new SingleAttribute("VM_PER_INTERVAL",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// VM_MONITORING_HISTORY
|
||||
value = "86400";
|
||||
|
||||
attribute = new SingleAttribute("VM_MONITORING_HISTORY",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
//XML-RPC Server PORT
|
||||
value = "2633";
|
||||
|
||||
|
@ -243,7 +243,9 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vm_migrate(new VirtualMachineMigrate());
|
||||
xmlrpc_c::methodPtr vm_action(new VirtualMachineAction());
|
||||
xmlrpc_c::methodPtr vm_savedisk(new VirtualMachineSaveDisk());
|
||||
xmlrpc_c::methodPtr vm_monitoring(new VirtualMachineMonitoring());
|
||||
xmlrpc_c::methodPtr vm_pool_acct(new VirtualMachinePoolAccounting());
|
||||
xmlrpc_c::methodPtr vm_pool_monitoring(new VirtualMachinePoolMonitoring());
|
||||
|
||||
// VirtualNetwork Methods
|
||||
xmlrpc_c::methodPtr vn_addleases(new VirtualNetworkAddLeases());
|
||||
@ -347,9 +349,11 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.vm.info", vm_info);
|
||||
RequestManagerRegistry.addMethod("one.vm.chown", vm_chown);
|
||||
RequestManagerRegistry.addMethod("one.vm.chmod", vm_chmod);
|
||||
RequestManagerRegistry.addMethod("one.vm.monitoring", vm_monitoring);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.monitoring", vm_pool_monitoring);
|
||||
|
||||
/* VM Template related methods*/
|
||||
RequestManagerRegistry.addMethod("one.template.update", template_update);
|
||||
|
@ -131,6 +131,41 @@ void VirtualMachinePoolAccounting::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolMonitoring::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
if ( filter_flag < MINE )
|
||||
{
|
||||
failure_response(XML_RPC_API,
|
||||
request_error("Incorrect filter_flag",""),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
|
||||
where_filter(att, filter_flag, -1, -1, "", "", where);
|
||||
|
||||
rc = (static_cast<VirtualMachinePool *>(pool))->dump_monitoring(oss, where);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void HostPoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
|
@ -21,12 +21,13 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool RequestManagerVirtualMachine::vm_authorization(int oid,
|
||||
ImageTemplate * tmpl,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth * host_perm,
|
||||
PoolObjectAuth * ds_perm,
|
||||
AuthRequest::Operation op)
|
||||
bool RequestManagerVirtualMachine::vm_authorization(
|
||||
int oid,
|
||||
ImageTemplate * tmpl,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth * host_perm,
|
||||
PoolObjectAuth * ds_perm,
|
||||
AuthRequest::Operation op)
|
||||
{
|
||||
PoolObjectSQL * object;
|
||||
PoolObjectAuth vm_perms;
|
||||
@ -139,6 +140,7 @@ VirtualMachine * RequestManagerVirtualMachine::get_vm(int id,
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -174,6 +176,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
@ -573,3 +576,42 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineMonitoring::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
bool auth = vm_authorization(id, 0, att, 0, 0, auth_op);
|
||||
|
||||
if ( auth == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
oss << "oid = " << id;
|
||||
|
||||
where = oss.str();
|
||||
|
||||
oss.str("");
|
||||
|
||||
rc = (static_cast<VirtualMachinePool *>(pool))->dump_monitoring(oss, where);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -24,13 +24,13 @@ VirtualMachinePool* NebulaTest::create_vmpool(SqlDB* db, string hook_location,
|
||||
vector<const Attribute *> hooks;
|
||||
vector<const Attribute *> restricted_attrs;
|
||||
|
||||
return new VirtualMachinePool(db, hooks, hook_location, vloc, restricted_attrs);
|
||||
return new VirtualMachinePool(db, hooks, hook_location, vloc, restricted_attrs, 0);
|
||||
}
|
||||
|
||||
HostPool* NebulaTest::create_hpool(SqlDB* db, string hook_location, string vloc)
|
||||
{
|
||||
vector<const Attribute *> hooks;
|
||||
return new HostPool(db, hooks, hook_location, vloc);
|
||||
return new HostPool(db, hooks, hook_location, vloc, 0);
|
||||
}
|
||||
|
||||
VirtualNetworkPool* NebulaTest::create_vnpool(SqlDB* db, string mac_prefix, int size)
|
||||
|
@ -99,9 +99,18 @@ const char * VirtualMachine::db_names =
|
||||
"owner_u, group_u, other_u";
|
||||
|
||||
const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
|
||||
"vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, "
|
||||
"gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, "
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER)";
|
||||
"vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, "
|
||||
"gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, "
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER)";
|
||||
|
||||
|
||||
const char * VirtualMachine::monit_table = "vm_monitoring";
|
||||
|
||||
const char * VirtualMachine::monit_db_names = "vmid, last_poll, body";
|
||||
|
||||
const char * VirtualMachine::monit_db_bootstrap = "CREATE TABLE IF NOT EXISTS "
|
||||
"vm_monitoring (vmid INTEGER, last_poll INTEGER, body TEXT, "
|
||||
"PRIMARY KEY(vmid, last_poll))";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -727,6 +736,83 @@ error_common:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::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 vmid=" << oid
|
||||
<< " AND last_poll < (" << last_poll
|
||||
<< " - " << VirtualMachinePool::vm_monitoring_history() << ")";
|
||||
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
oss << "INSERT INTO " << monit_table << " ("<< monit_db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< last_poll << ","
|
||||
<< "'" << 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 VM to XML.";
|
||||
|
||||
goto error_common;
|
||||
|
||||
error_body:
|
||||
error_str = "could not insert the VM in the DB.";
|
||||
|
||||
error_common:
|
||||
oss.str("");
|
||||
oss << "Error updating VM monitoring information, " << error_str;
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR, oss);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::clean_monitoring(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << monit_table << " WHERE vmid=" << oid;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::add_history(
|
||||
int hid,
|
||||
const string& hostname,
|
||||
|
@ -24,11 +24,18 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
VirtualMachinePool::VirtualMachinePool(SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs)
|
||||
int VirtualMachinePool::_vm_monitoring_history;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
VirtualMachinePool::VirtualMachinePool(
|
||||
SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
const string& hook_location,
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
int vm_monitoring_history)
|
||||
: PoolSQL(db, VirtualMachine::table, false)
|
||||
{
|
||||
const VectorAttribute * vattr;
|
||||
@ -186,6 +193,8 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db,
|
||||
|
||||
// Set restricted attributes
|
||||
VirtualMachineTemplate::set_restricted_attributes(restricted_attrs);
|
||||
|
||||
_vm_monitoring_history = vm_monitoring_history;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -300,3 +309,27 @@ int VirtualMachinePool::dump_acct(ostringstream& oss,
|
||||
|
||||
return PoolSQL::dump(oss, "HISTORY_RECORDS", cmd);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::dump_monitoring(
|
||||
ostringstream& oss,
|
||||
const string& where)
|
||||
{
|
||||
ostringstream cmd;
|
||||
|
||||
cmd << "SELECT " << VirtualMachine::monit_table << ".body FROM "
|
||||
<< VirtualMachine::monit_table
|
||||
<< " INNER JOIN " << VirtualMachine::table
|
||||
<< " WHERE vmid = oid";
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
cmd << " AND " << where;
|
||||
}
|
||||
|
||||
cmd << " ORDER BY vmid, " << VirtualMachine::monit_table << ".last_poll;";
|
||||
|
||||
return PoolSQL::dump(oss, "MONITORING_DATA", cmd);
|
||||
}
|
||||
|
@ -90,7 +90,8 @@ public:
|
||||
SqlDB * db,
|
||||
vector<const Attribute *> hook_mads,
|
||||
vector<const Attribute *> restricted_attrs):
|
||||
VirtualMachinePool(db, hook_mads, "./", "./", restricted_attrs)
|
||||
VirtualMachinePool(db, hook_mads,
|
||||
"./", "./", restricted_attrs, 0)
|
||||
{};
|
||||
|
||||
|
||||
|
@ -550,6 +550,7 @@ void VirtualMachineManagerDriver::protocol(
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_monitoring(vm);
|
||||
|
||||
if (state != '-' &&
|
||||
(vm->get_lcm_state() == VirtualMachine::RUNNING ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user