Skip to content
Snippets Groups Projects
Commit 68b2b3b2 authored by Anael Beutot's avatar Anael Beutot
Browse files

Added tag for hypervisors showing total cpu and memory allocated to VMs.

parent b3dcf60b
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,11 @@ class Handler(HostHandler):
for dom in self.hypervisor.domains.itervalues():
self.tag_db.add_sub_object(dom.name, dom.tags.itervalues())
# we must refresh those tags only when domains tags are registered to
# have the calculated values
for tag in ('cpualloc', 'cpurunning', 'memalloc', 'memrunning'):
self.tag_db['__main__'][tag].update_value()
self.rpc_handler.update(dict(
vm_define=self.vm_define,
vm_undefine=self.vm_undefine,
......@@ -149,6 +154,10 @@ class Handler(HostHandler):
logger.error('Connection to libvirt lost, trying to restart')
# update connection state
self.virt_connected = False
# refresh those tags
for tag in ('cpualloc', 'cpurunning', 'memalloc', 'memrunning'):
self.tag_db['__main__'][tag].update_value()
# unregister tags that will be re registered later
for storage in self.hypervisor.storage.storages:
self.tag_db.remove_tags((
......@@ -817,7 +826,8 @@ class Hypervisor(object):
def update_domain_count(self):
"""Update domain state count tags."""
# update domain state counts
for tag in ('nvm', 'vmpaused', 'vmstarted', 'vmstopped'):
for tag in ('nvm', 'vmpaused', 'vmstarted', 'vmstopped', 'cpualloc',
'cpurunning', 'memalloc', 'memrunning'):
self.handler.tag_db['__main__'][tag].update_value()
def vm_define(self, xml_desc):
......
......@@ -129,3 +129,33 @@ def vmstarted(handl):
def vmstopped(handl):
"""Count of VMs Stopped."""
return handl.hypervisor.vm_stopped
@_check_virt_connected
def cpurunning(handl):
"""CPU total used by running VMs on the hypervisor."""
return sum(int(vm.tags['cpu'].value) for vm in
handl.hypervisor.domains.itervalues() if vm.tags['cpu'].value and
vm.state == 'running')
@_check_virt_connected
def cpualloc(handl):
"""CPU total used by all VMs on the hypervisor."""
return sum(int(vm.tags['cpu'].value) for vm in
handl.hypervisor.domains.itervalues() if vm.tags['cpu'].value)
@_check_virt_connected
def memrunning(handl):
"""Memory used by running VMs on the hypervisor."""
return sum(int(vm.tags['mem'].value) for vm in
handl.hypervisor.domains.itervalues() if vm.tags['mem'].value and
vm.state == 'running')
@_check_virt_connected
def memalloc(handl):
"""Memory used by all VMs on the hypervisor."""
return sum(int(vm.tags['mem'].value) for vm in
handl.hypervisor.domains.itervalues() if vm.tags['mem'].value)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment