WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [XEND] Add simple VCPUs, VBDs, VIFs stati

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEND] Add simple VCPUs, VBDs, VIFs statistics monitoring
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 25 Jan 2007 08:55:14 -0800
Delivery-date: Thu, 25 Jan 2007 08:56:04 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Alastair Tse <atse@xxxxxxxxxxxxx>
# Date 1169640581 0
# Node ID f7a52957b427f7bd107be57f06d311e126e9eff1
# Parent  4f5772324e679e9794ccd72848023c081d7300da
[XEND] Add simple VCPUs, VBDs, VIFs statistics monitoring

Keep track of xentop like statistics to expose through the Xen API

Signed-off-by: Alastair Tse <atse@xxxxxxxxxxxxx>
---
 tools/python/scripts/xapi.py            |    6 ++++
 tools/python/xen/xend/XendDomainInfo.py |   34 +++++++++++++++++++-------
 tools/python/xen/xend/XendNode.py       |   41 +++++++++++++++++++++++++++++++-
 3 files changed, 71 insertions(+), 10 deletions(-)

diff -r 4f5772324e67 -r f7a52957b427 tools/python/scripts/xapi.py
--- a/tools/python/scripts/xapi.py      Wed Jan 24 12:07:54 2007 +0000
+++ b/tools/python/scripts/xapi.py      Wed Jan 24 12:09:41 2007 +0000
@@ -200,6 +200,12 @@ def xapi_host_info(*args):
         print HOST_INFO_FORMAT % ('VMs', len(hostinfo['resident_VMs']))
         print HOST_INFO_FORMAT % ('UUID', host)        
 
+        for host_cpu_uuid in hostinfo['host_CPUs']:
+            host_cpu = execute(server.host_cpu.get_record, session,
+                               host_cpu_uuid)
+            print 'CPU %s Util: %.2f' % (host_cpu['number'],
+                                         float(host_cpu['utilisation']))
+        
 def xapi_host_set_name(*args):
     if len(args) < 1:
         raise OptionError("No hostname specified")
diff -r 4f5772324e67 -r f7a52957b427 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Wed Jan 24 12:07:54 2007 +0000
+++ b/tools/python/xen/xend/XendDomainInfo.py   Wed Jan 24 12:09:41 2007 +0000
@@ -2052,10 +2052,29 @@ class XendDomainInfo:
                     # handle that properly.
 
             config['MTU'] = 1500 # TODO
-            config['io_read_kbs'] = 0.0
-            config['io_write_kbs'] = 0.0
+            
+            if self.state not in (XEN_API_VM_POWER_STATE_HALTED,):
+                xennode = XendNode.instance()
+                rx_bps, tx_bps = xennode.get_vif_util(self.domid, devid)
+                config['io_read_kbs'] = rx_bps/1024
+                config['io_write_kbs'] = tx_bps/1024
+            else:
+                config['io_read_kbs'] = 0.0
+                config['io_write_kbs'] = 0.0                
 
         if dev_class == 'vbd':
+
+            if self.state not in (XEN_API_VM_POWER_STATE_HALTED,):
+                controller = self.getDeviceController(dev_class)
+                devid, _1, _2 = controller.getDeviceDetails(config)
+                xennode = XendNode.instance()
+                rd_blkps, wr_blkps = xennode.get_vbd_util(self.domid, devid)
+                config['io_read_kbs'] = rd_blkps
+                config['io_write_kbs'] = wr_blkps
+            else:
+                config['io_read_kbs'] = 0.0
+                config['io_write_kbs'] = 0.0                
+            
             config['VDI'] = config.get('VDI', '')
             config['device'] = config.get('dev', '')
             if ':' in config['device']:
@@ -2068,8 +2087,7 @@ class XendDomainInfo:
 
             config['driver'] = 'paravirtualised' # TODO
             config['image'] = config.get('uname', '')
-            config['io_read_kbs'] = 0.0
-            config['io_write_kbs'] = 0.0
+
             if config.get('mode', 'r') == 'r':
                 config['mode'] = 'RO'
             else:
@@ -2088,14 +2106,12 @@ class XendDomainInfo:
             raise XendError('Invalid property for device: %s' % field)
 
     def get_vcpus_util(self):
-        # TODO: this returns the total accum cpu time, rather than util
-        # TODO: spec says that key is int, however, python does not allow
-        #       non-string keys to dictionaries.
         vcpu_util = {}
+        xennode = XendNode.instance()
         if 'vcpus_number' in self.info and self.domid != None:
             for i in range(0, self.info['vcpus_number']):
-                info = xc.vcpu_getinfo(self.domid, i)
-                vcpu_util[str(i)] = info['cpu_time']/1000000000.0
+                util = xennode.get_vcpu_util(self.domid, i)
+                vcpu_util[str(i)] = util
                 
         return vcpu_util
 
diff -r 4f5772324e67 -r f7a52957b427 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Wed Jan 24 12:07:54 2007 +0000
+++ b/tools/python/xen/xend/XendNode.py Wed Jan 24 12:09:41 2007 +0000
@@ -30,6 +30,7 @@ from xen.xend.XendPIF import *
 from xen.xend.XendPIF import *
 from xen.xend.XendNetwork import *
 from xen.xend.XendStateStore import XendStateStore
+from xen.xend.XendMonitor import XendMonitor
 
 class XendNode:
     """XendNode - Represents a Domain 0 Host."""
@@ -46,6 +47,8 @@ class XendNode:
         
         self.xc = xen.lowlevel.xc.xc()
         self.state_store = XendStateStore(xendoptions().get_xend_state_path())
+        self.monitor = XendMonitor()
+        self.monitor.start()
 
         # load host state from XML file
         saved_host = self.state_store.load_state('host')
@@ -285,8 +288,16 @@ class XendNode:
             raise XendError('Invalid CPU Reference')        
             
     def get_host_cpu_load(self, host_cpu_ref):
+        host_cpu = self.cpus.get(host_cpu_ref)
+        if not host_cpu:
+            return 0.0
+
+        vcpu = int(host_cpu['number'])
+        cpu_loads = self.monitor.get_domain_vcpus_util()
+        if 0 in cpu_loads and vcpu in cpu_loads[0]:
+            return cpu_loads[0][vcpu]
+
         return 0.0
-
 
     #
     # Network Functions
@@ -397,6 +408,34 @@ class XendNode:
     def xendinfo(self):
         return [['xend_config_format', 3]]
 
+    #
+    # utilisation tracking
+    #
+
+    def get_vcpu_util(self, domid, vcpuid):
+        cpu_loads = self.monitor.get_domain_vcpus_util()
+        if domid in cpu_loads:
+            return cpu_loads[domid].get(vcpuid, 0.0)
+        return 0.0
+
+    def get_vif_util(self, domid, vifid):
+        vif_loads = self.monitor.get_domain_vifs_util()
+        if domid in vif_loads:
+            return vif_loads[domid].get(vifid, (0.0, 0.0))
+        return (0.0, 0.0)
+
+    def get_vbd_util(self, domid, vbdid):
+        vbd_loads = self.monitor.get_domain_vbds_util()
+        if domid in vbd_loads:
+            return vbd_loads[domid].get(vbdid, (0.0, 0.0))
+        return (0.0, 0.0)
+
+    def get_pif_util(self, pifid):
+        pifs_util = self.monitor.get_pifs_util()
+        if pifid in pifs_util:
+            return pifs_util[pifid]
+        return (0.0, 0.0)
+
     # dictionary version of *info() functions to get rid of
     # SXPisms.
     def nodeinfo_dict(self):

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [XEND] Add simple VCPUs, VBDs, VIFs statistics monitoring, Xen patchbot-unstable <=