mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
[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>
This commit is contained in:
1 parent
68da406e51
commit
247a0089e5
4 files changed
+30
-19
No files matched your search
@@ -1448,10 +1448,15 @@ class XendAPI(object):
|
||||
'type'))
|
||||
|
||||
def VBD_get_io_read_kbs(self, session, vbd_ref):
|
||||
return xen_api_todo()
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
'io_read_kbs'))
|
||||
|
||||
|
||||
def VBD_get_io_write_kbs(self, session, vbd_ref):
|
||||
return xen_api_todo()
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vbd', vbd_ref,
|
||||
'io_read_kbs'))
|
||||
|
||||
def VBD_get_all(self, session):
|
||||
xendom = XendDomain.instance()
|
||||
@@ -1553,10 +1558,14 @@ class XendAPI(object):
|
||||
|
||||
|
||||
def VIF_get_io_read_kbs(self, session, vif_ref):
|
||||
return xen_api_todo()
|
||||
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
|
||||
'io_read_kbs'))
|
||||
|
||||
def VIF_get_io_write_kbs(self, session, vif_ref):
|
||||
return xen_api_todo()
|
||||
xendom = XendDomain.instance()
|
||||
return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref,
|
||||
'io_write_kbs'))
|
||||
|
||||
def VIF_get_all(self, session):
|
||||
xendom = XendDomain.instance()
|
||||
|
||||
@@ -49,7 +49,7 @@ PROC_NET_DEV_RE = r'(?P<rx_bytes>\d+)\s+' \
|
||||
|
||||
VIF_DOMAIN_RE = re.compile(r'vif(?P<domid>\d+)\.(?P<iface>\d+):\s*' +
|
||||
PROC_NET_DEV_RE)
|
||||
PIF_RE = re.compile(r'peth(?P<iface>\d+):\s*' + PROC_NET_DEV_RE)
|
||||
PIF_RE = re.compile(r'^\s*(?P<iface>peth\d+):\s*' + PROC_NET_DEV_RE)
|
||||
|
||||
# The VBD transfer figures are in "requests" where we don't
|
||||
# really know how many bytes per requests. For now we make
|
||||
@@ -154,10 +154,10 @@ class XendMonitor(threading.Thread):
|
||||
if not is_pif:
|
||||
continue
|
||||
|
||||
pifid = int(is_pif.group('iface'))
|
||||
pifname = is_pif.group('iface')
|
||||
rx_bytes = int(is_pif.group('rx_bytes'))
|
||||
tx_bytes = int(is_pif.group('tx_bytes'))
|
||||
stats[pifid] = (usage_at, rx_bytes, tx_bytes)
|
||||
stats[pifname] = (usage_at, rx_bytes, tx_bytes)
|
||||
|
||||
return stats
|
||||
|
||||
@@ -297,19 +297,19 @@ class XendMonitor(threading.Thread):
|
||||
|
||||
# Calculate utilisation for PIFs
|
||||
|
||||
for pifid, stats in self._get_pif_stats().items():
|
||||
if pifid not in self.pifs:
|
||||
self.pifs[pifid] = stats
|
||||
for pifname, stats in self._get_pif_stats().items():
|
||||
if pifname not in self.pifs:
|
||||
self.pifs[pifname] = stats
|
||||
continue
|
||||
|
||||
usage_at, rx, tx = stats
|
||||
prv_at, prv_rx, prv_tx = self.pifs[pifid]
|
||||
prv_at, prv_rx, prv_tx = self.pifs[pifname]
|
||||
interval = usage_at - prv_at
|
||||
rx_util = (rx - prv_rx)/interval
|
||||
tx_util = (tx - prv_tx)/interval
|
||||
|
||||
self.pifs_util[pifid] = (rx_util, tx_util)
|
||||
self.pifs[pifid] = stats
|
||||
self.pifs_util[pifname] = (rx_util, tx_util)
|
||||
self.pifs[pifname] = stats
|
||||
|
||||
for domid in self._domain_vcpus_util.keys():
|
||||
if domid not in active_domids:
|
||||
|
||||
@@ -482,10 +482,10 @@ class XendNode:
|
||||
return vbd_loads[domid].get(vbdid, (0.0, 0.0))
|
||||
return (0.0, 0.0)
|
||||
|
||||
def get_pif_util(self, pifid):
|
||||
def get_pif_util(self, pifname):
|
||||
pifs_util = self.monitor.get_pifs_util()
|
||||
if pifid in pifs_util:
|
||||
return pifs_util[pifid]
|
||||
if pifname in pifs_util:
|
||||
return pifs_util[pifname]
|
||||
return (0.0, 0.0)
|
||||
|
||||
# dictionary version of *info() functions to get rid of
|
||||
|
||||
@@ -115,10 +115,12 @@ class XendPIF:
|
||||
return success
|
||||
|
||||
def get_io_read_kbs(self):
|
||||
return 0.0
|
||||
from xen.xend.XendNode import instance as xennode
|
||||
return xennode().get_pif_util(self.name)[0]
|
||||
|
||||
def get_io_write_kbs(self):
|
||||
return 0.0
|
||||
from xen.xend.XendNode import instance as xennode
|
||||
return xennode().get_pif_util(self.name)[1]
|
||||
|
||||
def get_record(self, transient = True):
|
||||
result = {'name': self.name,
|
||||
|
||||