コード例 #1
0
 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(_('Could not get cache usage for %(id)s: %(e)s'),
                           {'id': instance.id, 'e': err})
コード例 #2
0
ファイル: memory.py プロジェクト: skolekonov/ceilometer
 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
                     })
コード例 #3
0
ファイル: __init__.py プロジェクト: ylwdream/ceilometer
 def get_samples(self, manager, cache, resources):
     self._inspection_duration = self._record_poll_time()
     for instance in resources:
         try:
             polled_time, result = self._inspect_cached(
                 cache, instance, self._inspection_duration)
             if not result:
                 continue
             for stats in self.aggregate_method(result):
                 yield self._stats_to_sample(instance, stats, polled_time)
         except NoVolumeException:
             # FIXME(sileht): This should be a removed... but I will
             # not change the test logic for now
             LOG.warning("%(name)s statistic in not available for "
                         "instance %(instance_id)s" % {
                             'name': self.sample_name,
                             'instance_id': instance.id
                         })
         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(
                 '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(
                 '%(inspector)s does not provide data for '
                 '%(pollster)s', {
                     'inspector': self.inspector.__class__.__name__,
                     'pollster': self.__class__.__name__
                 })
             raise plugin_base.PollsterPermanentError(resources)
         except Exception as err:
             LOG.error('Could not get %(name)s events for %(id)s: %(e)s', {
                 'name': self.sample_name,
                 'id': instance.id,
                 'e': err
             },
                       exc_info=True)
コード例 #4
0
ファイル: disk.py プロジェクト: bopopescu/OpenStack-Ocata
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         try:
             disk_iops_info = self._populate_cache(
                 self.inspector,
                 cache,
                 instance,
             )
             for disk_iops in self._get_samples(instance, disk_iops_info):
                 yield disk_iops
         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(
                 '%(inspector)s does not provide data for '
                 '%(pollster)s', {
                     'inspector': self.inspector.__class__.__name__,
                     'pollster': self.__class__.__name__
                 })
             raise plugin_base.PollsterPermanentError(resources)
         except Exception as err:
             instance_name = util.instance_name(instance)
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'), {
                 'name': instance_name,
                 'error': err
             })
コード例 #5
0
    def get_samples(self, manager, cache, resources):
        # Only one resource for Node Manager pollster
        try:
            stats = self.read_data(cache)
        except nmexcept.IPMIException:
            self.polling_failures += 1
            LOG.warning(
                _('Polling %(name)s faild for %(cnt)s times!') %
                ({
                    'name': self.NAME,
                    'cnt': self.polling_failures
                }))
            if (CONF.ipmi.polling_retry >= 0
                    and self.polling_failures > CONF.ipmi.polling_retry):
                LOG.warning(_('Pollster for %s is disabled!') % self.NAME)
                raise plugin_base.PollsterPermanentError(resources)
            else:
                return

        self.polling_failures = 0

        metadata = {'node': CONF.host}

        if stats:
            data = self.get_value(stats)

            yield sample.Sample(name=self.NAME,
                                type=self.TYPE,
                                unit=self.UNIT,
                                volume=data,
                                user_id=None,
                                project_id=None,
                                resource_id=CONF.host,
                                timestamp=timeutils.utcnow().isoformat(),
                                resource_metadata=metadata)
コード例 #6
0
 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(
                 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(_('Could not get CPU Util for %(id)s: %(e)s'), {
                 'id': instance.id,
                 'e': err
             })
コード例 #7
0
ファイル: net.py プロジェクト: lloydwuhb/ceilometer
 def get_samples(self, manager, cache, resources):
     self._inspection_duration = self._record_poll_time()
     for instance in resources:
         instance_name = util.instance_name(instance)
         LOG.debug('checking net info for instance %s', instance.id)
         try:
             vnics = self._get_vnics_for_instance(
                 cache,
                 self.inspector,
                 instance,
             )
             for vnic, info in vnics:
                 LOG.debug(self.NET_USAGE_MESSAGE, instance_name,
                           vnic.name, self._get_rx_info(info),
                           self._get_tx_info(info))
                 yield self._get_sample(instance, vnic, info)
         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('%(inspector)s does not provide data for '
                       ' %(pollster)s',
                       {'inspector': self.inspector.__class__.__name__,
                        'pollster': self.__class__.__name__})
             raise plugin_base.PollsterPermanentError(resources)
         except Exception as err:
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'),
                           {'name': instance_name, 'error': err})
コード例 #8
0
 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(_('could not get CPU time for %(id)s: %(e)s'),
                           {'id': instance.id, 'e': err})
コード例 #9
0
    def get_samples(self, manager, cache, resources):
        func = super(TestPollsterPollingException, self).get_samples
        sample = func(manager=manager, cache=cache, resources=resources)

        # Raise polling exception after 2 times
        self.polling_failures += 1
        if self.polling_failures > 2:
            raise plugin_base.PollsterPermanentError()

        return sample
コード例 #10
0
ファイル: sensor.py プロジェクト: xiaoliukai/ceilometer
    def get_samples(self, manager, cache, resources):
        # Only one resource for IPMI pollster
        try:
            stats = self.ipmi.read_sensor_any(self.METRIC)
        except ipmiexcept.IPMIException:
            self.polling_failures += 1
            LOG.warning(
                _('Polling %(mtr)s sensor failed for %(cnt)s times!') %
                ({
                    'mtr': self.METRIC,
                    'cnt': self.polling_failures
                }))
            if (CONF.ipmi.polling_retry >= 0
                    and self.polling_failures > CONF.ipmi.polling_retry):
                LOG.warning(_('Pollster for %s is disabled!') % self.METRIC)
                raise plugin_base.PollsterPermanentError(resources[0])
            else:
                return

        self.polling_failures = 0

        sensor_type_data = self._get_sensor_types(stats, self.METRIC)

        for sensor_data in sensor_type_data:
            # Continue if sensor_data is not parseable.
            try:
                sensor_reading = sensor_data['Sensor Reading']
                sensor_id = sensor_data['Sensor ID']
            except KeyError:
                continue

            if not parser.validate_reading(sensor_reading):
                continue

            try:
                volume, unit = parser.parse_reading(sensor_reading)
            except parser.InvalidSensorData:
                continue

            resource_id = '%(host)s-%(sensor-id)s' % {
                'host': CONF.host,
                'sensor-id': parser.transform_id(sensor_id)
            }

            metadata = {'node': CONF.host}

            yield sample.Sample(name='hardware.ipmi.%s' % self.METRIC.lower(),
                                type=sample.TYPE_GAUGE,
                                unit=unit,
                                volume=volume,
                                user_id=None,
                                project_id=None,
                                resource_id=resource_id,
                                timestamp=timeutils.utcnow().isoformat(),
                                resource_metadata=metadata)
コード例 #11
0
    def _get_account_info(self, ksclient, tenants):
        endpoint = self._get_endpoint(ksclient)
        if not endpoint:
            raise StopIteration()

        try:
            from ceilometer.objectstore.rgw_client import RGWAdminClient
            rgw_client = RGWAdminClient(endpoint, self.access_key, self.secret)
        except ImportError:
            raise plugin_base.PollsterPermanentError(tenants)

        for t in tenants:
            api_method = 'get_%s' % self.METHOD
            yield t.id, getattr(rgw_client, api_method)(t.id)
コード例 #12
0
ファイル: memory.py プロジェクト: skolekonov/ceilometer
 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
                     })
コード例 #13
0
ファイル: disk.py プロジェクト: tianmaofu/ceilometer
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         instance_name = util.instance_name(instance)
         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 ceilometer.NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(
                 '%(inspector)s does not provide data for '
                 '%(pollster)s', {
                     'inspector': self.inspector.__class__.__name__,
                     'pollster': self.__class__.__name__
                 })
             raise plugin_base.PollsterPermanentError(resources)
         except Exception as err:
             LOG.exception(_LE('Ignoring instance %(name)s: %(error)s'), {
                 'name': instance_name,
                 'error': err
             })
コード例 #14
0
ファイル: __init__.py プロジェクト: tianmaofu/ceilometer
    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)
コード例 #15
0
 def get_samples(self, manager, cache, resources):
     self._inspection_duration = self._record_poll_time()
     for instance in resources:
         state = instance.status.lower()
         if (state != 'active'):
             LOG.info("Skip the instance with status %(instance_state)s",
                      {'instance_state': state})
             continue
         instance_name = util.instance_name(instance)
         LOG.debug('Getting process list for instance %s', instance_name)
         try:
             LOG.debug('Using inspector %s', self.inspector)
             time1 = datetime.datetime.now()
             process_list = self.inspector.get_process_list(instance_name)
             time2 = datetime.datetime.now()
             latency = (time2 - time1).total_seconds()
             timestamp = time1.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
             FileUtils.write_introspection_latency(timestamp + "\t" +
                                                   (str)(latency * 1000))
             LOG.debug(
                 "PROCESS LIST: %(instance)s lenth: %(plist_length)s", {
                     'instance': instance,
                     'plist_length': process_list[0]['process_name']
                 })
             yield util.make_sample_from_instance(
                 instance,
                 name='instance.process.list',
                 type=sample.TYPE_GAUGE,
                 unit='instance',
                 volume=process_list,
             )
         except vmi_inspector.InstanceNotFoundException as err:
             # Instance was deleted while getting samples. Ignore it.
             LOG.debug('Exception while getting samples %s', err)
         except vmi_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 vmi_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 vmi_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(
                 _('Could not get Process List for '
                   '%(id)s: %(e)s'), {
                       'id': instance.id,
                       'e': err
                   })