1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-28 14:50:08 +03:00

F #2765: Configurable VM disk monitoring (#3525)

This commit is contained in:
Pavel Czerný 2019-07-17 22:11:02 +02:00 committed by Ruben S. Montero
parent 8ebb79ef74
commit 04b6d01599
8 changed files with 90 additions and 60 deletions

View File

@ -38,10 +38,12 @@ public:
time_t _monitor_period,
ImagePool * _ipool,
DatastorePool * _dspool,
vector<const VectorAttribute*>& _mads):
vector<const VectorAttribute*>& _mads,
int _monitor_vm_disk):
MadManager(_mads),
timer_period(_timer_period),
monitor_period(_monitor_period),
monitor_vm_disk(_monitor_vm_disk),
ipool(_ipool),
dspool(_dspool)
{
@ -323,6 +325,12 @@ private:
*/
time_t monitor_period;
/**
* Monitor Virtual Machine disk usage every X datastore monitoring.
* 0 to disable
*/
int monitor_vm_disk;
/**
* Pointer to the Image Pool to access VMs
*/

View File

@ -16,6 +16,9 @@
# monitoring information. -1 to disable DB updating and 0 to write every update
# MONITORING_THREADS: Max. number of threads used to process monitor messages
#
# DS_MONITOR_VM_DISK: Number of MONIROTING_INTERVAL_DATASTORE intervals to monitor
# VM disks. 0 to disable
#
# HOST_PER_INTERVAL: Number of hosts monitored in each interval.
# HOST_MONITORING_EXPIRATION_TIME: Time, in seconds, to expire monitoring
# information. Use 0 to disable HOST monitoring recording.
@ -76,6 +79,7 @@ MONITORING_INTERVAL_DB_UPDATE = 0
MONITORING_THREADS = 50
#DS_MONITOR_VM_DISK = 10
#HOST_PER_INTERVAL = 15
#HOST_MONITORING_EXPIRATION_TIME = 43200

View File

@ -169,6 +169,7 @@ void ImageManager::timer_action(const ActionRequest& ar)
void ImageManager::monitor_datastore(int ds_id)
{
static map<int,int> monitor_vm_disk_counter;
string ds_data, ds_location, ds_name;
string* drv_msg;
@ -217,10 +218,22 @@ void ImageManager::monitor_datastore(int ds_id)
}
nd.get_ds_location(ds_location);
oss << "<DATASTORE_LOCATION>"
<< ds_location
<< "</DATASTORE_LOCATION>";
if ( monitor_vm_disk > 0)
{
bool vm_monitor = --monitor_vm_disk_counter[ds_id] <= 0;
oss << "<MONITOR_VM_DISKS>"
<< vm_monitor
<< "</MONITOR_VM_DISKS>";
if (vm_monitor)
{
monitor_vm_disk_counter[ds_id] = monitor_vm_disk;
}
}
ds_location = oss.str();
break;

View File

@ -606,8 +606,6 @@ static void monitor_action(istringstream& is,
int id,
const string& result)
{
static map<int, int> tics;
string dsinfo64;
string *dsinfo = 0;
@ -696,14 +694,7 @@ static void monitor_action(istringstream& is,
NebulaLog::log("ImM", Log::DEBUG, oss);
//Process VM disk information every 10 monitor actions
if ( --tics[id] > 0 )
{
return;
}
tics[id] = 10;
//Process VM disk information
vector<VectorAttribute *> vm_disk_info;
vector<VectorAttribute *>::iterator it;

View File

@ -334,7 +334,7 @@ void Nebula::start(bool bootstrap_only)
rc = sysdb.check_db_version(is_federation_slave(), local_bootstrap,
shared_bootstrap);
if( rc == -1 )
if ( rc == -1 )
{
throw runtime_error("Database version mismatch. Check oned.log.");
}
@ -976,11 +976,15 @@ void Nebula::start(bool bootstrap_only)
nebula_configuration->get("DATASTORE_MAD", image_mads);
int monitor_vm_disk;
nebula_configuration->get("DS_MONITOR_VM_DISK", monitor_vm_disk);
imagem = new ImageManager(timer_period,
monitor_interval_datastore,
ipool,
dspool,
image_mads);
image_mads,
monitor_vm_disk);
}
catch (bad_alloc&)
{
@ -1000,7 +1004,7 @@ void Nebula::start(bool bootstrap_only)
{
try
{
vector<const VectorAttribute *> mmads ;
vector<const VectorAttribute *> mmads;
nebula_configuration->get("MARKET_MAD", mmads);
@ -1024,7 +1028,7 @@ void Nebula::start(bool bootstrap_only)
{
try
{
vector<const VectorAttribute *> ipam_mads ;
vector<const VectorAttribute *> ipam_mads;
nebula_configuration->get("IPAM_MAD", ipam_mads);
@ -1215,7 +1219,7 @@ void Nebula::start(bool bootstrap_only)
pthread_join(authm->get_thread_id(),0);
pthread_join(raftm->get_thread_id(),0);
if(is_federation_slave())
if (is_federation_slave())
{
pthread_join(aclm->get_thread_id(),0);
}

View File

@ -419,6 +419,7 @@ void OpenNebulaTemplate::set_conf_default()
# MONITORING_INTERVAL_DATASTORE
# MONITORING_INTERVAL_DB_UPDATE
# MONITORING_THREADS
# DS_MONITOR_VM_DISK
# HOST_PER_INTERVAL
# HOST_MONITORING_EXPIRATION_TIME
# VM_INDIVIDUAL_MONITORING
@ -440,6 +441,7 @@ void OpenNebulaTemplate::set_conf_default()
set_conf_single("MONITORING_INTERVAL_DATASTORE", "300");
set_conf_single("MONITORING_INTERVAL_DB_UPDATE", "0");
set_conf_single("MONITORING_THREADS", "50");
set_conf_single("DS_MONITOR_VM_DISK", "1");
set_conf_single("HOST_PER_INTERVAL", "15");
set_conf_single("HOST_MONITORING_EXPIRATION_TIME", "43200");
set_conf_single("VM_INDIVIDUAL_MONITORING", "no");

View File

@ -45,12 +45,14 @@ unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE_LOCATION \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST)
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
/DS_DRIVER_ACTION_DATA/MONITOR_VM_DISKS)
unset i
BASE_PATH="${XPATH_ELEMENTS[i++]}/$2"
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
MONITOR_VM_DISKS="${XPATH_ELEMENTS[i++]}"
# ------------ Compute datastore usage -------------
@ -99,32 +101,34 @@ echo "USED_MB=\$USED_MB"
echo "FREE_MB=\$FREE_MB"
echo "TOTAL_MB=\$TOTAL_MB"
lvdata=\$($SUDO $LVS --noheadings --nosuffix --units m -o lv_name,lv_size --separator : "${LVM_VG_PREFIX}${DS_ID}" | sed -e 's/^[[:space:]]*//' | grep '^lv-one-' | sed 's/^lv-one-//' | tr '-' ':' | sort -n)
[ -z "\$lvdata" ] && exit 0
if [ $MONITOR_VM_DISKS -eq 1 ]; then
lvdata=\$($SUDO $LVS --noheadings --nosuffix --units m -o lv_name,lv_size --separator : "${LVM_VG_PREFIX}${DS_ID}" | sed -e 's/^[[:space:]]*//' | grep '^lv-one-' | sed 's/^lv-one-//' | tr '-' ':' | sort -n)
[ -z "\$lvdata" ] && exit 0
vm_previous='n'
vm_previous='n'
while IFS="\n" read -r line; do
vm=\$(echo "\$line" | cut -d':' -f1)
[ -n "\$vm" ] || continue
while IFS="\n" read -r line; do
vm=\$(echo "\$line" | cut -d':' -f1)
[ -n "\$vm" ] || continue
disk=\$(echo "\$line" | cut -d':' -f2)
size=\$(echo "\$line" | cut -d':' -f3 | cut -d'.' -f1)
disk=\$(echo "\$line" | cut -d':' -f2)
size=\$(echo "\$line" | cut -d':' -f3 | cut -d'.' -f1)
if [ "\$vm" != "\$vm_previous" ]; then
[ "\$vm_previous" != "n" ] && echo "\"]"
if [ "\$vm" != "\$vm_previous" ]; then
[ "\$vm_previous" != "n" ] && echo "\"]"
vm_previous="\$vm"
echo -n "VM=[ID=\$vm,POLL=\""
else
echo -n " "
fi
vm_previous="\$vm"
echo -n "VM=[ID=\$vm,POLL=\""
else
echo -n " "
fi
echo -n "DISK_SIZE=[ID=\$disk,SIZE=\$size]"
echo -n "DISK_SIZE=[ID=\$disk,SIZE=\$size]"
done <<< "\$( echo "\$lvdata" )"
done <<< "\$( echo "\$lvdata" )"
[ "\$vm_previous" != "n" ] && echo "\"]"
[ "\$vm_previous" != "n" ] && echo "\"]"
fi
EOF
)

View File

@ -45,12 +45,14 @@ unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE_LOCATION \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST)
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
/DS_DRIVER_ACTION_DATA/MONITOR_VM_DISKS)
unset i
BASE_PATH="${XPATH_ELEMENTS[i++]}/$2"
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
MONITOR_VM_DISKS="${XPATH_ELEMENTS[i++]}"
# ------------ Compute datastore usage -------------
@ -73,37 +75,39 @@ echo "USED_MB=\$USED_MB"
echo "FREE_MB=\$FREE_MB"
echo "TOTAL_MB=\$TOTAL_MB"
vms=\$(ls "$BASE_PATH" | grep '^[0-9]\+$')
if [ $MONITOR_VM_DISKS -eq 1 ]; then
vms=\$(ls "$BASE_PATH" | grep '^[0-9]\+$')
for vm in \$vms; do
vmdir="${BASE_PATH}/\${vm}"
disks=\$(ls "\$vmdir" 2>/dev/null | grep '^disk\.[0-9]\+$')
for vm in \$vms; do
vmdir="${BASE_PATH}/\${vm}"
disks=\$(ls "\$vmdir" 2>/dev/null | grep '^disk\.[0-9]\+$')
[ -z \$disks ] && continue
[ -z \$disks ] && continue
echo -n "VM=[ID=\$vm,POLL=\""
echo -n "VM=[ID=\$vm,POLL=\""
for disk in \$disks; do
disk_id="\$(echo "\$disk" | cut -d. -f2)"
disk_size="\$(du -mL "\${vmdir}/\${disk}" 2>/dev/null | awk '{print \$1}')"
snap_dir="\${vmdir}/\${disk}.snap"
for disk in \$disks; do
disk_id="\$(echo "\$disk" | cut -d. -f2)"
disk_size="\$(du -mL "\${vmdir}/\${disk}" 2>/dev/null | awk '{print \$1}')"
snap_dir="\${vmdir}/\${disk}.snap"
[ -z "\$disk_size" ] && continue
echo -n "DISK_SIZE=[ID=\${disk_id},SIZE=\${disk_size}] "
[ -z "\$disk_size" ] && continue
echo -n "DISK_SIZE=[ID=\${disk_id},SIZE=\${disk_size}] "
if [ -e "\$snap_dir" ]; then
snaps="\$(ls "\$snap_dir" 2>/dev/null | grep '^[0-9]$')"
if [ -e "\$snap_dir" ]; then
snaps="\$(ls "\$snap_dir" 2>/dev/null | grep '^[0-9]$')"
for snap in \$snaps; do
snap_size="\$(du -mL "\${snap_dir}/\${snap}" 2>/dev/null | awk '{print \$1}')"
[ -z "\$snap_size" ] && continue
echo -n "SNAPSHOT_SIZE=[ID=\${snap},DISK_ID=\${disk_id},SIZE=\${snap_size}] "
done
fi
for snap in \$snaps; do
snap_size="\$(du -mL "\${snap_dir}/\${snap}" 2>/dev/null | awk '{print \$1}')"
[ -z "\$snap_size" ] && continue
echo -n "SNAPSHOT_SIZE=[ID=\${snap},DISK_ID=\${disk_id},SIZE=\${snap_size}] "
done
fi
done
echo "\"]"
done
echo "\"]"
done
fi
EOF
)