direct-io.hg

changeset 13641:b97780b7080d

[XEND] Hook in utilisation statistics into Xen API calls.

Change PIF to be indexed by device name rather than the interface
number.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Fri Jan 26 15:45:51 2007 +0000 (2007-01-26)
parents 93d3ff513609
children 480436ef6255
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendMonitor.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendPIF.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Fri Jan 26 15:44:41 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Fri Jan 26 15:45:51 2007 +0000
     1.3 @@ -1448,10 +1448,15 @@ class XendAPI(object):
     1.4                                                                'type'))        
     1.5  
     1.6      def VBD_get_io_read_kbs(self, session, vbd_ref):
     1.7 -        return xen_api_todo()
     1.8 +        xendom = XendDomain.instance()
     1.9 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
    1.10 +                                                              'io_read_kbs'))
    1.11 +    
    1.12      
    1.13      def VBD_get_io_write_kbs(self, session, vbd_ref):
    1.14 -        return xen_api_todo()
    1.15 +        xendom = XendDomain.instance()
    1.16 +        return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
    1.17 +                                                              'io_read_kbs'))
    1.18      
    1.19      def VBD_get_all(self, session):
    1.20          xendom = XendDomain.instance()
    1.21 @@ -1553,10 +1558,14 @@ class XendAPI(object):
    1.22      
    1.23   
    1.24      def VIF_get_io_read_kbs(self, session, vif_ref):
    1.25 -        return xen_api_todo()
    1.26 -    
    1.27 +        xendom = XendDomain.instance()
    1.28 +        return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
    1.29 +                                                               'io_read_kbs'))
    1.30 +
    1.31      def VIF_get_io_write_kbs(self, session, vif_ref):
    1.32 -        return xen_api_todo()
    1.33 +        xendom = XendDomain.instance()
    1.34 +        return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
    1.35 +                                                               'io_write_kbs'))
    1.36      
    1.37      def VIF_get_all(self, session):
    1.38          xendom = XendDomain.instance()
     2.1 --- a/tools/python/xen/xend/XendMonitor.py	Fri Jan 26 15:44:41 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendMonitor.py	Fri Jan 26 15:45:51 2007 +0000
     2.3 @@ -49,7 +49,7 @@ PROC_NET_DEV_RE = r'(?P<rx_bytes>\d+)\s+
     2.4  
     2.5  VIF_DOMAIN_RE = re.compile(r'vif(?P<domid>\d+)\.(?P<iface>\d+):\s*' +
     2.6                             PROC_NET_DEV_RE)
     2.7 -PIF_RE = re.compile(r'peth(?P<iface>\d+):\s*' + PROC_NET_DEV_RE)
     2.8 +PIF_RE = re.compile(r'^\s*(?P<iface>peth\d+):\s*' + PROC_NET_DEV_RE)
     2.9  
    2.10  # The VBD transfer figures are in "requests" where we don't
    2.11  # really know how many bytes per requests. For now we make
    2.12 @@ -154,10 +154,10 @@ class XendMonitor(threading.Thread):
    2.13              if not is_pif:
    2.14                  continue
    2.15              
    2.16 -            pifid = int(is_pif.group('iface'))
    2.17 +            pifname = is_pif.group('iface')
    2.18              rx_bytes = int(is_pif.group('rx_bytes'))
    2.19              tx_bytes = int(is_pif.group('tx_bytes'))
    2.20 -            stats[pifid] = (usage_at, rx_bytes, tx_bytes)
    2.21 +            stats[pifname] = (usage_at, rx_bytes, tx_bytes)
    2.22  
    2.23          return stats    
    2.24  
    2.25 @@ -297,19 +297,19 @@ class XendMonitor(threading.Thread):
    2.26  
    2.27                  # Calculate utilisation for PIFs
    2.28  
    2.29 -                for pifid, stats in self._get_pif_stats().items():
    2.30 -                    if pifid not in self.pifs:
    2.31 -                        self.pifs[pifid] = stats
    2.32 +                for pifname, stats in self._get_pif_stats().items():
    2.33 +                    if pifname not in self.pifs:
    2.34 +                        self.pifs[pifname] = stats
    2.35                          continue
    2.36  
    2.37                      usage_at, rx, tx = stats
    2.38 -                    prv_at, prv_rx, prv_tx  = self.pifs[pifid]
    2.39 +                    prv_at, prv_rx, prv_tx  = self.pifs[pifname]
    2.40                      interval = usage_at - prv_at
    2.41                      rx_util = (rx - prv_rx)/interval
    2.42                      tx_util = (tx - prv_tx)/interval
    2.43  
    2.44 -                    self.pifs_util[pifid] = (rx_util, tx_util)
    2.45 -                    self.pifs[pifid] = stats
    2.46 +                    self.pifs_util[pifname] = (rx_util, tx_util)
    2.47 +                    self.pifs[pifname] = stats
    2.48  
    2.49                  for domid in self._domain_vcpus_util.keys():
    2.50                      if domid not in active_domids:
     3.1 --- a/tools/python/xen/xend/XendNode.py	Fri Jan 26 15:44:41 2007 +0000
     3.2 +++ b/tools/python/xen/xend/XendNode.py	Fri Jan 26 15:45:51 2007 +0000
     3.3 @@ -482,10 +482,10 @@ class XendNode:
     3.4              return vbd_loads[domid].get(vbdid, (0.0, 0.0))
     3.5          return (0.0, 0.0)
     3.6  
     3.7 -    def get_pif_util(self, pifid):
     3.8 +    def get_pif_util(self, pifname):
     3.9          pifs_util = self.monitor.get_pifs_util()
    3.10 -        if pifid in pifs_util:
    3.11 -            return pifs_util[pifid]
    3.12 +        if pifname in pifs_util:
    3.13 +            return pifs_util[pifname]
    3.14          return (0.0, 0.0)
    3.15  
    3.16      # dictionary version of *info() functions to get rid of
     4.1 --- a/tools/python/xen/xend/XendPIF.py	Fri Jan 26 15:44:41 2007 +0000
     4.2 +++ b/tools/python/xen/xend/XendPIF.py	Fri Jan 26 15:45:51 2007 +0000
     4.3 @@ -115,10 +115,12 @@ class XendPIF:
     4.4          return success
     4.5  
     4.6      def get_io_read_kbs(self):
     4.7 -        return 0.0
     4.8 +        from xen.xend.XendNode import instance as xennode
     4.9 +        return xennode().get_pif_util(self.name)[0]
    4.10  
    4.11      def get_io_write_kbs(self):
    4.12 -        return 0.0
    4.13 +        from xen.xend.XendNode import instance as xennode
    4.14 +        return xennode().get_pif_util(self.name)[1]      
    4.15  
    4.16      def get_record(self, transient = True):
    4.17          result = {'name': self.name,