Exemplo n.º 1
0
 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:
             instance_name = util.instance_name(instance)
             memory_info = manager.inspector.inspect_memory_usage( instance_name, self._inspection_duration)
             if (memory_info):
                 usg=memory_info.usage
             else:
                 usg=0;
             # Workaround https://bugs.launchpad.net/fuel/+bug/1379794
             LOG.debug(_("MEMORY USAGE: %(instance)s %(usage)f"),
                       ({'instance': getattr(instance, 'id'),
                         'usage': usg}))
             yield util.make_sample_from_instance(
                 instance,
                 name='memory.usage',
                 type=sample.TYPE_GAUGE,
                 unit='MB',
                 volume=usg,
             )
         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 Memory Usage is not implemented for %s'
                         ), manager.inspector.__class__.__name__)
         except Exception as err:
             LOG.exception(_('Could not get Memory Usage for '
                             '%(id)s: %(e)s'), {'id': instance.id,
                                                'e': err})
Exemplo n.º 2
0
 def get_samples(self, manager, cache, instance):
     LOG.info(_('checking instance %s'), instance.id)
     instance_name = util.instance_name(instance)
     try:
         cpu_info = manager.inspector.inspect_cpus(instance_name)
         LOG.info(
             _("CPUTIME USAGE: %(instance)s %(time)d") %
             ({
                 'instance': instance.__dict__,
                 'time': cpu_info.time
             }))
         cpu_num = {'cpu_number': cpu_info.number}
         yield util.make_sample_from_instance(
             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 Exception as err:
         LOG.error(
             _('could not get CPU time for %(id)s: %(e)s') %
             ({
                 'id': instance.id,
                 'e': err
             }))
         LOG.exception(err)
Exemplo n.º 3
0
 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)
         instance_name = util.instance_name(instance)
         try:
             memory_info = manager.inspector.inspect_memory_resident(
                 instance_name, self._inspection_duration)
             LOG.debug("RESIDENT MEMORY: %(instance)s %(resident)f",
                       {'instance': instance,
                        'resident': memory_info.resident})
             yield util.make_sample_from_instance(
                 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 ceilometer.NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug('Obtaining Resident Memory is not implemented'
                       ' for %s', self.inspector.__class__.__name__)
         except Exception as err:
             LOG.exception(_('Could not get Resident Memory Usage for '
                               '%(id)s: %(e)s'), {'id': instance.id,
                                                  'e': err})
Exemplo n.º 4
0
    def _populate_cache(self, inspector, cache, instance):
        i_cache = cache.setdefault(self.CACHE_KEY_DISK_INFO, {})
        if instance.id not in i_cache:
            instance_name = util.instance_name(instance)
            all_capacity = 0
            all_allocation = 0
            all_physical = 0
            per_disk_capacity = {}
            per_disk_allocation = {}
            per_disk_physical = {}
            disk_info = inspector.inspect_disk_info(instance_name)
            for disk, info in disk_info:
                all_capacity += info.capacity
                all_allocation += info.allocation
                all_physical += info.physical

                per_disk_capacity[disk.device] = info.capacity
                per_disk_allocation[disk.device] = info.allocation
                per_disk_physical[disk.device] = info.physical
            per_disk_info = {
                'capacity': per_disk_capacity,
                'allocation': per_disk_allocation,
                'physical': per_disk_physical,
            }
            i_cache[instance.id] = DiskInfoData(
                all_capacity,
                all_allocation,
                all_physical,
                per_disk_info
            )
        return i_cache[instance.id]
Exemplo n.º 5
0
    def inspect_memory_usage(self, instance, duration=None):
        instance_name = util.instance_name(instance)
        domain = self._get_domain_not_shut_off_or_raise(instance)

        try:
            memory_stats = domain.memoryStats()
            if (memory_stats and memory_stats.get('available')
                    and memory_stats.get('unused')):
                memory_used = (memory_stats.get('available') -
                               memory_stats.get('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)
            else:
                msg = _('Failed to inspect memory usage of instance '
                        '<name=%(name)s, id=%(id)s>, '
                        'can not get info from libvirt.') % {
                            'name': instance_name,
                            'id': instance.id
                        }
                raise virt_inspector.InstanceNoDataException(msg)
        # memoryStats might launch an exception if the method is not supported
        # by the underlying hypervisor being used by libvirt.
        except libvirt.libvirtError as e:
            msg = _('Failed to inspect memory usage of %(instance_uuid)s, '
                    'can not get info from libvirt: %(error)s') % {
                        'instance_uuid': instance.id,
                        'error': e
                    }
            raise virt_inspector.NoDataException(msg)
Exemplo n.º 6
0
    def inspect_vnics(self, instance):
        instance_name = util.instance_name(instance)
        vm_ref = self._lookup_by_name(instance_name)
        dom_id = self._call_xenapi("VM.get_domid", vm_ref)
        vif_refs = self._call_xenapi("VM.get_VIFs", vm_ref)
        bw_all = self._call_plugin_serialized('bandwidth',
                                              'fetch_all_bandwidth')
        for vif_ref in vif_refs or []:
            vif_rec = self._call_xenapi("VIF.get_record", vif_ref)

            interface = virt_inspector.Interface(name=vif_rec['uuid'],
                                                 mac=vif_rec['MAC'],
                                                 fref=None,
                                                 parameters=None)
            bw_vif = bw_all[dom_id][vif_rec['device']]

            # TODO(jianghuaw): Currently the plugin can only support
            # rx_bytes and tx_bytes, so temporarily set others as -1.
            stats = virt_inspector.InterfaceStats(rx_bytes=bw_vif['bw_in'],
                                                  rx_packets=-1,
                                                  rx_drop=-1,
                                                  rx_errors=-1,
                                                  tx_bytes=bw_vif['bw_out'],
                                                  tx_packets=-1,
                                                  tx_drop=-1,
                                                  tx_errors=-1)
            yield (interface, stats)
Exemplo n.º 7
0
 def _get_vms(self, manager):
     vms = nova_client.Client().instance_get_all_by_host(cfg.CONF.host)
     for vm in vms:
         instance_name = util.instance_name(vm)
         state = manager.inspector.inspect_state(instance_name)
         if state.state == inspector.PAUSED:
             yield vm
Exemplo n.º 8
0
 def inspect_memory_usage_rate(self,instance,duration=None):
     instance_name=util.instance_name(instance)
     vm_ref=self._lookup_by_name(instance_name)
     total_mem=float(self._call_xenapi("VM.query_data_source",
                                         vm_ref,
                                         "memory"))
     return total_mem
Exemplo n.º 9
0
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         try:
             disk_size_info = self._populate_cache(
                 self.inspector,
                 cache,
                 instance,
             )
             for disk_info in self._get_samples(instance, disk_size_info):
                 yield disk_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.warning(_LW('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__})
         except Exception as err:
             instance_name = util.instance_name(instance)
             LOG.exception(_('Ignoring instance %(name)s '
                             '(%(instance_id)s) : %(error)s') % (
                           {'name': instance_name,
                            'instance_id': instance.id,
                            'error': err}))
Exemplo n.º 10
0
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         LOG.info(_('checking instance %s'), instance.id)
         instance_name = util.instance_name(instance)
         try:
             cpu_info = manager.inspector.inspect_cpus(instance_name)
             LOG.info(_("CPUTIME USAGE: %(instance)s %(time)d"), {
                 'instance': instance.__dict__,
                 'time': cpu_info.time
             })
             cpu_num = {'cpu_number': cpu_info.number}
             yield util.make_sample_from_instance(
                 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 NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(_('Obtaining CPU time is not implemented for %s'),
                       manager.inspector.__class__.__name__)
         except Exception as err:
             LOG.exception(_('could not get CPU time for %(id)s: %(e)s'), {
                 'id': instance.id,
                 'e': err
             })
Exemplo n.º 11
0
    def make_vnic_sample(instance, name, type, unit, volume, vnic_data):
        metadata = copy.copy(vnic_data)
        resource_metadata = dict(zip(metadata._fields, metadata))
        resource_metadata['instance_id'] = instance.id
        resource_metadata['instance_type'] = (instance.flavor['id']
                                              if instance.flavor else None)

        compute_util.add_reserved_user_metadata(instance.metadata,
                                                resource_metadata)

        if vnic_data.fref is not None:
            rid = vnic_data.fref
        else:
            instance_name = util.instance_name(instance)
            rid = "%s-%s-%s" % (instance_name, instance.id, vnic_data.name)

        return sample.Sample(name=name,
                             type=type,
                             unit=unit,
                             volume=volume,
                             user_id=instance.user_id,
                             project_id=instance.tenant_id,
                             resource_id=rid,
                             timestamp=timeutils.utcnow().isoformat(),
                             resource_metadata=resource_metadata)
Exemplo n.º 12
0
 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.warn(
                 _LW('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__
                 })
         except Exception as err:
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'), {
                 'name': instance_name,
                 'error': err
             })
Exemplo n.º 13
0
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         LOG.info(_('checking instance %s'), instance.id)
         instance_name = util.instance_name(instance)
         try:
             cpu_info = manager.inspector.inspect_cpus(instance_name)
             LOG.info(_("CPUTIME USAGE: %(instance)s %(time)d") % (
                      {'instance': instance.__dict__,
                       'time': cpu_info.time}))
             cpu_num = {'cpu_number': cpu_info.number}
             yield util.make_sample_from_instance(
                 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 NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(_('Obtaining CPU time is not implemented for %s'
                         ), manager.inspector.__class__.__name__)
         except Exception as err:
             LOG.error(_('could not get CPU time for %(id)s: %(e)s') % (
                       {'id': instance.id, 'e': err}))
             LOG.exception(err)
Exemplo n.º 14
0
 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(_LE('Ignoring instance %(name)s: %(error)s'),
                           {'name': instance_name, 'error': err})
Exemplo n.º 15
0
 def inspect_disk_latency(self, instance, duration):
     instance_name = util.instance_name(instance)
     for disk_metrics in self._utils.get_disk_latency_metrics(
             instance_name):
         yield virt_inspector.DiskLatencyStats(
             device=disk_metrics['instance_id'],
             disk_latency=disk_metrics['disk_latency'] / 1000)
Exemplo n.º 16
0
 def inspect_disks(self, instance):
     instance_name = util.instance_name(instance)
     domain = self._lookup_by_uuid(instance)
     state = domain.info()[0]
     if state == libvirt.VIR_DOMAIN_SHUTOFF:
         LOG.warn(
             _('Failed to inspect disks of instance Name '
               '%(instance_name)s UUID %(instance_uuid)s, '
               'domain is in state of SHUTOFF'), {
                   'instance_name': instance_name,
                   'instance_uuid': instance.id
               })
         return
     tree = etree.fromstring(domain.XMLDesc(0))
     for device in filter(bool, [
             target.get("dev")
             for target in tree.findall('devices/disk/target')
     ]):
         disk = virt_inspector.Disk(device=device)
         block_stats = domain.blockStats(device)
         stats = virt_inspector.DiskStats(read_requests=block_stats[0],
                                          read_bytes=block_stats[1],
                                          write_requests=block_stats[2],
                                          write_bytes=block_stats[3],
                                          errors=block_stats[4])
         yield (disk, stats)
Exemplo n.º 17
0
 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.warning(_LW('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__})
         except Exception as err:
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'),
                           {'name': instance_name, 'error': err})
Exemplo n.º 18
0
 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
             })
Exemplo n.º 19
0
 def get_samples(self, manager, cache, resources):
     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,
                 manager.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 NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(_('%(inspector)s does not provide data for '
                         ' %(pollster)s'), ({
                       'inspector': manager.inspector.__class__.__name__,
                       'pollster': self.__class__.__name__}))
         except Exception as err:
             LOG.warning(_('Ignoring instance %(name)s: %(error)s') % (
                         {'name': instance_name, 'error': err}))
             LOG.exception(err)
Exemplo n.º 20
0
 def _get_vnics_for_instance(self, cache, inspector, instance):
     instance_name = util.instance_name(instance)
     i_cache = cache.setdefault(self.CACHE_KEY_VNIC, {})
     if instance_name not in i_cache:
         i_cache[instance_name] = list(
             self._get_vnic_info(inspector, instance))
     return i_cache[instance_name]
Exemplo n.º 21
0
 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(_('Ignoring instance %(name)s: %(error)s'),
                           {'name': instance_name, 'error': err})
Exemplo n.º 22
0
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         LOG.debug(_('checking instance %s'), instance.id)
         instance_name = util.instance_name(instance)
         try:
             checkpoint_pause = manager.inspector.inspect_checkpoint(
                 instance)[2]
             LOG.debug(_("CHECKPOINT PAUSE: %(instance)s %(time)d"), {
                 'instance': instance.__dict__,
                 'time': checkpoint_pause
             })
             yield util.make_sample_from_instance(
                 instance,
                 name='checkpoint.pause',
                 type=sample.TYPE_GAUGE,
                 unit='ms',
                 volume=checkpoint_pause,
             )
         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 checkpoint pause is not implemented for %s'),
                 manager.inspector.__class__.__name__)
         except Exception as err:
             LOG.exception(
                 _('could not get checkpoint pause for %(id)s: %(e)s'), {
                     'id': instance.id,
                     'e': err
                 })
Exemplo n.º 23
0
    def _populate_cache(self, inspector, cache, instance):
        i_cache = cache.setdefault(self.CACHE_KEY_DISK_INFO, {})
        if instance.id not in i_cache:
            instance_name = util.instance_name(instance)
            all_capacity = 0
            all_allocation = 0
            all_physical = 0
            per_disk_capacity = {}
            per_disk_allocation = {}
            per_disk_physical = {}
            disk_info = inspector.inspect_disk_info(instance_name)
            for disk, info in disk_info:
                all_capacity += info.capacity
                all_allocation += info.allocation
                all_physical += info.physical

                per_disk_capacity[disk.device] = info.capacity
                per_disk_allocation[disk.device] = info.allocation
                per_disk_physical[disk.device] = info.physical
            per_disk_info = {
                'capacity': per_disk_capacity,
                'allocation': per_disk_allocation,
                'physical': per_disk_physical,
            }
            i_cache[instance.id] = DiskInfoData(all_capacity, all_allocation,
                                                all_physical, per_disk_info)
        return i_cache[instance.id]
Exemplo n.º 24
0
 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,
                 manager.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 NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(
                 _('%(inspector)s does not provide data for '
                   ' %(pollster)s'), {
                       'inspector': manager.inspector.__class__.__name__,
                       'pollster': self.__class__.__name__
                   })
         except Exception as err:
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'), {
                 'name': instance_name,
                 'error': err
             })
Exemplo n.º 25
0
    def inspect_memory_usage(self, instance, duration=None):
        instance_name = util.instance_name(instance)
        domain = self._get_domain_not_shut_off_or_raise(instance)

        try:
            memory_stats = domain.memoryStats()
            if (memory_stats and
                    memory_stats.get('available') and
                    memory_stats.get('unused')):
                memory_used = (memory_stats.get('available') -
                               memory_stats.get('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)
            else:
                msg = _('Failed to inspect memory usage of instance '
                        '<name=%(name)s, id=%(id)s>, '
                        'can not get info from libvirt.') % {
                    'name': instance_name, 'id': instance.id}
                raise virt_inspector.InstanceNoDataException(msg)
        # memoryStats might launch an exception if the method is not supported
        # by the underlying hypervisor being used by libvirt.
        except libvirt.libvirtError as e:
            msg = _('Failed to inspect memory usage of %(instance_uuid)s, '
                    'can not get info from libvirt: %(error)s') % {
                'instance_uuid': instance.id, 'error': e}
            raise virt_inspector.NoDataException(msg)
Exemplo n.º 26
0
    def make_vnic_sample(instance, name, type, unit, volume, vnic_data):
        metadata = copy.copy(vnic_data)
        resource_metadata = dict(zip(metadata._fields, metadata))
        resource_metadata['instance_id'] = instance.id
        resource_metadata['instance_type'] = (instance.flavor['id'] if
                                              instance.flavor else None)

        compute_util.add_reserved_user_metadata(instance.metadata,
                                                resource_metadata)

        if vnic_data.fref is not None:
            rid = vnic_data.fref
        else:
            instance_name = util.instance_name(instance)
            rid = "%s-%s-%s" % (instance_name, instance.id, vnic_data.name)

        return sample.Sample(
            name=name,
            type=type,
            unit=unit,
            volume=volume,
            user_id=instance.user_id,
            project_id=instance.tenant_id,
            resource_id=rid,
            timestamp=timeutils.isotime(),
            resource_metadata=resource_metadata
        )
Exemplo n.º 27
0
    def inspect_vnics(self, instance, duration):
        instance_name = util.instance_name(instance)
        vm_ref = self._lookup_by_name(instance_name)
        dom_id = self.session.VM.get_domid(vm_ref)
        vif_refs = self.session.VM.get_VIFs(vm_ref)
        bw_all = self.session.call_plugin_serialized('bandwidth',
                                                     'fetch_all_bandwidth')
        LOG.debug("inspect_vnics, all bandwidth: %s",
                  bw_all,
                  instance=instance)

        for vif_ref in vif_refs:
            vif_rec = self.session.VIF.get_record(vif_ref)

            bw_vif = bw_all[dom_id][vif_rec['device']]

            # TODO(jianghuaw): Currently the plugin can only support
            # rx_bytes and tx_bytes, so temporarily set others as -1.
            yield virt_inspector.InterfaceStats(name=vif_rec['uuid'],
                                                mac=vif_rec['MAC'],
                                                fref=None,
                                                parameters=None,
                                                rx_bytes=bw_vif['bw_in'],
                                                rx_packets=-1,
                                                rx_drop=-1,
                                                rx_errors=-1,
                                                tx_bytes=bw_vif['bw_out'],
                                                tx_packets=-1,
                                                tx_drop=-1,
                                                tx_errors=-1,
                                                rx_bytes_delta=-1,
                                                tx_bytes_delta=-1)
Exemplo n.º 28
0
 def get_samples(self, manager, cache, resources):
     for instance in resources:
         instance_name = util.instance_name(instance)
         try:
             c_data = self._populate_cache(
                 manager.inspector,
                 cache,
                 instance,
                 instance_name,
             )
             yield self._get_sample(instance, c_data)
         except virt_inspector.InstanceNotFoundException as err:
             # Instance was deleted while getting samples. Ignore it.
             LOG.debug(_('Exception while getting samples %s'), err)
         except NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(
                 _('%(inspector)s does not provide data for '
                   ' %(pollster)s'), {
                       'inspector': manager.inspector.__class__.__name__,
                       'pollster': self.__class__.__name__
                   })
         except Exception as err:
             LOG.exception(_('Ignoring instance %(name)s: %(error)s'), {
                 'name': instance_name,
                 'error': err
             })
Exemplo n.º 29
0
    def inspect_memory_usage(self, instance, duration=None):
        instance_name = util.instance_name(instance)
        domain = self._lookup_by_uuid(instance)
        state = domain.info()[0]
        if state == libvirt.VIR_DOMAIN_SHUTOFF:
            LOG.warn(_('Failed to inspect memory usage of instance Name '
                       '%(instance_name)s UUID %(instance_uuid)s, '
                       'domain is in state of SHUTOFF'),
                     {'instance_name': instance_name,
                      'instance_uuid': instance.id})
            return

        try:
            memory_stats = domain.memoryStats()
            if (memory_stats and
                    memory_stats.get('available') and
                    memory_stats.get('unused')):
                memory_used = (memory_stats.get('available') -
                               memory_stats.get('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)
            else:
                LOG.warn(_('Failed to inspect memory usage of instance Name '
                           '%(instance_name)s UUID %(instance_uuid)s, '
                           'can not get info from libvirt'),
                         {'instance_name': instance_name,
                          'instance_uuid': instance.id})
        # memoryStats might launch an exception if the method
        # is not supported by the underlying hypervisor being
        # used by libvirt
        except libvirt.libvirtError as e:
            LOG.warn(_('Failed to inspect memory usage of %(instance_uuid)s, '
                       'can not get info from libvirt: %(error)s'),
                     {'instance_uuid': instance.id, 'error': e})
Exemplo n.º 30
0
 def inspect_disk_latency(self, instance, duration):
     instance_name = util.instance_name(instance)
     for disk_metrics in self._utils.get_disk_latency_metrics(
             instance_name):
         yield virt_inspector.DiskLatencyStats(
             device=disk_metrics['instance_id'],
             disk_latency=disk_metrics['disk_latency'] / 1000)
Exemplo n.º 31
0
 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)
         instance_name = util.instance_name(instance)
         try:
             memory_info = manager.inspector.inspect_memory_resident(
                 instance_name, self._inspection_duration)
             LOG.debug("RESIDENT MEMORY: %(instance)s %(resident)f", {
                 'instance': instance,
                 'resident': memory_info.resident
             })
             yield util.make_sample_from_instance(
                 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 ceilometer.NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(
                 'Obtaining Resident Memory is not implemented'
                 ' for %s', self.inspector.__class__.__name__)
         except Exception as err:
             LOG.exception(
                 _('Could not get Resident Memory Usage for '
                   '%(id)s: %(e)s'), {
                       'id': instance.id,
                       'e': err
                   })
Exemplo n.º 32
0
 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, manager.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 NotImplementedError:
             # Selected inspector does not implement this pollster.
             LOG.debug(
                 _("%(inspector)s does not provide data for " " %(pollster)s"),
                 ({"inspector": manager.inspector.__class__.__name__, "pollster": self.__class__.__name__}),
             )
         except Exception as err:
             LOG.warning(_("Ignoring instance %(name)s: %(error)s") % ({"name": instance_name, "error": err}))
             LOG.exception(err)
Exemplo n.º 33
0
 def inspect_instance(self, instance, duration):
     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)
Exemplo n.º 34
0
    def inspect_memory_usage(self, instance, duration=None):
        instance_name = util.instance_name(instance)
        domain = self._lookup_by_name(instance_name)
        state = domain.info()[0]
        if state == libvirt.VIR_DOMAIN_SHUTOFF:
            LOG.warn(
                _('Failed to inspect memory usage of %(instance_name)s, '
                  'domain is in state of SHUTOFF'),
                {'instance_name': instance_name})
            return

        try:
            memory_stats = domain.memoryStats()
            if (memory_stats and memory_stats.get('available')
                    and memory_stats.get('unused')):
                memory_used = (memory_stats.get('available') -
                               memory_stats.get('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)
            else:
                LOG.warn(
                    _('Failed to inspect memory usage of '
                      '%(instance_name)s, can not get info from libvirt'),
                    {'instance_name': instance_name})
        # memoryStats might launch an exception if the method
        # is not supported by the underlying hypervisor being
        # used by libvirt
        except libvirt.libvirtError as e:
            LOG.warn(
                _('Failed to inspect memory usage of %(instance_name)s, '
                  'can not get info from libvirt: %(error)s'), {
                      'instance_name': instance_name,
                      'error': e
                  })
Exemplo n.º 35
0
 def _get_vms(self, manager):
     vms = nova_client.Client().instance_get_all_by_host(cfg.CONF.host)
     for vm in vms:
         instance_name = util.instance_name(vm)
         state = manager.inspector.inspect_state(instance_name)
         if state.state == inspector.PAUSED:
             yield vm
Exemplo n.º 36
0
 def inspect_memory_usage(self, instance, duration=None):
     instance_name = util.instance_name(instance)
     vm_ref = self._lookup_by_name(instance_name)
     metrics_ref = self._call_xenapi("VM.get_metrics", vm_ref)
     metrics_rec = self._call_xenapi("VM_metrics.get_record", metrics_ref)
     # Stat provided from XenServer is in B, converting it to MB.
     memory = int(metrics_rec["memory_actual"]) / units.Mi
     return virt_inspector.MemoryUsageStats(usage=memory)
Exemplo n.º 37
0
 def inspect_memory_usage(self, instance, duration=None):
     instance_name = util.instance_name(instance)
     vm_ref = self._lookup_by_name(instance_name)
     metrics_ref = self._call_xenapi("VM.get_metrics", vm_ref)
     metrics_rec = self._call_xenapi("VM_metrics.get_record", metrics_ref)
     # Stat provided from XenServer is in B, converting it to MB.
     memory = int(metrics_rec['memory_actual']) / units.Mi
     return virt_inspector.MemoryUsageStats(usage=memory)
Exemplo n.º 38
0
 def _get_vnics_for_instance(self, cache, inspector, instance):
     instance_name = util.instance_name(instance)
     i_cache = cache.setdefault(self.CACHE_KEY_VNIC, {})
     if instance_name not in i_cache:
         i_cache[instance_name] = list(
             self._get_vnic_info(inspector, instance)
         )
     return i_cache[instance_name]
Exemplo n.º 39
0
    def inspect_disk_iops(self, instance):
        instance_name = util.instance_name(instance)
        for disk_metrics in self._utils.get_disk_iops_count(instance_name):
            disk = virt_inspector.Disk(device=disk_metrics['instance_id'])
            stats = virt_inspector.DiskIOPSStats(
                iops_count=disk_metrics['iops_count'])

            yield (disk, stats)
Exemplo n.º 40
0
    def inspect_disk_iops(self, instance):
        instance_name = util.instance_name(instance)
        for disk_metrics in self._utils.get_disk_iops_count(instance_name):
            disk = virt_inspector.Disk(device=disk_metrics['instance_id'])
            stats = virt_inspector.DiskIOPSStats(
                iops_count=disk_metrics['iops_count'])

            yield (disk, stats)
Exemplo n.º 41
0
    def inspect_disk_latency(self, instance):
        instance_name = util.instance_name(instance)
        for disk_metrics in self._utils.get_disk_latency_metrics(
                instance_name):
            disk = virt_inspector.Disk(device=disk_metrics['instance_id'])
            stats = virt_inspector.DiskLatencyStats(
                disk_latency=disk_metrics['disk_latency'])

            yield (disk, stats)
Exemplo n.º 42
0
 def inspect_instance(self, instance, duration):
     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)
     LOG.debug("inspect_instance, cpu_util: %(cpu)s, memory_usage: %(mem)s",
               {'cpu': cpu_util, 'mem': memory_usage}, instance=instance)
     return virt_inspector.InstanceStats(cpu_util=cpu_util,
                                         memory_usage=memory_usage)
Exemplo n.º 43
0
    def inspect_disk_latency(self, instance):
        instance_name = util.instance_name(instance)
        for disk_metrics in self._utils.get_disk_latency_metrics(
                instance_name):
            disk = virt_inspector.Disk(device=disk_metrics['instance_id'])
            stats = virt_inspector.DiskLatencyStats(
                disk_latency=disk_metrics['disk_latency'])

            yield (disk, stats)
Exemplo n.º 44
0
 def inspect_checkpoint(self, instance):
     instance_name = util.instance_name(instance)
     domain = self._lookup_by_uuid(instance)
     info = domain.jobInfo()
     return virt_inspector.CheckpointStats(
         checkpoint_size=info[12],
         checkpoint_length=info[13],
         checkpoint_pause=info[14],
         checkpoint_count=info[15],
         checkpoint_proxyDiscompare=info[16])
Exemplo n.º 45
0
 def inspect_disks(self, instance, duration):
     instance_name = util.instance_name(instance)
     for disk_metrics in self._utils.get_disk_metrics(instance_name):
         yield virt_inspector.DiskStats(
             device=disk_metrics['instance_id'],
             read_requests=0,
             # Return bytes
             read_bytes=disk_metrics['read_mb'] * units.Mi,
             write_requests=0,
             write_bytes=disk_metrics['write_mb'] * units.Mi,
             errors=0)
Exemplo n.º 46
0
    def inspect_cpus(self, instance):
        instance_name = util.instance_name(instance)
        (cpu_clock_used, cpu_count,
         uptime) = self._utils.get_cpu_metrics(instance_name)
        host_cpu_clock, host_cpu_count = self._utils.get_host_cpu_info()

        cpu_percent_used = (cpu_clock_used / float(host_cpu_clock * cpu_count))
        # Nanoseconds
        cpu_time = (long(uptime * cpu_percent_used) * units.k)

        return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)
Exemplo n.º 47
0
    def inspect_cpus(self, instance):
        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)

        return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)
Exemplo n.º 48
0
 def inspect_disks(self, instance, duration):
     instance_name = util.instance_name(instance)
     for disk_metrics in self._utils.get_disk_metrics(instance_name):
         yield virt_inspector.DiskStats(
             device=disk_metrics['instance_id'],
             read_requests=0,
             # Return bytes
             read_bytes=disk_metrics['read_mb'] * units.Mi,
             write_requests=0,
             write_bytes=disk_metrics['write_mb'] * units.Mi,
             errors=0, wr_total_times=0, rd_total_times=0)
Exemplo n.º 49
0
    def inspect_cpus(self, instance):
        instance_name = util.instance_name(instance)
        (cpu_clock_used,
         cpu_count, uptime) = self._utils.get_cpu_metrics(instance_name)
        host_cpu_clock, host_cpu_count = self._utils.get_host_cpu_info()

        cpu_percent_used = (cpu_clock_used /
                            float(host_cpu_clock * cpu_count))
        # Nanoseconds
        cpu_time = (long(uptime * cpu_percent_used) * units.k)

        return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)
Exemplo n.º 50
0
    def inspect_instance(self, instance, duration):
        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.InstanceStats(cpu_number=cpu_count,
                                            cpu_time=cpu_time,
                                            memory_usage=memory_usage)
Exemplo n.º 51
0
    def inspect_instance(self, instance, duration):
        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.InstanceStats(
            cpu_number=cpu_count,
            cpu_time=cpu_time,
            memory_usage=memory_usage)
Exemplo n.º 52
0
    def _get_domain_not_shut_off_or_raise(self, instance):
        instance_name = util.instance_name(instance)
        domain = self._lookup_by_uuid(instance)

        state = domain.info()[0]
        if state == libvirt.VIR_DOMAIN_SHUTOFF:
            msg = _('Failed to inspect data of instance '
                    '<name=%(name)s, id=%(id)s>, '
                    'domain state is SHUTOFF.') % {
                'name': instance_name, 'id': instance.id}
            raise virt_inspector.InstanceShutOffException(msg)

        return domain
Exemplo n.º 53
0
    def inspect_disks(self, instance):
        instance_name = util.instance_name(instance)
        for disk_metrics in self._utils.get_disk_metrics(instance_name):
            disk = virt_inspector.Disk(device=disk_metrics['instance_id'])
            stats = virt_inspector.DiskStats(
                read_requests=0,
                # Return bytes
                read_bytes=disk_metrics['read_mb'] * units.Mi,
                write_requests=0,
                write_bytes=disk_metrics['write_mb'] * units.Mi,
                errors=0)

            yield (disk, stats)
Exemplo n.º 54
0
 def get_samples(self, manager, cache, instance):
     instance_name = util.instance_name(instance)
     try:
         c_data = self._populate_cache(
             manager.inspector,
             cache,
             instance,
             instance_name,
         )
         yield self._get_sample(instance, c_data)
     except Exception as err:
         LOG.warning('Ignoring instance %s: %s', instance_name, err)
         LOG.exception(err)
Exemplo n.º 55
0
 def inspect_cpu_util(self, instance, duration=None):
     instance_name = util.instance_name(instance)
     vm_ref = self._lookup_by_name(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
     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)
Exemplo n.º 56
0
 def get_counters(self, manager, cache, instance):
     instance_name = util.instance_name(instance)
     c_data = self._populate_cache(
         manager.inspector,
         cache,
         instance,
         instance_name,
     )
     try:
         yield self._get_counter(instance, c_data)
     except Exception as err:
         LOG.warning('Ignoring instance %s: %s',
                     instance_name, err)
         LOG.exception(err)
Exemplo n.º 57
0
    def inspect_cpu_util(self, instance, duration=None):
        instance_name = util.instance_name(instance)
        vm_ref = self._lookup_by_name(instance_name)
        metrics_ref = self._call_xenapi("VM.get_metrics", vm_ref)
        metrics_rec = self._call_xenapi("VM_metrics.get_record", metrics_ref)
        vcpus_number = metrics_rec["VCPUs_number"]
        vcpus_utils = metrics_rec["VCPUs_utilisation"]
        if len(vcpus_utils) == 0:
            msg = _("Could not get VM %s CPU Utilization") % instance_name
            raise XenapiException(msg)

        utils = 0.0
        for num in range(int(vcpus_number)):
            utils += vcpus_utils.get(str(num))
        utils = utils / int(vcpus_number) * 100
        return virt_inspector.CPUUtilStats(util=utils)
Exemplo n.º 58
0
 def inspect_vnics(self, instance, duration):
     instance_name = util.instance_name(instance)
     for vnic_metrics in self._utils.get_vnic_metrics(instance_name):
         yield virt_inspector.InterfaceStats(
             name=vnic_metrics["element_name"],
             mac=vnic_metrics["address"],
             fref=None,
             parameters=None,
             rx_bytes=vnic_metrics['rx_mb'] * units.Mi,
             rx_packets=0,
             rx_drop=0,
             rx_errors=0,
             tx_bytes=vnic_metrics['tx_mb'] * units.Mi,
             tx_packets=0,
             tx_drop=0,
             tx_errors=0)
Exemplo n.º 59
0
 def get_samples(self, manager, cache, instance):
     instance_name = util.instance_name(instance)
     LOG.info('checking instance %s', instance.id)
     try:
         vnics = self._get_vnics_for_instance(
             cache,
             manager.inspector,
             instance_name,
         )
         for vnic, info in vnics:
             LOG.info(self.NET_USAGE_MESSAGE, instance_name,
                      vnic.name, info.rx_bytes, info.tx_bytes)
             yield self._get_sample(instance, vnic, info)
     except Exception as err:
         LOG.warning('Ignoring instance %s: %s',
                     instance_name, err)
         LOG.exception(err)