Example #1
0
    def inspect_disk_rates(self, instance, duration=None):
        vm_moid = self._ops.get_vm_moid(instance.id)
        if not vm_moid:
            raise virt_inspector.InstanceNotFoundException(
                'VM %s not found in VMware Vsphere' % instance.id)

        disk_stats = {}
        disk_ids = set()
        disk_counters = [
            VC_DISK_READ_RATE_CNTR, VC_DISK_READ_REQUESTS_RATE_CNTR,
            VC_DISK_WRITE_RATE_CNTR, VC_DISK_WRITE_REQUESTS_RATE_CNTR
        ]

        for disk_counter in disk_counters:
            disk_counter_id = self._ops.get_perf_counter_id(disk_counter)
            disk_id_to_stat_map = self._ops.query_vm_device_stats(
                vm_moid, disk_counter_id, duration)
            disk_stats[disk_counter] = disk_id_to_stat_map
            disk_ids.update(disk_id_to_stat_map.iterkeys())

        for disk_id in disk_ids:

            def stat_val(counter_name):
                return disk_stats[counter_name].get(disk_id, 0)

            disk = virt_inspector.Disk(device=disk_id)
            # Stats provided from vSphere are in KB/s, converting it to B/s.
            disk_rate_info = virt_inspector.DiskRateStats(
                read_bytes_rate=stat_val(VC_DISK_READ_RATE_CNTR) * units.Ki,
                read_requests_rate=stat_val(VC_DISK_READ_REQUESTS_RATE_CNTR),
                write_bytes_rate=stat_val(VC_DISK_WRITE_RATE_CNTR) * units.Ki,
                write_requests_rate=stat_val(VC_DISK_WRITE_REQUESTS_RATE_CNTR))
            yield (disk, disk_rate_info)
Example #2
0
    def inspect_disk_rates(self, instance, duration=None):
        instance_name = get_instance_name(instance)
        vm_ref = self._lookup_by_name(instance_name)
        vbd_refs = self._call_xenapi("VM.get_VBDs", vm_ref)
        if vbd_refs:
            for vbd_ref in vbd_refs:
                vbd_rec = self._call_xenapi("VBD.get_record", vbd_ref)
                vbd_metrics_ref = self._call_xenapi("VBD.get_metrics", vbd_ref)
                vbd_metrics_rec = self._call_xenapi("VBD_metrics.get_record",
                                                    vbd_metrics_ref)

                disk = virt_inspector.Disk(device=vbd_rec['device'])
                # Stats provided from XenServer are in KB/s,
                # converting it to B/s.
                read_rate = float(vbd_metrics_rec['io_read_kbs']) * units.Ki
                write_rate = float(vbd_metrics_rec['io_write_kbs']) * units.Ki
                disk_rate_info = virt_inspector.DiskRateStats(
                    read_bytes_rate=read_rate,
                    read_requests_rate=0,
                    write_bytes_rate=write_rate,
                    write_requests_rate=0)
                yield (disk, disk_rate_info)