Merge "compute: create one pollster to rule them all"

This commit is contained in:
Jenkins 2017-03-21 16:21:24 +00:00 committed by Gerrit Code Review
commit 24ae1e9423
20 changed files with 473 additions and 1009 deletions

View File

@ -14,12 +14,17 @@
import abc
from oslo_log import log
from oslo_utils import timeutils
import six
from ceilometer.agent import plugin_base
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.i18n import _LE, _LW
from ceilometer import sample
LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
@ -92,3 +97,82 @@ class BaseComputePollster(plugin_base.PollsterBase):
additional_metadata={'disk_name': disk},
))
return samples
class GenericComputePollster(BaseComputePollster):
"""This class aims to cache instance statistics data
First polled pollsters that inherit of this will retrieve and cache
stats of an instance, then other pollsters will just build the samples
without querying the backend anymore.
"""
sample_name = None
sample_unit = ''
sample_type = sample.TYPE_GAUGE
sample_stats_key = None
@staticmethod
def get_additional_metadata(instance, stats):
pass
def _inspect_cached(self, cache, instance, duration):
cache.setdefault(self.cache_key, {})
if instance.id not in cache[self.cache_key]:
stats = self.inspector.inspect_instance(instance, duration)
cache[self.cache_key][instance.id] = stats
return cache[self.cache_key][instance.id]
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
try:
stats = self._inspect_cached(cache, instance,
self._inspection_duration)
volume = getattr(stats, self.sample_stats_key)
LOG.debug("%(instance_id)s/%(name)s volume: "
"%(volume)s" % {
'name': self.sample_name,
'instance_id': instance.id,
'volume': (volume if volume is not None
else 'Unavailable')})
if volume is None:
# FIXME(sileht): This should be a removed... but I will
# not change the test logic for now
LOG.warning(_LW("%(name)s statistic in not available for "
"instance %(instance_id)s") %
{'name': self.sample_name,
'instance_id': instance.id})
continue
yield util.make_sample_from_instance(
self.conf,
instance,
name=self.sample_name,
unit=self.sample_unit,
type=self.sample_type,
volume=volume,
additional_metadata=self.get_additional_metadata(
instance, stats),
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting sample of %(name)s: %(exc)s',
{'instance_id': instance.id,
'name': self.sample_name, 'exc': e})
except virt_inspector.NoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.error(
_LE('Could not get %(name)s events for %(id)s: %(e)s'), {
'name': self.sample_name, 'id': instance.id, 'e': err},
exc_info=True)

View File

@ -1,136 +0,0 @@
#
# Copyright 2012 eNovance <licensing@enovance.com>
# Copyright 2012 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log
import ceilometer
from ceilometer.agent import plugin_base
from ceilometer.compute import pollsters
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.i18n import _, _LE
from ceilometer import sample
LOG = log.getLogger(__name__)
class CPUPollster(pollsters.BaseComputePollster):
def get_samples(self, manager, cache, resources):
for instance in resources:
LOG.debug('checking instance %s', instance.id)
try:
cpu_info = self.inspector.inspect_cpus(instance)
LOG.debug("CPUTIME USAGE: %(instance)s %(time)d",
{'instance': instance,
'time': cpu_info.time})
cpu_num = {'cpu_number': cpu_info.number}
yield util.make_sample_from_instance(
self.conf,
instance,
name='cpu',
type=sample.TYPE_CUMULATIVE,
unit='ns',
volume=cpu_info.time,
additional_metadata=cpu_num,
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting samples of %(pollster)s: %(exc)s',
{'instance_id': instance.id,
'pollster': self.__class__.__name__, 'exc': e})
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining CPU time is not implemented for %s',
self.inspector.__class__.__name__)
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.exception(_LE('could not get CPU time for %(id)s: %(e)s'),
{'id': instance.id, 'e': err})
class CPUUtilPollster(pollsters.BaseComputePollster):
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
LOG.debug('Checking CPU util for instance %s', instance.id)
try:
cpu_info = self.inspector.inspect_cpu_util(
instance, self._inspection_duration)
LOG.debug("CPU UTIL: %(instance)s %(util)d",
{'instance': instance,
'util': cpu_info.util})
yield util.make_sample_from_instance(
self.conf,
instance,
name='cpu_util',
type=sample.TYPE_GAUGE,
unit='%',
volume=cpu_info.util,
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining CPU Util is not implemented for %s',
self.inspector.__class__.__name__)
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.exception(_LE('Could not get CPU Util for %(id)s: %(e)s'),
{'id': instance.id, 'e': err})
class CPUL3CachePollster(pollsters.BaseComputePollster):
def get_samples(self, manager, cache, resources):
for instance in resources:
LOG.debug(_('checking cache usage for instance %s'), instance.id)
try:
cpu_cache = self.inspector.inspect_cpu_l3_cache(instance)
LOG.debug(_("CPU cache size: %(id)s %(cache_size)d"),
({'id': instance.id,
'cache_size': cpu_cache.l3_cache_usage}))
yield util.make_sample_from_instance(
self.conf,
instance,
name='cpu_l3_cache',
type=sample.TYPE_GAUGE,
unit='B',
volume=cpu_cache.l3_cache_usage,
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.NoDataException as e:
LOG.warning(('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
raise plugin_base.PollsterPermanentError(resources)
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining cache usage is not implemented for %s',
self.inspector.__class__.__name__)
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.exception(
_LE('Could not get cache usage for %(id)s: %(e)s'),
{'id': instance.id, 'e': err})

View File

@ -0,0 +1,89 @@
#
# Copyright 2012 eNovance <licensing@enovance.com>
# Copyright 2012 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ceilometer.compute import pollsters
from ceilometer import sample
class InstanceStatsPollster(pollsters.GenericComputePollster):
cache_key = "instance_stats"
class CPUPollster(InstanceStatsPollster):
sample_name = 'cpu'
sample_unit = 'ns'
sample_stats_key = 'cpu_time'
sample_type = sample.TYPE_CUMULATIVE
@staticmethod
def get_additional_metadata(instance, c_data):
return {'cpu_number': c_data.cpu_number}
class CPUUtilPollster(InstanceStatsPollster):
sample_name = 'cpu_util'
sample_unit = '%'
sample_stats_key = 'cpu_util'
class MemoryUsagePollster(InstanceStatsPollster):
sample_name = 'memory.usage'
sample_unit = 'MB'
sample_stats_key = 'memory_usage'
class MemoryResidentPollster(InstanceStatsPollster):
sample_name = 'memory.resident'
sample_unit = 'MB'
sample_stats_key = 'memory_resident'
class PerfCPUCyclesPollster(InstanceStatsPollster):
sample_name = 'perf.cpu.cycles'
sample_stats_key = 'cpu_cycles'
class PerfInstructionsPollster(InstanceStatsPollster):
sample_name = 'perf.instructions'
sample_stats_key = 'instructions'
class PerfCacheReferencesPollster(InstanceStatsPollster):
sample_name = 'perf.cache.references'
sample_stats_key = 'cache_references'
class PerfCacheMissesPollster(InstanceStatsPollster):
sample_name = 'perf.cache.misses'
sample_stats_key = 'cache_misses'
class MemoryBandwidthTotalPollster(InstanceStatsPollster):
sample_name = 'memory.bandwidth.total'
sample_unit = 'B/s'
sample_stats_key = 'memory_bandwidth_total'
class MemoryBandwidthLocalPollster(InstanceStatsPollster):
sample_name = 'memory.bandwidth.local'
sample_unit = 'B/s'
sample_stats_key = 'memory_bandwidth_local'
class CPUL3CachePollster(InstanceStatsPollster):
sample_name = 'cpu_l3_cache'
sample_unit = 'B'
sample_stats_key = "cpu_l3_cache_usage"

View File

@ -1,208 +0,0 @@
# Copyright (c) 2014 VMware, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import collections
from oslo_log import log
import ceilometer
from ceilometer.agent import plugin_base
from ceilometer.compute import pollsters
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.i18n import _LE, _LW
from ceilometer import sample
LOG = log.getLogger(__name__)
MemoryBandwidthData = collections.namedtuple('MemoryBandwidthData',
['total', 'local'])
class MemoryUsagePollster(pollsters.BaseComputePollster):
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
LOG.debug('Checking memory usage for instance %s', instance.id)
try:
memory_info = self.inspector.inspect_memory_usage(
instance, self._inspection_duration)
LOG.debug("MEMORY USAGE: %(instance)s %(usage)f",
{'instance': instance,
'usage': memory_info.usage})
yield util.make_sample_from_instance(
self.conf,
instance,
name='memory.usage',
type=sample.TYPE_GAUGE,
unit='MB',
volume=memory_info.usage,
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting samples of %(pollster)s: %(exc)s',
{'instance_id': instance.id,
'pollster': self.__class__.__name__, 'exc': e})
except virt_inspector.InstanceNoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
except virt_inspector.NoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
raise plugin_base.PollsterPermanentError(resources)
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining Memory Usage is not implemented for %s',
self.inspector.__class__.__name__)
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.exception(_LE('Could not get Memory Usage for '
'%(id)s: %(e)s'), {'id': instance.id,
'e': err})
class MemoryResidentPollster(pollsters.BaseComputePollster):
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
LOG.debug('Checking resident memory for instance %s',
instance.id)
try:
memory_info = self.inspector.inspect_memory_resident(
instance, self._inspection_duration)
LOG.debug("RESIDENT MEMORY: %(instance)s %(resident)f",
{'instance': instance,
'resident': memory_info.resident})
yield util.make_sample_from_instance(
self.conf,
instance,
name='memory.resident',
type=sample.TYPE_GAUGE,
unit='MB',
volume=memory_info.resident,
)
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting samples of %(pollster)s: %(exc)s',
{'instance_id': instance.id,
'pollster': self.__class__.__name__, 'exc': e})
except virt_inspector.NoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining Resident Memory is not implemented'
' for %s', self.inspector.__class__.__name__)
raise plugin_base.PollsterPermanentError(resources)
except Exception as err:
LOG.exception(_LE('Could not get Resident Memory Usage for '
'%(id)s: %(e)s'), {'id': instance.id,
'e': err})
class _MemoryBandwidthPollster(pollsters.BaseComputePollster):
CACHE_KEY_MEMORY_BANDWIDTH = 'memory-bandwidth'
def _populate_cache(self, inspector, cache, instance):
i_cache = cache.setdefault(self.CACHE_KEY_MEMORY_BANDWIDTH, {})
if instance.id not in i_cache:
memory_bandwidth = self.inspector.inspect_memory_bandwidth(
instance, self._inspection_duration)
i_cache[instance.id] = MemoryBandwidthData(
memory_bandwidth.total,
memory_bandwidth.local,
)
return i_cache[instance.id]
@abc.abstractmethod
def _get_samples(self, instance, c_data):
"""Return one or more Samples."""
def _get_sample_total_and_local(self, instance, _name, _unit,
c_data, _element):
"""Total / local Pollster and return one Sample"""
return [util.make_sample_from_instance(
self.conf,
instance,
name=_name,
type=sample.TYPE_GAUGE,
unit=_unit,
volume=getattr(c_data, _element),
)]
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
try:
c_data = self._populate_cache(
self.inspector,
cache,
instance,
)
for s in self._get_samples(instance, c_data):
yield s
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting samples of %(pollster)s: %(exc)s',
{'instance_id': instance.id,
'pollster': self.__class__.__name__, 'exc': e})
except virt_inspector.NoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
raise plugin_base.PollsterPermanentError(resources)
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining memory bandwidth is not implemented'
' for %s', self.inspector.__class__.__name__)
except Exception as err:
LOG.exception(_LE('Could not get memory bandwidth for '
'%(id)s: %(e)s'), {'id': instance.id,
'e': err})
class MemoryBandwidthTotalPollster(_MemoryBandwidthPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'memory.bandwidth.total', 'B/s', c_data, 'total')
class MemoryBandwidthLocalPollster(_MemoryBandwidthPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'memory.bandwidth.local', 'B/s', c_data, 'local')

View File

@ -1,129 +0,0 @@
# Copyright 2016 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import collections
from oslo_log import log
import ceilometer
from ceilometer.agent import plugin_base
from ceilometer.compute import pollsters
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.i18n import _LE, _LW
from ceilometer import sample
LOG = log.getLogger(__name__)
PerfEventsData = collections.namedtuple('PerfEventsData',
['cpu_cycles', 'instructions',
'cache_references', 'cache_misses'])
class _PerfEventsPollster(pollsters.BaseComputePollster):
CACHE_KEY_MEMORY_BANDWIDTH = 'perf-events'
def _populate_cache(self, inspector, cache, instance):
i_cache = cache.setdefault(self.CACHE_KEY_MEMORY_BANDWIDTH, {})
if instance.id not in i_cache:
perf_events = self.inspector.inspect_perf_events(
instance, self._inspection_duration)
i_cache[instance.id] = PerfEventsData(
perf_events.cpu_cycles,
perf_events.instructions,
perf_events.cache_references,
perf_events.cache_misses,
)
return i_cache[instance.id]
@abc.abstractmethod
def _get_samples(self, instance, c_data):
"""Return one or more Samples."""
def _get_sample_total_and_local(self, instance, _name, _unit,
c_data, _element):
"""Total / local Pollster and return one Sample"""
return [util.make_sample_from_instance(
self.conf,
instance,
name=_name,
type=sample.TYPE_GAUGE,
unit=_unit,
volume=getattr(c_data, _element),
)]
def get_samples(self, manager, cache, resources):
self._inspection_duration = self._record_poll_time()
for instance in resources:
try:
c_data = self._populate_cache(
self.inspector,
cache,
instance,
)
for s in self._get_samples(instance, c_data):
yield s
except virt_inspector.InstanceNotFoundException as err:
# Instance was deleted while getting samples. Ignore it.
LOG.debug('Exception while getting samples %s', err)
except virt_inspector.InstanceShutOffException as e:
LOG.debug('Instance %(instance_id)s was shut off while '
'getting samples of %(pollster)s: %(exc)s',
{'instance_id': instance.id,
'pollster': self.__class__.__name__, 'exc': e})
except virt_inspector.NoDataException as e:
LOG.warning(_LW('Cannot inspect data of %(pollster)s for '
'%(instance_id)s, non-fatal reason: %(exc)s'),
{'pollster': self.__class__.__name__,
'instance_id': instance.id, 'exc': e})
raise plugin_base.PollsterPermanentError(resources)
except ceilometer.NotImplementedError:
# Selected inspector does not implement this pollster.
LOG.debug('Obtaining perf events is not implemented'
' for %s', self.inspector.__class__.__name__)
except Exception as err:
LOG.exception(_LE('Could not get perf events for '
'%(id)s: %(e)s'), {'id': instance.id,
'e': err})
class PerfEventsCPUCyclesPollster(_PerfEventsPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'perf.cpu.cycles', '', c_data, 'cpu_cycles')
class PerfEventsInstructionsPollster(_PerfEventsPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'perf.instructions', '', c_data, 'instructions')
class PerfEventsCacheReferencesPollster(_PerfEventsPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'perf.cache.references', '', c_data, 'cache_references')
class PerfEventsCacheMissesPollster(_PerfEventsPollster):
def _get_samples(self, instance, c_data):
return self._get_sample_total_and_local(
instance, 'perf.cache.misses', '', c_data, 'cache_misses')

View File

@ -91,22 +91,19 @@ class HyperVInspector(virt_inspector.Inspector):
return float(host_cpu_clock * host_cpu_count)
def inspect_cpus(self, instance):
def inspect_instance(self, instance, duration=None):
instance_name = util.instance_name(instance)
(cpu_clock_used,
cpu_count, uptime) = self._utils.get_cpu_metrics(instance_name)
cpu_percent_used = cpu_clock_used / self._host_max_cpu_clock
# Nanoseconds
cpu_time = (int(uptime * cpu_percent_used) * units.k)
memory_usage = self._utils.get_memory_metrics(instance_name)
return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)
def inspect_memory_usage(self, instance, duration=None):
instance_name = util.instance_name(instance)
usage = self._utils.get_memory_metrics(instance_name)
return virt_inspector.MemoryUsageStats(usage=usage)
return virt_inspector.InstanceStats(
cpu_number=cpu_count,
cpu_time=cpu_time,
memory_usage=memory_usage)
def inspect_vnics(self, instance):
instance_name = util.instance_name(instance)

View File

@ -35,6 +35,36 @@ OPTS = [
LOG = log.getLogger(__name__)
# Named tuple representing instance statistics
class InstanceStats(object):
fields = [
'cpu_number', # number: number of CPUs
'cpu_time', # time: cumulative CPU time
'cpu_util', # util: CPU utilization in percentage
'cpu_l3_cache_usage', # cachesize: Amount of CPU L3 cache used
'memory_usage', # usage: Amount of memory used
'memory_resident', #
'memory_bandwidth_total', # total: total system bandwidth from one
# level of cache
'memory_bandwidth_local', # local: bandwidth of memory traffic for a
# memory controller
'cpu_cycles', # cpu_cycles: the number of cpu cycles one
# instruction needs
'instructions', # instructions: the count of instructions
'cache_references', # cache_references: the count of cache hits
'cache_misses', # cache_misses: the count of caches misses
]
def __init__(self, **kwargs):
for k in self.fields:
setattr(self, k, kwargs.pop(k, None))
if kwargs:
raise AttributeError(
"'InstanceStats' object has no attributes '%s'" % kwargs)
# Named tuple representing instances.
#
# name: the name of the instance
@ -43,62 +73,6 @@ LOG = log.getLogger(__name__)
Instance = collections.namedtuple('Instance', ['name', 'UUID'])
# Named tuple representing CPU statistics.
#
# number: number of CPUs
# time: cumulative CPU time
#
CPUStats = collections.namedtuple('CPUStats', ['number', 'time'])
# Named tuple representing CPU Utilization statistics.
#
# util: CPU utilization in percentage
#
CPUUtilStats = collections.namedtuple('CPUUtilStats', ['util'])
# Named tuple representing CPU L3 cache usage statistics.
#
# cachesize: Amount of CPU L3 cache used
#
CPUL3CacheUsageStats = collections.namedtuple('CPUL3CacheUsageStats',
['l3_cache_usage'])
# Named tuple representing Memory usage statistics.
#
# usage: Amount of memory used
#
MemoryUsageStats = collections.namedtuple('MemoryUsageStats', ['usage'])
# Named tuple representing Resident Memory usage statistics.
#
# resident: Amount of resident memory
#
MemoryResidentStats = collections.namedtuple('MemoryResidentStats',
['resident'])
# Named tuple representing memory bandwidth statistics.
#
# total: total system bandwidth from one level of cache
# local: bandwidth of memory traffic for a memory controller
#
MemoryBandwidthStats = collections.namedtuple('MemoryBandwidthStats',
['total', 'local'])
# Named tuple representing perf events statistics.
#
# cpu_cycles: the number of cpu cycles one instruction needs
# instructions: the count of instructions
# cache_references: the count of cache hits
# cache_misses: the count of caches misses
#
PerfEventsStats = collections.namedtuple('PerfEventsStats',
['cpu_cycles', 'instructions',
'cache_references', 'cache_misses'])
# Named tuple representing vNICs.
#
# name: the name of the vNIC
@ -208,10 +182,6 @@ class InstanceShutOffException(InspectorException):
pass
class InstanceNoDataException(InspectorException):
pass
class NoDataException(InspectorException):
pass
@ -223,29 +193,13 @@ class Inspector(object):
def __init__(self, conf):
self.conf = conf
def inspect_cpus(self, instance):
def inspect_instance(self, instance, duration=None):
"""Inspect the CPU statistics for an instance.
:param instance: the target instance
:return: the number of CPUs and cumulative CPU time
"""
raise ceilometer.NotImplementedError
def inspect_cpu_util(self, instance, duration=None):
"""Inspect the CPU Utilization (%) for an instance.
:param instance: the target instance
:param duration: the last 'n' seconds, over which the value should be
inspected
:return: the percentage of CPU utilization
"""
raise ceilometer.NotImplementedError
def inspect_cpu_l3_cache(self, instance):
"""Inspect the CPU L3 cache usage for an instance.
:param instance: the target instance
:return: the amount of cpu l3 cache used
:return: the instance stats
"""
raise ceilometer.NotImplementedError
@ -278,36 +232,6 @@ class Inspector(object):
"""
raise ceilometer.NotImplementedError
def inspect_memory_usage(self, instance, duration=None):
"""Inspect the memory usage statistics for an instance.
:param instance: the target instance
:param duration: the last 'n' seconds, over which the value should be
inspected
:return: the amount of memory used
"""
raise ceilometer.NotImplementedError
def inspect_memory_resident(self, instance, duration=None):
"""Inspect the resident memory statistics for an instance.
:param instance: the target instance
:param duration: the last 'n' seconds, over which the value should be
inspected
:return: the amount of resident memory
"""
raise ceilometer.NotImplementedError
def inspect_memory_bandwidth(self, instance, duration=None):
"""Inspect the memory bandwidth statistics for an instance.
:param instance: the target instance
:param duration: the last 'n' seconds, over which the value should be
inspected
:return:
"""
raise ceilometer.NotImplementedError
def inspect_disk_rates(self, instance, duration=None):
"""Inspect the disk statistics as rates for an instance.
@ -343,16 +267,6 @@ class Inspector(object):
"""
raise ceilometer.NotImplementedError
def inspect_perf_events(self, instance, duration=None):
"""Inspect the perf events statistics for an instance.
:param instance: the target instance
:param duration: the last 'n' seconds, over which the value should be
inspected
:return:
"""
raise ceilometer.NotImplementedError
def get_hypervisor_inspector(conf):
try:

View File

@ -61,26 +61,6 @@ class LibvirtInspector(virt_inspector.Inspector):
except Exception as ex:
raise virt_inspector.InspectorException(six.text_type(ex))
@libvirt_utils.retry_on_disconnect
def inspect_cpus(self, instance):
domain = self._get_domain_not_shut_off_or_raise(instance)
# TODO(gordc): this can probably be cached since it can be used to get
# all data related
stats = self.connection.domainListGetStats([domain])
dom_stat = stats[0][1]
return virt_inspector.CPUStats(number=dom_stat['vcpu.current'],
time=dom_stat['cpu.time'])
@libvirt_utils.raise_nodata_if_unsupported("l3 cache usage")
@libvirt_utils.retry_on_disconnect
def inspect_cpu_l3_cache(self, instance):
domain = self._lookup_by_uuid(instance)
stats = self.connection.domainListGetStats(
[domain], libvirt.VIR_DOMAIN_STATS_PERF)
perf = stats[0][1]
usage = perf["perf.cmt"]
return virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=usage)
def _get_domain_not_shut_off_or_raise(self, instance):
instance_name = util.instance_name(instance)
domain = self._lookup_by_uuid(instance)
@ -148,18 +128,6 @@ class LibvirtInspector(virt_inspector.Inspector):
errors=block_stats[4])
yield (disk, stats)
@libvirt_utils.raise_nodata_if_unsupported("memory usge", False)
@libvirt_utils.retry_on_disconnect
def inspect_memory_usage(self, instance, duration=None):
domain = self._get_domain_not_shut_off_or_raise(instance)
memory_stats = domain.memoryStats()
memory_used = (memory_stats['available'] -
memory_stats['unused'])
# Stat provided from libvirt is in KB, converting it to MB.
memory_used = memory_used / units.Ki
return virt_inspector.MemoryUsageStats(usage=memory_used)
@libvirt_utils.retry_on_disconnect
def inspect_disk_info(self, instance):
domain = self._get_domain_not_shut_off_or_raise(instance)
@ -188,32 +156,34 @@ class LibvirtInspector(virt_inspector.Inspector):
physical=block_info[2])
yield (dsk, info)
@libvirt_utils.raise_nodata_if_unsupported
@libvirt_utils.retry_on_disconnect
def inspect_memory_resident(self, instance, duration=None):
domain = self._get_domain_not_shut_off_or_raise(instance)
memory = domain.memoryStats()['rss'] / units.Ki
return virt_inspector.MemoryResidentStats(resident=memory)
@libvirt_utils.raise_nodata_if_unsupported("memory bandwidth")
@libvirt_utils.retry_on_disconnect
def inspect_memory_bandwidth(self, instance, duration=None):
domain = self._get_domain_not_shut_off_or_raise(instance)
stats = self.connection.domainListGetStats(
[domain], libvirt.VIR_DOMAIN_STATS_PERF)
perf = stats[0][1]
return virt_inspector.MemoryBandwidthStats(total=perf["perf.mbmt"],
local=perf["perf.mbml"])
@libvirt_utils.raise_nodata_if_unsupported("perf events")
@libvirt_utils.retry_on_disconnect
def inspect_perf_events(self, instance, duration=None):
def inspect_instance(self, instance, duration=None):
domain = self._get_domain_not_shut_off_or_raise(instance)
stats = self.connection.domainListGetStats(
[domain], libvirt.VIR_DOMAIN_STATS_PERF)
perf = stats[0][1]
return virt_inspector.PerfEventsStats(
cpu_cycles=perf["perf.cpu_cycles"],
instructions=perf["perf.instructions"],
cache_references=perf["perf.cache_references"],
cache_misses=perf["perf.cache_misses"])
memory_used = memory_resident = None
memory_stats = domain.memoryStats()
# Stat provided from libvirt is in KB, converting it to MB.
if 'available' in memory_stats and 'unused' in memory_stats:
memory_used = (memory_stats['available'] -
memory_stats['unused']) / units.Ki
if 'rss' in memory_stats:
memory_resident = memory_stats['rss'] / units.Ki
# TODO(sileht): stats also have the disk/vnic info
# we could use that instead of the old method for Queen
stats = self.connection.domainListGetStats([domain], 0)[0][1]
return virt_inspector.InstanceStats(
cpu_number=stats.get('vcpu.current'),
cpu_time=stats.get('cpu.time'),
memory_usage=memory_used,
memory_resident=memory_resident,
cpu_cycles=stats.get("perf.cpu_cycles"),
instructions=stats.get("perf.instructions"),
cache_references=stats.get("perf.cache_references"),
cache_misses=stats.get("perf.cache_misses"),
memory_bandwidth_total=stats.get("perf.mbmt"),
memory_bandwidth_local=stats.get("perf.mbml"),
cpu_l3_cache_usage=stats.get("perf.cmt"),
)

View File

@ -109,25 +109,16 @@ retry_on_disconnect = tenacity.retry(
stop=tenacity.stop_after_attempt(2))
class raise_nodata_if_unsupported(object):
def __init__(self, meter, permanent=True):
self.meter = meter
self.permanent = permanent
def __call__(self, method):
def inner(in_self, instance, *args, **kwargs):
try:
return method(in_self, instance, *args, **kwargs)
except (libvirt.libvirtError, KeyError, AttributeError) as e:
# NOTE(sileht): At this point libvirt connection error
# have been reraise as tenacity.RetryError()
msg = _LE('Failed to inspect %(meter)s of %(instance_uuid)s, '
'can not get info from libvirt: %(error)s') % {
"meter": self.meter,
"instance_uuid": instance.id,
"error": e}
if self.permanent:
raise virt_inspector.NoDataException(msg)
else:
raise virt_inspector.InstanceNoDataException(msg)
return inner
def raise_nodata_if_unsupported(method):
def inner(in_self, instance, *args, **kwargs):
try:
return method(in_self, instance, *args, **kwargs)
except libvirt.libvirtError as e:
# NOTE(sileht): At this point libvirt connection error
# have been reraise as tenacity.RetryError()
msg = _LE('Failed to inspect instance %(instance_uuid)s stats, '
'can not get info from libvirt: %(error)s') % {
"instance_uuid": instance.id,
"error": e}
raise virt_inspector.NoDataException(msg)
return inner

View File

@ -114,20 +114,6 @@ class VsphereInspector(virt_inspector.Inspector):
return vm_mobj
def inspect_cpu_util(self, instance, duration=None):
vm_mobj = self._get_vm_mobj_not_power_off_or_raise(instance)
cpu_util_counter_id = self._ops.get_perf_counter_id(
VC_AVERAGE_CPU_CONSUMED_CNTR)
cpu_util = self._ops.query_vm_aggregate_stats(
vm_mobj, cpu_util_counter_id, duration)
# For this counter vSphere returns values scaled-up by 100, since the
# corresponding API can't return decimals, but only longs.
# For e.g. if the utilization is 12.34%, the value returned is 1234.
# Hence, dividing by 100.
cpu_util = cpu_util / 100
return virt_inspector.CPUUtilStats(util=cpu_util)
def inspect_vnic_rates(self, instance, duration=None):
vm_mobj = self._get_vm_mobj_not_power_off_or_raise(instance)
@ -164,16 +150,6 @@ class VsphereInspector(virt_inspector.Inspector):
parameters=None)
yield (interface, stats)
def inspect_memory_usage(self, instance, duration=None):
vm_mobj = self._get_vm_mobj_not_power_off_or_raise(instance)
mem_counter_id = self._ops.get_perf_counter_id(
VC_AVERAGE_MEMORY_CONSUMED_CNTR)
memory = self._ops.query_vm_aggregate_stats(
vm_mobj, mem_counter_id, duration)
# Stat provided from vSphere is in KB, converting it to MB.
memory = memory / units.Ki
return virt_inspector.MemoryUsageStats(usage=memory)
def inspect_disk_rates(self, instance, duration=None):
vm_mobj = self._get_vm_mobj_not_power_off_or_raise(instance)
@ -207,3 +183,26 @@ class VsphereInspector(virt_inspector.Inspector):
write_requests_rate=stat_val(VC_DISK_WRITE_REQUESTS_RATE_CNTR)
)
yield(disk, disk_rate_info)
def inspect_instance(self, instance, duration=None):
vm_mobj = self._get_vm_mobj_not_power_off_or_raise(instance)
cpu_util_counter_id = self._ops.get_perf_counter_id(
VC_AVERAGE_CPU_CONSUMED_CNTR)
cpu_util = self._ops.query_vm_aggregate_stats(
vm_mobj, cpu_util_counter_id, duration)
# For this counter vSphere returns values scaled-up by 100, since the
# corresponding API can't return decimals, but only longs.
# For e.g. if the utilization is 12.34%, the value returned is 1234.
# Hence, dividing by 100.
cpu_util = cpu_util / 100
mem_counter_id = self._ops.get_perf_counter_id(
VC_AVERAGE_MEMORY_CONSUMED_CNTR)
memory = self._ops.query_vm_aggregate_stats(
vm_mobj, mem_counter_id, duration)
# Stat provided from vSphere is in KB, converting it to MB.
memory = memory / units.Ki
return virt_inspector.InstanceStats(
cpu_util=cpu_util,
memory_usage=memory)

View File

@ -133,24 +133,27 @@ class XenapiInspector(virt_inspector.Inspector):
else:
return vm_refs[0]
def inspect_cpu_util(self, instance, duration=None):
def inspect_instance(self, instance, duration=None):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
cpu_util = self._get_cpu_usage(vm_ref, instance_name)
memory_usage = self._get_memory_usage(vm_ref)
return virt_inspector.InstanceStats(cpu_util=cpu_util,
memory_usage=memory_usage)
def _get_cpu_usage(self, vm_ref, instance_name):
vcpus_number = int(self._call_xenapi("VM.get_VCPUs_max", vm_ref))
if vcpus_number <= 0:
msg = _("Could not get VM %s CPU number") % instance_name
raise XenapiException(msg)
utils = 0.0
cpu_util = 0.0
for index in range(vcpus_number):
utils += float(self._call_xenapi("VM.query_data_source",
vm_ref,
"cpu%d" % index))
utils = utils / int(vcpus_number) * 100
return virt_inspector.CPUUtilStats(util=utils)
cpu_util += float(self._call_xenapi("VM.query_data_source",
vm_ref,
"cpu%d" % index))
return cpu_util / int(vcpus_number) * 100
def inspect_memory_usage(self, instance, duration=None):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
def _get_memory_usage(self, vm_ref):
total_mem = float(self._call_xenapi("VM.query_data_source",
vm_ref,
"memory"))
@ -166,8 +169,7 @@ class XenapiInspector(virt_inspector.Inspector):
# memory provided from XenServer is in Bytes;
# memory_internal_free provided from XenServer is in KB,
# converting it to MB.
memory_usage = (total_mem - free_mem * units.Ki) / units.Mi
return virt_inspector.MemoryUsageStats(usage=memory_usage)
return (total_mem - free_mem * units.Ki) / units.Mi
def inspect_vnics(self, instance):
instance_name = util.instance_name(instance)

View File

@ -18,6 +18,7 @@ import mock
from oslo_config import fixture as fixture_config
from oslotest import mockpatch
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer import service
import ceilometer.tests.base as base
@ -57,3 +58,15 @@ class TestPollsterBase(base.BaseTestCase):
self.useFixture(mockpatch.Patch(
'ceilometer.compute.pollsters.BaseComputePollster._get_inspector',
return_value=self.inspector))
def _mock_inspect_instance(self, *data):
next_value = iter(data)
def inspect(instance, duration):
value = next(next_value)
if isinstance(value, virt_inspector.InstanceStats):
return value
else:
raise value
self.inspector.inspect_instance = mock.Mock(side_effect=inspect)

View File

@ -19,7 +19,7 @@ import time
import mock
from ceilometer.agent import manager
from ceilometer.compute.pollsters import cpu
from ceilometer.compute.pollsters import instance_stats
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.tests.unit.compute.pollsters import base
@ -28,20 +28,15 @@ class TestCPUPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2),
virt_inspector.CPUStats(time=3 * (10 ** 6), number=2),
self._mock_inspect_instance(
virt_inspector.InstanceStats(cpu_time=1 * (10 ** 6), cpu_number=2),
virt_inspector.InstanceStats(cpu_time=3 * (10 ** 6), cpu_number=2),
# cpu_time resets on instance restart
virt_inspector.CPUStats(time=2 * (10 ** 6), number=2),
))
def inspect_cpus(name):
return next(next_value)
self.inspector.inspect_cpus = mock.Mock(side_effect=inspect_cpus)
virt_inspector.InstanceStats(cpu_time=2 * (10 ** 6), cpu_number=2),
)
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
def _verify_cpu_metering(expected_time):
cache = {}
@ -57,27 +52,13 @@ class TestCPUPollster(base.TestPollsterBase):
_verify_cpu_metering(3 * (10 ** 6))
_verify_cpu_metering(2 * (10 ** 6))
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples_no_caching(self):
cpu_stats = virt_inspector.CPUStats(time=1 * (10 ** 6), number=2)
self.inspector.inspect_cpus = mock.Mock(return_value=cpu_stats)
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
cache = {}
samples = list(pollster.get_samples(mgr, cache, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(10 ** 6, samples[0].volume)
self.assertEqual(0, len(cache))
# the following apply to all instance resource pollsters but are tested
# here alone.
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_metadata(self):
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(1, samples[0].resource_metadata['vcpus'])
@ -94,7 +75,7 @@ class TestCPUPollster(base.TestPollsterBase):
self.CONF.set_override('reserved_metadata_keys', ['fqdn'])
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual({'fqdn': 'vm_fqdn',
'stack': '2cadc4b4-8789-123c-b4eg-edd2f0a9c128'},
@ -103,21 +84,21 @@ class TestCPUPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_reserved_metadata_with_namespace(self):
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual({'stack': '2cadc4b4-8789-123c-b4eg-edd2f0a9c128'},
samples[0].resource_metadata['user_metadata'])
self.CONF.set_override('reserved_metadata_namespace', [])
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertNotIn('user_metadata', samples[0].resource_metadata)
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_flavor_name_as_metadata_instance_type(self):
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUPollster(self.CONF)
pollster = instance_stats.CPUPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual('m1.small',
@ -128,19 +109,13 @@ class TestCPUUtilPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.CPUUtilStats(util=40),
virt_inspector.CPUUtilStats(util=60),
))
def inspect_cpu_util(name, duration):
return next(next_value)
self.inspector.inspect_cpu_util = (mock.
Mock(side_effect=inspect_cpu_util))
self._mock_inspect_instance(
virt_inspector.InstanceStats(cpu_util=40),
virt_inspector.InstanceStats(cpu_util=60),
)
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUUtilPollster(self.CONF)
pollster = instance_stats.CPUUtilPollster(self.CONF)
def _verify_cpu_util_metering(expected_util):
cache = {}
@ -158,19 +133,13 @@ class TestCPUL3CachePollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=90112),
virt_inspector.CPUL3CacheUsageStats(l3_cache_usage=180224),
))
def inspect_cpu_l3_cache(name):
return next(next_value)
self.inspector.inspect_cpu_l3_cache = (mock.Mock(
side_effect=inspect_cpu_l3_cache))
self._mock_inspect_instance(
virt_inspector.InstanceStats(cpu_l3_cache_usage=90112),
virt_inspector.InstanceStats(cpu_l3_cache_usage=180224),
)
mgr = manager.AgentManager(0, self.CONF)
pollster = cpu.CPUL3CachePollster(self.CONF)
pollster = instance_stats.CPUL3CachePollster(self.CONF)
def _verify_cpu_l3_cache_metering(expected_usage):
cache = {}

View File

@ -17,7 +17,7 @@ import mock
from ceilometer.agent import manager
from ceilometer.agent import plugin_base
from ceilometer.compute.pollsters import memory
from ceilometer.compute.pollsters import instance_stats
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.tests.unit.compute.pollsters import base
@ -26,27 +26,17 @@ class TestMemoryPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.MemoryUsageStats(usage=1.0),
virt_inspector.MemoryUsageStats(usage=2.0),
virt_inspector.InstanceNoDataException(),
self._mock_inspect_instance(
virt_inspector.InstanceStats(memory_usage=1.0),
virt_inspector.InstanceStats(memory_usage=2.0),
virt_inspector.InstanceStats(),
virt_inspector.InstanceShutOffException(),
))
def inspect_memory_usage(instance, duration):
value = next(next_value)
if isinstance(value, virt_inspector.MemoryUsageStats):
return value
else:
raise value
self.inspector.inspect_memory_usage = mock.Mock(
side_effect=inspect_memory_usage)
)
mgr = manager.AgentManager(0, self.CONF)
pollster = memory.MemoryUsagePollster(self.CONF)
pollster = instance_stats.MemoryUsagePollster(self.CONF)
@mock.patch('ceilometer.compute.pollsters.memory.LOG')
@mock.patch('ceilometer.compute.pollsters.LOG')
def _verify_memory_metering(expected_count, expected_memory_mb,
expected_warnings, mylog):
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
@ -67,14 +57,9 @@ class TestMemoryPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples_with_empty_stats(self):
def inspect_memory_usage(instance, duration):
raise virt_inspector.NoDataException()
self.inspector.inspect_memory_usage = mock.Mock(
side_effect=inspect_memory_usage)
self._mock_inspect_instance(virt_inspector.NoDataException())
mgr = manager.AgentManager(0, self.CONF)
pollster = memory.MemoryUsagePollster(self.CONF)
pollster = instance_stats.MemoryUsagePollster(self.CONF)
def all_samples():
return list(pollster.get_samples(mgr, {}, [self.instance]))
@ -87,27 +72,17 @@ class TestResidentMemoryPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.MemoryResidentStats(resident=1.0),
virt_inspector.MemoryResidentStats(resident=2.0),
virt_inspector.NoDataException(),
self._mock_inspect_instance(
virt_inspector.InstanceStats(memory_resident=1.0),
virt_inspector.InstanceStats(memory_resident=2.0),
virt_inspector.InstanceStats(),
virt_inspector.InstanceShutOffException(),
))
def inspect_memory_resident(instance, duration):
value = next(next_value)
if isinstance(value, virt_inspector.MemoryResidentStats):
return value
else:
raise value
self.inspector.inspect_memory_resident = mock.Mock(
side_effect=inspect_memory_resident)
)
mgr = manager.AgentManager(0, self.CONF)
pollster = memory.MemoryResidentPollster(self.CONF)
pollster = instance_stats.MemoryResidentPollster(self.CONF)
@mock.patch('ceilometer.compute.pollsters.memory.LOG')
@mock.patch('ceilometer.compute.pollsters.LOG')
def _verify_resident_memory_metering(expected_count,
expected_resident_memory_mb,
expected_warnings, mylog):
@ -132,20 +107,17 @@ class TestMemoryBandwidthPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
next_value = iter((
virt_inspector.MemoryBandwidthStats(total=1892352, local=1802240),
virt_inspector.MemoryBandwidthStats(total=1081344, local=90112),
))
self._mock_inspect_instance(
virt_inspector.InstanceStats(memory_bandwidth_total=1892352,
memory_bandwidth_local=1802240),
virt_inspector.InstanceStats(memory_bandwidth_total=1081344,
memory_bandwidth_local=90112),
)
def inspect_memory_bandwidth(instance, duration):
return next(next_value)
self.inspector.inspect_memory_bandwidth = mock.Mock(
side_effect=inspect_memory_bandwidth)
mgr = manager.AgentManager(0, self.CONF)
def _check_memory_bandwidth_total(expected_usage):
pollster = memory.MemoryBandwidthTotalPollster(self.CONF)
pollster = instance_stats.MemoryBandwidthTotalPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual(1, len(samples))
@ -154,7 +126,7 @@ class TestMemoryBandwidthPollster(base.TestPollsterBase):
self.assertEqual(expected_usage, samples[0].volume)
def _check_memory_bandwidth_local(expected_usage):
pollster = memory.MemoryBandwidthLocalPollster(self.CONF)
pollster = instance_stats.MemoryBandwidthLocalPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertEqual(1, len(samples))
@ -167,18 +139,11 @@ class TestMemoryBandwidthPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples_with_empty_stats(self):
def inspect_memory_bandwidth(instance, duration):
raise virt_inspector.NoDataException()
self.inspector.inspect_memory_bandwidth = mock.Mock(
side_effect=inspect_memory_bandwidth)
self._mock_inspect_instance(virt_inspector.NoDataException())
mgr = manager.AgentManager(0, self.CONF)
pollster = memory.MemoryBandwidthTotalPollster(self.CONF)
pollster = instance_stats.MemoryBandwidthTotalPollster(self.CONF)
def all_samples():
return list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertRaises(plugin_base.PollsterPermanentError,
all_samples)
self.assertRaises(plugin_base.PollsterPermanentError, all_samples)

View File

@ -16,58 +16,56 @@ import mock
from ceilometer.agent import manager
from ceilometer.agent import plugin_base
from ceilometer.compute.pollsters import perf
from ceilometer.compute.pollsters import instance_stats
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.tests.unit.compute.pollsters import base
class TestPerfEventsPollster(base.TestPollsterBase):
class TestPerfPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples(self):
fake_value = virt_inspector.PerfEventsStats(cpu_cycles=7259361,
instructions=8815623,
cache_references=74184,
cache_misses=16737)
self._mock_inspect_instance(
virt_inspector.InstanceStats(cpu_cycles=7259361,
instructions=8815623,
cache_references=74184,
cache_misses=16737)
)
def inspect_perf_events(instance, duration):
return fake_value
self.inspector.inspect_perf_events = mock.Mock(
side_effect=inspect_perf_events)
mgr = manager.AgentManager(0, self.CONF)
cache = {}
def _check_perf_events_cpu_cycles(expected_usage):
pollster = perf.PerfEventsCPUCyclesPollster(self.CONF)
pollster = instance_stats.PerfCPUCyclesPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
samples = list(pollster.get_samples(mgr, cache, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(set(['perf.cpu.cycles']),
set([s.name for s in samples]))
self.assertEqual(expected_usage, samples[0].volume)
def _check_perf_events_instructions(expected_usage):
pollster = perf.PerfEventsInstructionsPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
pollster = instance_stats.PerfInstructionsPollster(self.CONF)
samples = list(pollster.get_samples(mgr, cache, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(set(['perf.instructions']),
set([s.name for s in samples]))
self.assertEqual(expected_usage, samples[0].volume)
def _check_perf_events_cache_references(expected_usage):
pollster = perf.PerfEventsCacheReferencesPollster(self.CONF)
pollster = instance_stats.PerfCacheReferencesPollster(
self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
samples = list(pollster.get_samples(mgr, cache, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(set(['perf.cache.references']),
set([s.name for s in samples]))
self.assertEqual(expected_usage, samples[0].volume)
def _check_perf_events_cache_misses(expected_usage):
pollster = perf.PerfEventsCacheMissesPollster(self.CONF)
pollster = instance_stats.PerfCacheMissesPollster(self.CONF)
samples = list(pollster.get_samples(mgr, {}, [self.instance]))
samples = list(pollster.get_samples(mgr, cache, [self.instance]))
self.assertEqual(1, len(samples))
self.assertEqual(set(['perf.cache.misses']),
set([s.name for s in samples]))
@ -80,18 +78,11 @@ class TestPerfEventsPollster(base.TestPollsterBase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_samples_with_empty_stats(self):
def inspect_perf_events(instance, duration):
raise virt_inspector.NoDataException()
self.inspector.inspect_perf_events = mock.Mock(
side_effect=inspect_perf_events)
self._mock_inspect_instance(virt_inspector.NoDataException())
mgr = manager.AgentManager(0, self.CONF)
pollster = perf.PerfEventsCPUCyclesPollster(self.CONF)
pollster = instance_stats.PerfCPUCyclesPollster(self.CONF)
def all_samples():
return list(pollster.get_samples(mgr, {}, [self.instance]))
self.assertRaises(plugin_base.PollsterPermanentError,
all_samples)
self.assertRaises(plugin_base.PollsterPermanentError, all_samples)

View File

@ -43,17 +43,20 @@ class TestHyperVInspection(base.BaseTestCase):
self._inspector._utils.get_cpu_metrics.side_effect = (
os_win_exc.OSWinException)
self.assertRaises(virt_inspector.InspectorException,
self._inspector.inspect_cpus, mock.sentinel.instance)
self._inspector.inspect_instance,
mock.sentinel.instance)
self._inspector._utils.get_cpu_metrics.side_effect = (
os_win_exc.HyperVException)
self.assertRaises(virt_inspector.InspectorException,
self._inspector.inspect_cpus, mock.sentinel.instance)
self._inspector.inspect_instance,
mock.sentinel.instance)
self._inspector._utils.get_cpu_metrics.side_effect = (
os_win_exc.NotFound(resource='foofoo'))
self.assertRaises(virt_inspector.InstanceNotFoundException,
self._inspector.inspect_cpus, mock.sentinel.instance)
self._inspector.inspect_instance,
mock.sentinel.instance)
def test_assert_original_traceback_maintained(self):
def bar(self):
@ -62,7 +65,7 @@ class TestHyperVInspection(base.BaseTestCase):
self._inspector._utils.get_cpu_metrics.side_effect = bar
try:
self._inspector.inspect_cpus(mock.sentinel.instance)
self._inspector.inspect_instance(mock.sentinel.instance)
self.fail("Test expected exception, but it was not raised.")
except virt_inspector.InstanceNotFoundException:
# exception has been raised as expected.
@ -83,7 +86,7 @@ class TestHyperVInspection(base.BaseTestCase):
cpu_clock = self._inspector._compute_host_max_cpu_clock()
self.assertEqual(2000.0, cpu_clock)
def test_inspect_cpus(self):
def test_inspect_instance(self):
fake_instance_name = 'fake_instance_name'
fake_cpu_clock_used = 2000
fake_cpu_count = 3000
@ -96,17 +99,13 @@ class TestHyperVInspection(base.BaseTestCase):
1000)
self._inspector._utils.get_cpu_metrics.return_value = (
fake_cpu_clock_used, fake_cpu_count, fake_uptime)
cpu_stats = self._inspector.inspect_cpus(fake_instance_name)
self.assertEqual(fake_cpu_count, cpu_stats.number)
self.assertEqual(fake_cpu_time, cpu_stats.time)
def test_inspect_memory_usage(self):
fake_usage = self._inspector._utils.get_memory_metrics.return_value
usage = self._inspector.inspect_memory_usage(
mock.sentinel.FAKE_INSTANCE, mock.sentinel.FAKE_DURATION)
self.assertEqual(fake_usage, usage.usage)
stats = self._inspector.inspect_instance(fake_instance_name)
self.assertEqual(fake_cpu_count, stats.cpu_number)
self.assertEqual(fake_cpu_time, stats.cpu_time)
self.assertEqual(fake_usage, stats.memory_usage)
def test_inspect_vnics(self):
fake_instance_name = 'fake_instance_name'

View File

@ -42,27 +42,47 @@ class TestLibvirtInspection(base.BaseTestCase):
self.instance = VMInstance()
libvirt_inspector.libvirt = mock.Mock()
libvirt_inspector.libvirt.getVersion.return_value = 5001001
libvirt_inspector.libvirt.VIR_DOMAIN_SHUTOFF = 5
libvirt_inspector.libvirt.libvirtError = FakeLibvirtError
utils.libvirt = libvirt_inspector.libvirt
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=None):
self.inspector = libvirt_inspector.LibvirtInspector(self.CONF)
self.domain = mock.Mock()
def test_inspect_cpus(self):
def test_inspect_instance_stats(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 0, None, None)
domain.info.return_value = (0, 0, 0, 2, 999999)
domain.memoryStats.return_value = {'available': 51200,
'unused': 25600,
'rss': 30000}
conn = mock.Mock()
conn.lookupByUUIDString.return_value = domain
conn.domainListGetStats.return_value = [({}, {'cpu.time': 999999,
'vcpu.current': 2})]
conn.domainListGetStats.return_value = [({}, {
'cpu.time': 999999,
'vcpu.current': 2,
'perf.cmt': 90112,
'perf.cpu_cycles': 7259361,
'perf.instructions': 8815623,
'perf.cache_references': 74184,
'perf.cache_misses': 16737,
'perf.mbmt': 1892352,
'perf.mbml': 1802240})]
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
cpu_info = self.inspector.inspect_cpus(self.instance)
self.assertEqual(2, cpu_info.number)
self.assertEqual(999999, cpu_info.time)
stats = self.inspector.inspect_instance(self.instance)
self.assertEqual(2, stats.cpu_number)
self.assertEqual(999999, stats.cpu_time)
self.assertEqual(90112, stats.cpu_l3_cache_usage)
self.assertEqual(25600 / units.Ki, stats.memory_usage)
self.assertEqual(30000 / units.Ki, stats.memory_resident)
self.assertEqual(1892352, stats.memory_bandwidth_total)
self.assertEqual(1802240, stats.memory_bandwidth_local)
self.assertEqual(7259361, stats.cpu_cycles)
self.assertEqual(8815623, stats.instructions)
self.assertEqual(74184, stats.cache_references)
self.assertEqual(16737, stats.cache_misses)
def test_inspect_cpus_with_domain_shutoff(self):
domain = mock.Mock()
@ -73,21 +93,9 @@ class TestLibvirtInspection(base.BaseTestCase):
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
self.assertRaises(virt_inspector.InstanceShutOffException,
self.inspector.inspect_cpus,
self.inspector.inspect_instance,
self.instance)
def test_inspect_cpu_l3_cache(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 0, 2, 999999)
conn = mock.Mock()
conn.domainListGetStats.return_value = [({}, {'perf.cmt': 90112})]
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
cpu_info = self.inspector.inspect_cpu_l3_cache(self.instance)
self.assertEqual(90112, cpu_info.l3_cache_usage)
def test_inspect_vnics(self):
dom_xml = """
<domain type='kvm'>
@ -259,18 +267,6 @@ class TestLibvirtInspection(base.BaseTestCase):
self.assertRaises(virt_inspector.InstanceShutOffException,
list, inspect(self.instance))
def test_inspect_memory_usage(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 0, 2, 999999)
domain.memoryStats.return_value = {'available': 51200, 'unused': 25600}
conn = mock.Mock()
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
memory = self.inspector.inspect_memory_usage(self.instance)
self.assertEqual(25600 / units.Ki, memory.usage)
def test_inspect_disk_info(self):
dom_xml = """
<domain type='kvm'>
@ -368,67 +364,43 @@ class TestLibvirtInspection(base.BaseTestCase):
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
self.assertRaises(virt_inspector.InstanceShutOffException,
self.inspector.inspect_memory_usage,
self.inspector.inspect_instance,
self.instance)
def test_inspect_memory_usage_with_empty_stats(self):
def test_inspect_memory_with_empty_stats(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 51200, 2, 999999)
domain.memoryStats.return_value = {}
conn = mock.Mock()
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
self.assertRaises(virt_inspector.InstanceNoDataException,
self.inspector.inspect_memory_usage,
self.instance)
def test_inspect_memory_bandwidth(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 51200, 2, 999999)
conn = mock.Mock()
conn.domainListGetStats.return_value = [
({}, {'perf.mbmt': 1892352, 'perf.mbml': 1802240})]
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
mb = self.inspector.inspect_memory_bandwidth(self.instance)
self.assertEqual(1892352, mb.total)
self.assertEqual(1802240, mb.local)
def test_inspect_perf_events(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 51200, 2, 999999)
conn = mock.Mock()
conn.domainListGetStats.return_value = [
({}, {'perf.cpu_cycles': 7259361,
'perf.instructions': 8815623,
'perf.cache_references': 74184,
'perf.cache_misses': 16737})]
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
pe = self.inspector.inspect_perf_events(self.instance)
self.assertEqual(7259361, pe.cpu_cycles)
self.assertEqual(8815623, pe.instructions)
self.assertEqual(74184, pe.cache_references)
self.assertEqual(16737, pe.cache_misses)
def test_inspect_perf_events_libvirt_less_than_2_3_0(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 51200, 2, 999999)
conn = mock.Mock()
conn.domainListGetStats.return_value = [({}, {})]
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
self.assertRaises(virt_inspector.NoDataException,
self.inspector.inspect_perf_events,
self.instance)
stats = self.inspector.inspect_instance(self.instance)
self.assertIsNone(stats.memory_usage)
self.assertIsNone(stats.memory_resident)
def test_inspect_perf_events_libvirt_less_than_2_3_0(self):
domain = mock.Mock()
domain.info.return_value = (0, 0, 51200, 2, 999999)
domain.memoryStats.return_value = {'rss': 0,
'available': 51200,
'unused': 25600}
conn = mock.Mock()
conn.domainListGetStats.return_value = [({}, {})]
conn.lookupByUUIDString.return_value = domain
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
'refresh_libvirt_connection', return_value=conn):
stats = self.inspector.inspect_instance(self.instance)
self.assertIsNone(stats.cpu_l3_cache_usage)
self.assertIsNone(stats.memory_bandwidth_total)
self.assertIsNone(stats.memory_bandwidth_local)
self.assertIsNone(stats.cpu_cycles)
self.assertIsNone(stats.instructions)
self.assertIsNone(stats.cache_references)
self.assertIsNone(stats.cache_misses)
class TestLibvirtInspectionWithError(base.BaseTestCase):
@ -447,4 +419,4 @@ class TestLibvirtInspectionWithError(base.BaseTestCase):
def test_inspect_unknown_error(self):
self.assertRaises(virt_inspector.InspectorException,
self.inspector.inspect_cpus, 'foo')
self.inspector.inspect_instance, 'foo')

View File

@ -76,7 +76,6 @@ class TestVsphereInspection(base.BaseTestCase):
test_vm_mobj.value = "vm-21"
fake_perf_counter_id = 'fake_perf_counter_id'
fake_memory_value = 1024.0
fake_stat = virt_inspector.MemoryUsageStats(usage=1.0)
self._inspector._get_vm_mobj_not_power_off_or_raise = mock.MagicMock()
self._inspector._get_vm_mobj_not_power_off_or_raise.return_value = (
@ -85,15 +84,14 @@ class TestVsphereInspection(base.BaseTestCase):
ops_mock = self._inspector._ops
ops_mock.get_perf_counter_id.return_value = fake_perf_counter_id
ops_mock.query_vm_aggregate_stats.return_value = fake_memory_value
memory_stat = self._inspector.inspect_memory_usage(mock.MagicMock())
self.assertEqual(fake_stat, memory_stat)
stats = self._inspector.inspect_instance(mock.MagicMock())
self.assertEqual(1.0, stats.memory_usage)
def test_inspect_cpu_util(self):
test_vm_mobj = mock.MagicMock()
test_vm_mobj.value = "vm-21"
fake_perf_counter_id = 'fake_perf_counter_id'
fake_cpu_util_value = 60
fake_stat = virt_inspector.CPUUtilStats(util=60)
self._inspector._get_vm_mobj_not_power_off_or_raise = mock.MagicMock()
self._inspector._get_vm_mobj_not_power_off_or_raise.return_value = (
@ -103,8 +101,8 @@ class TestVsphereInspection(base.BaseTestCase):
ops_mock.get_perf_counter_id.return_value = fake_perf_counter_id
(ops_mock.query_vm_aggregate_stats.
return_value) = fake_cpu_util_value * 100
cpu_util_stat = self._inspector.inspect_cpu_util(mock.MagicMock())
self.assertEqual(fake_stat, cpu_util_stat)
stats = self._inspector.inspect_instance(mock.MagicMock())
self.assertEqual(60, stats.cpu_util)
def test_inspect_vnic_rates(self):

View File

@ -18,7 +18,6 @@ import mock
from oslo_config import fixture as fixture_config
from oslotest import base
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.compute.virt.xenapi import inspector as xenapi_inspector
from ceilometer.tests.unit.compute.virt.xenapi import fake_XenAPI
@ -59,43 +58,24 @@ class TestXenapiInspection(base.BaseTestCase):
xenapi_inspector.get_api_session = mock.Mock(return_value=api_session)
self.inspector = xenapi_inspector.XenapiInspector(self.CONF)
def test_inspect_cpu_util(self):
def test_inspect_instance(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
fake_stat = virt_inspector.CPUUtilStats(util=40)
fake_total_mem = 134217728.0
fake_free_mem = 65536.0
def fake_xenapi_request(method, args):
if method == 'VM.get_by_name_label':
return ['vm_ref']
elif method == 'VM.get_VCPUs_max':
return '1'
elif method == 'VM.query_data_source':
return 0.4
else:
return None
session = self.inspector.session
with mock.patch.object(session, 'xenapi_request',
side_effect=fake_xenapi_request):
cpu_util_stat = self.inspector.inspect_cpu_util(fake_instance)
self.assertEqual(fake_stat, cpu_util_stat)
def test_inspect_memory_usage(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
fake_stat = virt_inspector.MemoryUsageStats(usage=64)
def _fake_xenapi_request(method, args):
fake_total_mem = 134217728.0
fake_free_mem = 65536.0
if method == 'VM.get_by_name_label':
return ['vm_ref']
elif method == 'VM.query_data_source':
if 'memory' in args:
return fake_total_mem
elif 'memory_internal_free' in args:
return fake_free_mem
elif 'cpu0' in args:
return 0.4
else:
return None
else:
@ -103,14 +83,14 @@ class TestXenapiInspection(base.BaseTestCase):
session = self.inspector.session
with mock.patch.object(session, 'xenapi_request',
side_effect=_fake_xenapi_request):
memory_stat = self.inspector.inspect_memory_usage(fake_instance)
self.assertEqual(fake_stat, memory_stat)
side_effect=fake_xenapi_request):
stats = self.inspector.inspect_instance(fake_instance)
self.assertEqual(40, stats.cpu_util)
self.assertEqual(64, stats.memory_usage)
def test_inspect_memory_usage_without_freeMem(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
fake_stat = virt_inspector.MemoryUsageStats(usage=128)
def _fake_xenapi_request(method, args):
if xenapi_inspector.api is None:
@ -123,11 +103,15 @@ class TestXenapiInspection(base.BaseTestCase):
if method == 'VM.get_by_name_label':
return ['vm_ref']
elif method == 'VM.get_VCPUs_max':
return '1'
elif method == 'VM.query_data_source':
if 'memory' in args:
return fake_total_mem
elif 'memory_internal_free' in args:
raise xenapi_inspector.api.Failure(fake_details)
elif 'cpu0' in args:
return 0.4
else:
return None
else:
@ -136,8 +120,8 @@ class TestXenapiInspection(base.BaseTestCase):
session = self.inspector.session
with mock.patch.object(session, 'xenapi_request',
side_effect=_fake_xenapi_request):
memory_stat = self.inspector.inspect_memory_usage(fake_instance)
self.assertEqual(fake_stat, memory_stat)
stats = self.inspector.inspect_instance(fake_instance)
self.assertEqual(128, stats.memory_usage)
def test_inspect_vnics(self):
fake_instance = {

View File

@ -98,9 +98,9 @@ ceilometer.poll.compute =
disk.device.latency = ceilometer.compute.pollsters.disk:PerDeviceDiskLatencyPollster
disk.iops = ceilometer.compute.pollsters.disk:DiskIOPSPollster
disk.device.iops = ceilometer.compute.pollsters.disk:PerDeviceDiskIOPSPollster
cpu = ceilometer.compute.pollsters.cpu:CPUPollster
cpu_util = ceilometer.compute.pollsters.cpu:CPUUtilPollster
cpu_l3_cache = ceilometer.compute.pollsters.cpu:CPUL3CachePollster
cpu = ceilometer.compute.pollsters.instance_stats:CPUPollster
cpu_util = ceilometer.compute.pollsters.instance_stats:CPUUtilPollster
cpu_l3_cache = ceilometer.compute.pollsters.instance_stats:CPUL3CachePollster
network.incoming.bytes = ceilometer.compute.pollsters.net:IncomingBytesPollster
network.incoming.packets = ceilometer.compute.pollsters.net:IncomingPacketsPollster
network.outgoing.bytes = ceilometer.compute.pollsters.net:OutgoingBytesPollster
@ -111,20 +111,20 @@ ceilometer.poll.compute =
network.outgoing.packets.drop = ceilometer.compute.pollsters.net:OutgoingDropPollster
network.incoming.packets.error = ceilometer.compute.pollsters.net:IncomingErrorsPollster
network.outgoing.packets.error = ceilometer.compute.pollsters.net:OutgoingErrorsPollster
memory.usage = ceilometer.compute.pollsters.memory:MemoryUsagePollster
memory.resident = ceilometer.compute.pollsters.memory:MemoryResidentPollster
memory.bandwidth.total = ceilometer.compute.pollsters.memory:MemoryBandwidthTotalPollster
memory.bandwidth.local = ceilometer.compute.pollsters.memory:MemoryBandwidthLocalPollster
memory.usage = ceilometer.compute.pollsters.instance_stats:MemoryUsagePollster
memory.resident = ceilometer.compute.pollsters.instance_stats:MemoryResidentPollster
memory.bandwidth.total = ceilometer.compute.pollsters.instance_stats:MemoryBandwidthTotalPollster
memory.bandwidth.local = ceilometer.compute.pollsters.instance_stats:MemoryBandwidthLocalPollster
disk.capacity = ceilometer.compute.pollsters.disk:CapacityPollster
disk.allocation = ceilometer.compute.pollsters.disk:AllocationPollster
disk.usage = ceilometer.compute.pollsters.disk:PhysicalPollster
disk.device.capacity = ceilometer.compute.pollsters.disk:PerDeviceCapacityPollster
disk.device.allocation = ceilometer.compute.pollsters.disk:PerDeviceAllocationPollster
disk.device.usage = ceilometer.compute.pollsters.disk:PerDevicePhysicalPollster
perf.cpu.cycles = ceilometer.compute.pollsters.perf:PerfEventsCPUCyclesPollster
perf.instructions = ceilometer.compute.pollsters.perf:PerfEventsInstructionsPollster
perf.cache.references = ceilometer.compute.pollsters.perf:PerfEventsCacheReferencesPollster
perf.cache.misses = ceilometer.compute.pollsters.perf:PerfEventsCacheMissesPollster
perf.cpu.cycles = ceilometer.compute.pollsters.instance_stats:PerfCPUCyclesPollster
perf.instructions = ceilometer.compute.pollsters.instance_stats:PerfInstructionsPollster
perf.cache.references = ceilometer.compute.pollsters.instance_stats:PerfCacheReferencesPollster
perf.cache.misses = ceilometer.compute.pollsters.instance_stats:PerfCacheMissesPollster
ceilometer.poll.ipmi =
hardware.ipmi.node.power = ceilometer.ipmi.pollsters.node:PowerPollster