Skip to content

Commit

Permalink
Fixes and improvements in cvem monitoring
Browse files Browse the repository at this point in the history
Signed-off-by: Kristián Feldsam <[email protected]>
  • Loading branch information
feldsam committed Feb 9, 2016
1 parent cafad3f commit 5bd9afa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cvem/connectors/one/OpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DISK(XMLObject):
values = ['CLONE','READONLY','SAVE','SOURCE','TARGET' ]

class TEMPLATE(XMLObject):
values = [ 'CPU', 'MEMORY', 'NAME', 'RANK', 'REQUIREMENTS', 'VMID', 'VCPU', 'PACKEDMEMORY', 'MAXMEMORY' ]
values = [ 'CPU', 'MEMORY', 'NAME', 'RANK', 'REQUIREMENTS', 'VMID', 'VCPU' ]

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

This values doesn't exists in VM TEMPLATE, they are in monitoring info

tuples = { 'GRAPHICS': GRAPHICS, 'OS': OS }
tuples_lists = { 'DISK': DISK, 'NIC': NIC }
numeric = [ 'CPU', 'MEMORY', 'VCPU' ]
Expand All @@ -62,7 +62,7 @@ class VM(XMLObject):
STATE_FAILED=7
STATE_STR = {'0': 'init', '1': 'pending', '2': 'hold', '3': 'active', '4': 'stopped', '5': 'suspended', '6': 'done', '7': 'failed' }
LCM_STATE_STR={'0':'init','1':'prologing','2':'booting','3':'running','4':'migrating','5':'saving (stop)','6':'saving (suspend)','7':'saving (migrate)', '8':'prologing (migration)', '9':'prologing (resume)', '10': 'epilog (stop)','11':'epilog', '12':'cancel','13':'failure','14':'delete','15':'unknown'}
values = [ 'ID','UID','NAME','LAST_POLL','STATE','LCM_STATE','DEPLOY_ID','MEMORY','CPU','NET_TX','NET_RX', 'STIME','ETIME' ]
values = [ 'ID','UID','NAME','LAST_POLL','STATE','LCM_STATE','DEPLOY_ID','MEMORY','CPU','NET_TX','NET_RX', 'STIME','ETIME', 'PACKEDMEMORY', 'MAXMEMORY', 'REALMEMORY' ]

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

So I moved it here and added new one REALMEMORY, which is reported by opennebula poll script. It is from virsh dominfo "Used memory" without compromising by resident memory.

tuples = { 'TEMPLATE': TEMPLATE, 'HISTORY_RECORDS': HISTORY_RECORDS, 'USER_TEMPLATE': USER_TEMPLATE }
numeric = [ 'ID', 'UID', 'STATE', 'LCM_STATE', 'STIME','ETIME' ]

Expand Down Expand Up @@ -148,10 +148,10 @@ def get_vm_list():
res = []
for vm in res_vm.VM:
host = HostInfo(int(vm.HISTORY_RECORDS.HISTORY[0].HID), vm.HISTORY_RECORDS.HISTORY[0].HOSTNAME)
new_vm = VirtualMachineInfo(int(vm.ID), host, vm.TEMPLATE.MEMORY * 1024, vm)
new_vm = VirtualMachineInfo(int(vm.ID), host, vm.MAXMEMORY, vm)

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

I set MAXMEMORY to vm.allocated_memory

new_vm.user_id = vm.UID
if vm.USER_TEMPLATE.MEM_TOTAL:
new_vm.set_memory_values(int(vm.USER_TEMPLATE.MEM_TOTAL_REAL),
new_vm.set_memory_values(int(vm.REALMEMORY),

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

vm.real_memory - this was filled from Memory Reporter MEM_TOTAL_REAL, but it is a bad value which is close to maxmemory. We need real memory setted by virsh setmem command

int(vm.USER_TEMPLATE.MEM_TOTAL),
int(vm.USER_TEMPLATE.MEM_FREE))
if vm.USER_TEMPLATE.MIN_FREE_MEM:
Expand Down
2 changes: 1 addition & 1 deletion cvem/cvem/CMPInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, vm_id = None, host = None, allocated_memory = None, raw = Non
""" Total memory reported by the S.O. (less than real_memory) """
self.free_memory = None
""" Free memory of the VM """
self.allocated_memory = None
self.allocated_memory = allocated_memory

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Fix, I added missing assingment

""" Amount of memory originally allocated by the CMP """
self.min_free_mem = None
""" Minimum amount of memory that will trigger the exponential backoff algorithm
Expand Down
30 changes: 19 additions & 11 deletions cvem/cvem/Monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,32 @@ def monitor_vm(self, vm, all_vms):
"""
Main function of the monitor
"""
vm_pct_free_memory = float(vm.free_memory)/float(vm.total_memory) * 100.0
mem_over_ratio = Config.MEM_OVER
if vm.mem_over_ratio:
mem_over_ratio = vm.mem_over_ratio

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Moved this to top for earlier use


if vm.id not in self.mem_diff:
self.mem_diff[vm.id] = vm.real_memory - vm.total_memory

vm.total_memory += self.mem_diff[vm.id]
vm_pct_free_memory = float(vm.free_memory)/float(vm.total_memory) * 100.0
vm_pct_free_memory_inc_over_ratio = vm_pct_free_memory * (1 + mem_over_ratio / 100.0);

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Calculate free memory percentage including memory over provisioning ratio


vmid_msg = "VMID " + str(vm.id) + ": "
vm.host = self.get_host_info(vm.host.id)
#logger.debug(vmid_msg + "VM is in Host: " + vm.host.name + ". PACKEDMEMORY = " + str(vm.host.raw.TEMPLATE.PACKEDMEMORY))

logger.info(vmid_msg + "Real Memory: " + str(vm.real_memory))
logger.info(vmid_msg + "Total Memory: " + str(vm.total_memory))
logger.info(vmid_msg + "Free Memory: %d" % vm.free_memory)

mem_over_ratio = Config.MEM_OVER
if vm.mem_over_ratio:
mem_over_ratio = vm.mem_over_ratio

if vm_pct_free_memory < (mem_over_ratio - Config.MEM_MARGIN) or vm_pct_free_memory > (mem_over_ratio + Config.MEM_MARGIN):
if vm_pct_free_memory_inc_over_ratio < (mem_over_ratio - Config.MEM_MARGIN) or vm_pct_free_memory_inc_over_ratio > (mem_over_ratio + Config.MEM_MARGIN):

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Fixed this IF to comparing with free memory including mem_over_ratio. So it is TRUE only if freemem is 5% under or 5% over desired mem_over.

Ex.
total_mem = 612MB
free_mem = 100MB
used_mem = 512MB
over_ratio = 40%
set new_mem = 512 * 1,4 = 716,8MB

New itteration
total_mem = 716,8MB
free_mem = 204,8MB
over_ratio = 40%

Without over_ratio
free_mem/total_mem = 204,8/716,8 = 0,29 * 100 = 29%, so its is under 35% (40-5margin)
Script is executed to do new memory calculation

With over_ratio
free_mem/total_mem = 204,8/716,8 = 0,29 * 140 = 40,6%, great, here is no change, skip new calculations

After this fix MEM_DIFF_TO_CHANGE never takes to effect, probably

now = time.time()

logger.debug(vmid_msg + "VM %s has %.2f of free memory, change the memory size" % (vm.id, vm_pct_free_memory))
if vm.id in self.last_set_mem:
logger.debug(vmid_msg + "Last memory change was %s secs ago." % (now - self.last_set_mem[vm.id]))
else:
self.original_mem[vm.id] = vm.total_memory
self.original_mem[vm.id] = vm.allocated_memory

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

fix to save original allocated max memory

logger.debug(vmid_msg + "The memory of this VM has been never modified. Store the initial memory : " + str(self.original_mem[vm.id]))
self.last_set_mem[vm.id] = now

Expand Down Expand Up @@ -158,11 +159,18 @@ def monitor_vm(self, vm, all_vms):
multiplier = 1.0 + (mem_over_ratio/100.0)
logger.debug(vmid_msg + "The used memory %d is multiplied by %.2f" % (int(mem_usada), multiplier))
new_mem = int(mem_usada * multiplier)

# Check for minimum memory
if new_mem < Config.MEM_MIN:
new_mem = Config.MEM_MIN

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

First check for min VM memory


# add diff to new_mem value
new_mem += self.mem_diff[vm.id]

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

If mim mem is OK them add diff beetween real and total mem. This memory is somewhere stolen in hypervisor. (http://www.espenbraastad.no/post/memory-ballooning/)

After it we can check for original max memory


# We never set more memory that the initial amount
if new_mem > self.original_mem[vm.id]:
new_mem = self.original_mem[vm.id]
elif new_mem < Config.MEM_MIN:
new_mem = Config.MEM_MIN

if abs(int(vm.total_memory)-new_mem) < Config.MEM_DIFF_TO_CHANGE:
logger.debug(vmid_msg + "Not changing the memory. Too small difference.")
else:
Expand Down Expand Up @@ -319,7 +327,7 @@ def change_memory(vm_id, vm_host, new_mem):
"""
chmem_cmd = Config.CHANGE_MEMORY_CMD.format(hostname = vm_host.name, vmid = str(vm_id), newmemory = str(new_mem))

logger.debug("Change the memory from " + str(vm_id) + " to " + str(new_mem))
logger.debug("Change the memory of VM: " + str(vm_id) + " to " + str(new_mem))

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Fixed comment

logger.debug("Executing: " + chmem_cmd)
if not Config.ONLY_TEST:
success, out = runcommand(chmem_cmd, shell=True)
Expand Down
2 changes: 2 additions & 0 deletions opennebula/vmm/cloudvamp/poll
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module KVM
values[:state] = get_state(dominfo['State'])
values[:usedcpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:usedmemory] = [resident_mem, used_mem].max
values[:realmemory] = used_mem

This comment has been minimized.

Copy link
@feldsam

feldsam Feb 9, 2016

Author Owner

Added REALMEMORY do poller

values[:maxmemory] = [resident_mem, max_mem].max
values[:packedmemory] = values[:maxmemory] - values[:usedmemory]

Expand Down Expand Up @@ -141,6 +142,7 @@ module KVM
values[:state] = get_state(dominfo['State'])
values[:usedcpu] = cpu[vm[:pid]] if cpu[vm[:pid]]
values[:usedmemory] = [resident_mem, used_mem].max
values[:realmemory] = used_mem
values[:maxmemory] = [resident_mem, max_mem].max
values[:packedmemory] = values[:maxmemory] - values[:usedmemory]

Expand Down

0 comments on commit 5bd9afa

Please sign in to comment.