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)
def test_get_counters(self): disks = [ (virt_inspector.Disk(device='vda'), virt_inspector.DiskStats(read_bytes=1L, read_requests=2L, write_bytes=3L, write_requests=4L, errors=-1L)) ] self.inspector.inspect_disks(self.instance.name).AndReturn(disks) self.mox.ReplayAll() mgr = manager.AgentManager() pollster = pollsters.DiskIOPollster() counters = list(pollster.get_counters(mgr, self.instance)) assert counters self.assertEqual(set([c.name for c in counters]), set(pollster.get_counter_names())) def _verify_disk_metering(name, expected_volume): match = [c for c in counters if c.name == name] self.assertEquals(len(match), 1, 'missing counter %s' % name) self.assertEquals(match[0].volume, expected_volume) self.assertEquals(match[0].type, 'cumulative') _verify_disk_metering('disk.read.requests', 2L) _verify_disk_metering('disk.read.bytes', 1L) _verify_disk_metering('disk.write.requests', 4L) _verify_disk_metering('disk.write.bytes', 3L)
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)
def inspect_disks(self, instance_name): 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)
def inspect_disks(self, instance, duration): domain = self._get_domain_not_shut_off_or_raise(instance) for device in self._get_disk_devices(domain): block_stats = domain.blockStats(device) block_stats_flags = domain.blockStatsFlags(device, 0) yield virt_inspector.DiskStats( device=device, read_requests=block_stats[0], read_bytes=block_stats[1], write_requests=block_stats[2], write_bytes=block_stats[3], errors=block_stats[4], wr_total_times=block_stats_flags['wr_total_times'], rd_total_times=block_stats_flags['rd_total_times'])
def inspect_disks(self, instance, duration): """Inspect the disk statistics for an instance. The response is a generator of the values. :param instance: the target instance :param duration: the last 'n' seconds, over which the value should be inspected. The PowerVM implementation does not make use of the duration field. :return disk: The Disk indicating the device for the storage device. :return stats: The DiskStats indicating the read/write data to the device. """ # Get the current and previous sample. Delta is performed between # these two. uuid = self._puuid(instance) cur_date, cur_metric = self.vm_metrics.get_latest_metric(uuid) # If the cur_metric is none, then the instance can not be found in the # sample and an error should be raised. if cur_metric is None: raise virt_inspector.InstanceNotFoundException( _('VM %s not found in PowerVM Metrics Sample.') % instance.name) # If there isn't storage information, this is because the Virtual # I/O Metrics were turned off. Have to pass through this method. if cur_metric.storage is None: LOG.debug("Current storage metric was unavailable from the API " "instance %s." % instance.name) return # Bundle together the SCSI and virtual FC adapters adpts = cur_metric.storage.virt_adpts + cur_metric.storage.vfc_adpts # Loop through all the storage adapters for adpt in adpts: # PowerVM only shows the connection (SCSI or FC). Name after # the connection name yield virt_inspector.DiskStats(device=adpt.name, read_requests=adpt.num_reads, read_bytes=adpt.read_bytes, write_requests=adpt.num_writes, write_bytes=adpt.write_bytes, errors=0, wr_total_times=0, rd_total_times=0)
def inspect_disks(self, instance_name): domain = self._lookup_by_name(instance_name) 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)
def inspect_disks(self, instance, duration): domain = self._get_domain_not_shut_off_or_raise(instance) tree = etree.fromstring(domain.XMLDesc(0)) for device in filter(bool, [ target.get("dev") for target in tree.findall('devices/disk/target') ]): block_stats = domain.blockStats(device) yield virt_inspector.DiskStats(device=device, read_requests=block_stats[0], read_bytes=block_stats[1], write_requests=block_stats[2], write_bytes=block_stats[3], errors=block_stats[4])
def inspect_disks(self, instance_name): for disk_metrics in self._utils.get_disk_metrics(instance_name): device = dict([(i, disk_metrics[i]) for i in ['instance_id', 'host_resource'] if i in disk_metrics]) disk = virt_inspector.Disk(device=device) stats = virt_inspector.DiskStats( read_requests=0, # Return bytes read_bytes=disk_metrics['read_mb'] * 1024, write_requests=0, write_bytes=disk_metrics['write_mb'] * 1024, errors=0) yield (disk, stats)
class TestDiskPollsters(base.TestPollsterBase): DISKS = [(virt_inspector.Disk(device='vda'), virt_inspector.DiskStats(read_bytes=1L, read_requests=2L, write_bytes=3L, write_requests=4L, errors=-1L))] def setUp(self): super(TestDiskPollsters, self).setUp() self.inspector.inspect_disks(self.instance.name).AndReturn(self.DISKS) self.mox.ReplayAll() @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) def _check_get_samples(self, factory, name, expected_volume): pollster = factory() mgr = manager.AgentManager() cache = {} samples = list(pollster.get_samples(mgr, cache, self.instance)) assert samples assert pollster.CACHE_KEY_DISK in cache assert self.instance.name in cache[pollster.CACHE_KEY_DISK] self.assertEqual(set([s.name for s in samples]), set([name])) match = [s for s in samples if s.name == name] self.assertEquals(len(match), 1, 'missing counter %s' % name) self.assertEquals(match[0].volume, expected_volume) self.assertEquals(match[0].type, 'cumulative') def test_disk_read_requests(self): self._check_get_samples(disk.ReadRequestsPollster, 'disk.read.requests', 2L) def test_disk_read_bytes(self): self._check_get_samples(disk.ReadBytesPollster, 'disk.read.bytes', 1L) def test_disk_write_requests(self): self._check_get_samples(disk.WriteRequestsPollster, 'disk.write.requests', 4L) def test_disk_write_bytes(self): self._check_get_samples(disk.WriteBytesPollster, 'disk.write.bytes', 3L)
def inspect_disks(self, instance, duration): domain = self._get_domain_not_shut_off_or_raise(instance) for device in self._get_disk_devices(domain): try: block_stats = domain.blockStats(device) block_stats_flags = domain.blockStatsFlags(device, 0) yield virt_inspector.DiskStats( device=device, read_requests=block_stats[0], read_bytes=block_stats[1], write_requests=block_stats[2], write_bytes=block_stats[3], errors=block_stats[4], wr_total_times=block_stats_flags['wr_total_times'], rd_total_times=block_stats_flags['rd_total_times']) except libvirt.libvirtError as ex: # raised error even if lock is acquired while live migration, # even it looks normal. LOG.warning( _("Error from libvirt while checking blockStats, " "This may not be harmful, but please check : " "%(ex)s") % {'ex': ex}) pass
class TestDiskPollsters(TestBaseDiskIO): DISKS = [ virt_inspector.DiskStats( device='vda1', read_bytes=1, read_requests=2, write_bytes=3, write_requests=4, errors=-1, rd_total_times=100, wr_total_times=200, ), virt_inspector.DiskStats( device='vda2', read_bytes=2, read_requests=3, write_bytes=5, write_requests=7, errors=-1, rd_total_times=300, wr_total_times=400, ), ] def setUp(self): super(TestDiskPollsters, self).setUp() self.inspector.inspect_disks = mock.Mock(return_value=self.DISKS) def test_disk_read_requests(self): self._check_aggregate_samples(disk.ReadRequestsPollster, 'disk.read.requests', 5, expected_device=['vda1', 'vda2']) def test_disk_read_bytes(self): self._check_aggregate_samples(disk.ReadBytesPollster, 'disk.read.bytes', 3, expected_device=['vda1', 'vda2']) def test_disk_write_requests(self): self._check_aggregate_samples(disk.WriteRequestsPollster, 'disk.write.requests', 11, expected_device=['vda1', 'vda2']) def test_disk_write_bytes(self): self._check_aggregate_samples(disk.WriteBytesPollster, 'disk.write.bytes', 8, expected_device=['vda1', 'vda2']) def test_per_disk_read_requests(self): self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 2, 'vda1') self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 3, 'vda2') def test_per_disk_write_requests(self): self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 4, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 7, 'vda2') def test_per_disk_read_bytes(self): self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 1, 'vda1') self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 2, 'vda2') def test_per_disk_write_bytes(self): self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 3, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 5, 'vda2') def test_per_device_read_latency(self): self._check_per_device_samples(disk.PerDeviceDiskReadLatencyPollster, 'disk.device.read.latency', 100, 'vda1') self._check_per_device_samples(disk.PerDeviceDiskReadLatencyPollster, 'disk.device.read.latency', 300, 'vda2') def test_per_device_write_latency(self): self._check_per_device_samples(disk.PerDeviceDiskWriteLatencyPollster, 'disk.device.write.latency', 200, 'vda1') self._check_per_device_samples(disk.PerDeviceDiskWriteLatencyPollster, 'disk.device.write.latency', 400, 'vda2')
class TestDiskPollsters(TestBaseDiskIO): DISKS = [ (virt_inspector.Disk(device='vda1'), virt_inspector.DiskStats(read_bytes=1L, read_requests=2L, write_bytes=3L, write_requests=4L, errors=-1L)), (virt_inspector.Disk(device='vda2'), virt_inspector.DiskStats(read_bytes=2L, read_requests=3L, write_bytes=5L, write_requests=7L, errors=-1L)), ] def setUp(self): super(TestDiskPollsters, self).setUp() self.inspector.inspect_disks = mock.Mock(return_value=self.DISKS) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) def _check_get_samples(self, factory, name, expected_count=2): pollster = factory() mgr = manager.AgentManager() cache = {} samples = list(pollster.get_samples(mgr, cache, self.instance)) self.assertIsNotEmpty(samples) self.assertIn(pollster.CACHE_KEY_DISK, cache) for instance in self.instance: self.assertIn(instance.name, cache[pollster.CACHE_KEY_DISK]) self.assertEqual(set([name]), set([s.name for s in samples])) match = [s for s in samples if s.name == name] self.assertEqual(len(match), expected_count, 'missing counter %s' % name) return match def test_disk_read_requests(self): self._check_aggregate_samples(disk.ReadRequestsPollster, 'disk.read.requests', 5L, expected_device=['vda1', 'vda2']) def test_disk_read_bytes(self): self._check_aggregate_samples(disk.ReadBytesPollster, 'disk.read.bytes', 3L, expected_device=['vda1', 'vda2']) def test_disk_write_requests(self): self._check_aggregate_samples(disk.WriteRequestsPollster, 'disk.write.requests', 11L, expected_device=['vda1', 'vda2']) def test_disk_write_bytes(self): self._check_aggregate_samples(disk.WriteBytesPollster, 'disk.write.bytes', 8L, expected_device=['vda1', 'vda2']) def test_per_disk_read_requests(self): self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 2L, 'vda1') self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 3L, 'vda2') def test_per_disk_write_requests(self): self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 4L, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 7L, 'vda2') def test_per_disk_read_bytes(self): self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 1L, 'vda1') self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 2L, 'vda2') def test_per_disk_write_bytes(self): self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 3L, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 5L, 'vda2')
class TestDiskPollsters(TestBaseDiskIO): DISKS = [ (virt_inspector.Disk(device='vda1'), virt_inspector.DiskStats(read_bytes=1, read_requests=2, write_bytes=3, write_requests=4, errors=-1)), (virt_inspector.Disk(device='vda2'), virt_inspector.DiskStats(read_bytes=2, read_requests=3, write_bytes=5, write_requests=7, errors=-1)), ] CACHE_KEY = "CACHE_KEY_DISK" def setUp(self): super(TestDiskPollsters, self).setUp() self.inspector.inspect_disks = mock.Mock(return_value=self.DISKS) def test_disk_read_requests(self): self._check_aggregate_samples(disk.ReadRequestsPollster, 'disk.read.requests', 5, expected_device=['vda1', 'vda2']) def test_disk_read_bytes(self): self._check_aggregate_samples(disk.ReadBytesPollster, 'disk.read.bytes', 3, expected_device=['vda1', 'vda2']) def test_disk_write_requests(self): self._check_aggregate_samples(disk.WriteRequestsPollster, 'disk.write.requests', 11, expected_device=['vda1', 'vda2']) def test_disk_write_bytes(self): self._check_aggregate_samples(disk.WriteBytesPollster, 'disk.write.bytes', 8, expected_device=['vda1', 'vda2']) def test_per_disk_read_requests(self): self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 2, 'vda1') self._check_per_device_samples(disk.PerDeviceReadRequestsPollster, 'disk.device.read.requests', 3, 'vda2') def test_per_disk_write_requests(self): self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 4, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster, 'disk.device.write.requests', 7, 'vda2') def test_per_disk_read_bytes(self): self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 1, 'vda1') self._check_per_device_samples(disk.PerDeviceReadBytesPollster, 'disk.device.read.bytes', 2, 'vda2') def test_per_disk_write_bytes(self): self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 3, 'vda1') self._check_per_device_samples(disk.PerDeviceWriteBytesPollster, 'disk.device.write.bytes', 5, 'vda2')