This commit is contained in:
Vyacheslav Anzhiganov 2016-10-12 11:00:04 +03:00
parent f683840980
commit 4a5770cff6

View file

@ -14,14 +14,14 @@ class QemuStats(object):
def __del__(self): def __del__(self):
self.conn.close() self.conn.close()
def network(self, dom): def network(self, dom_name):
results = dict( results = dict(
read_bytes=0, read_packets=0, read_errors=0, read_drops=0, read_bytes=0, read_packets=0, read_errors=0, read_drops=0,
write_bytes=0, write_packets=0, write_errors=0, write_drops=0) write_bytes=0, write_packets=0, write_errors=0, write_drops=0)
dom = self.conn.lookupByName(dom) dom = self.conn.lookupByName(dom_name)
# dom = conn.lookupByID(5) # dom = conn.lookupByID(5)
if dom == None: if not dom:
return results return results
tree = ElementTree.fromstring(dom.XMLDesc()) tree = ElementTree.fromstring(dom.XMLDesc())
@ -39,17 +39,17 @@ class QemuStats(object):
return results return results
def cpu(self, dom): def cpu(self, dom_name):
# http://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-vCPU.html # http://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-vCPU.html
results = dict(cpu_time=0, system_time=0, user_time=0) results = dict(cpu_time=0, system_time=0, user_time=0)
if self.conn == None: if not self.conn:
print('Failed to open connection to qemu:///system', file=sys.stderr) print('Failed to open connection to qemu:///system', file=sys.stderr)
return results return results
# dom = conn.lookupByID(5) # dom = conn.lookupByID(5)
dom = self.conn.lookupByName(dom) dom = self.conn.lookupByName(dom_name)
if dom == None: if not dom:
print('Failed to find the domain '+domName, file=sys.stderr) print('Failed to find the domain '+dom_name, file=sys.stderr)
return results return results
stats = dom.getCPUStats(True) stats = dom.getCPUStats(True)
@ -60,20 +60,20 @@ class QemuStats(object):
return results return results
def memory(self, dom): def memory(self, dom_name):
# http://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-Memory.html # http://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/libvirt_application_development_guide_using_python-Guest_Domains-Monitoring-Memory.html
results = dict() results = dict()
if self.conn == None: if not self.conn:
print('Failed to open connection to qemu:///system', file=sys.stderr) print('Failed to open connection to qemu:///system', file=sys.stderr)
return results return results
# dom = conn.lookupByID(5) # dom = conn.lookupByID(5)
dom = self.conn.lookupByName(dom) dom = self.conn.lookupByName(dom_name)
if dom == None: if not dom:
print('Failed to find the domain '+domName, file=sys.stderr) print('Failed to find the domain '+dom_name, file=sys.stderr)
return results return results
stats = dom.memoryStats() stats = dom.memoryStats()
# print('memory used:') # print('memory used:')
for name in stats: for name in stats:
results[name] = stats[name] results[name] = stats[name]