1
#============================================================================
2
# This library is free software; you can redistribute it and/or
3
# modify it under the terms of version 2.1 of the GNU Lesser General Public
4
# License as published by the Free Software Foundation.
6
# This library is distributed in the hope that it will be useful,
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
# Lesser General Public License for more details.
11
# You should have received a copy of the GNU Lesser General Public
12
# License along with this library; if not, write to the Free Software
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
#============================================================================
15
# Copyright (c) 2006-2007 Xensource Inc.
16
# Copyright (c) 2007 Tom Wilkie
17
#============================================================================
19
from xen.xend.XendLogging import log
20
from xen.xend.XendBase import XendBase
21
import xen.lowlevel.xc
23
xc = xen.lowlevel.xc.xc()
25
class XendVMMetrics(XendBase):
32
attrRO = ['memory_actual',
41
return XendBase.getAttrRO() + attrRO
43
getClass = classmethod(getClass)
44
getAttrRO = classmethod(getAttrRO)
46
def __init__(self, uuid, xend_domain_instance):
47
XendBase.__init__(self, uuid, {})
48
self.xend_domain_instance = xend_domain_instance
50
def get_memory_actual(self):
51
domInfo = self.xend_domain_instance.getDomInfo()
53
return domInfo["mem_kb"] * 1024
57
def get_VCPUs_number(self):
58
domInfo = self.xend_domain_instance.getDomInfo()
60
return domInfo["online_vcpus"]
64
def get_VCPUs_utilisation(self):
65
return self.xend_domain_instance.get_vcpus_util()
67
def get_VCPUs_CPU(self):
68
domid = self.xend_domain_instance.getDomid()
71
vcpus_max = self.xend_domain_instance.info['VCPUs_max']
72
for i in range(0, vcpus_max):
73
info = xc.vcpu_getinfo(domid, i)
74
vcpus_cpu[i] = info['cpu']
79
def get_VCPUs_flags(self):
80
domid = self.xend_domain_instance.getDomid()
83
vcpus_max = self.xend_domain_instance.info['VCPUs_max']
84
for i in range(0, vcpus_max):
85
info = xc.vcpu_getinfo(domid, i)
93
vcpus_flags[i] = flags
100
domid = self.xend_domain_instance.getDomid()
101
domlist = xc.domain_getinfo(domid, 1)
102
if domlist and domid == domlist[0]['domid']:
107
if dominfo[key] == 1:
117
except Exception, err:
118
# ignore missing domain
119
log.trace("domain_getinfo(%d) failed, ignoring: %s", domid, str(err))
122
def get_VCPUs_params(self):
123
domid = self.xend_domain_instance.getDomid()
124
if domid is not None:
126
vcpus_max = self.xend_domain_instance.info['VCPUs_max']
127
for i in range(0, vcpus_max):
128
info = xc.vcpu_getinfo(domid, i)
129
params_live['cpumap%i' % i] = \
130
",".join(map(str, info['cpumap']))
132
params_live.update(xc.sched_credit_domain_get(domid))
138
def get_start_time(self):
139
import xen.xend.XendAPI as XendAPI
140
return XendAPI.datetime(
141
self.xend_domain_instance.info.get("start_time", 0))
143
def get_last_updated(self):
144
import xen.xend.XendAPI as XendAPI