Beispiel #1
0
    def inspect_vnic_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)

        vnic_stats = {}
        vnic_ids = set()

        for net_counter in (VC_NETWORK_RX_COUNTER, VC_NETWORK_TX_COUNTER):
            net_counter_id = self._ops.get_perf_counter_id(net_counter)
            vnic_id_to_stats_map = self._ops.query_vm_device_stats(
                vm_moid, net_counter_id, duration)
            vnic_stats[net_counter] = vnic_id_to_stats_map
            vnic_ids.update(vnic_id_to_stats_map.iterkeys())

        # Stats provided from vSphere are in KB/s, converting it to B/s.
        for vnic_id in vnic_ids:
            rx_bytes_rate = (
                vnic_stats[VC_NETWORK_RX_COUNTER].get(vnic_id, 0) * units.Ki)
            tx_bytes_rate = (
                vnic_stats[VC_NETWORK_TX_COUNTER].get(vnic_id, 0) * units.Ki)

            stats = virt_inspector.InterfaceRateStats(rx_bytes_rate,
                                                      tx_bytes_rate)
            interface = virt_inspector.Interface(name=vnic_id,
                                                 mac=None,
                                                 fref=None,
                                                 parameters=None)
            yield (interface, stats)
Beispiel #2
0
    def inspect_vnic_rates(self, instance, duration=None):
        instance_name = get_instance_name(instance)
        vm_ref = self._lookup_by_name(instance_name)
        vif_refs = self._call_xenapi("VM.get_VIFs", vm_ref)
        if vif_refs:
            for vif_ref in vif_refs:
                vif_rec = self._call_xenapi("VIF.get_record", vif_ref)
                vif_metrics_ref = self._call_xenapi("VIF.get_metrics", vif_ref)
                vif_metrics_rec = self._call_xenapi("VIF_metrics.get_record",
                                                    vif_metrics_ref)

                interface = virt_inspector.Interface(name=vif_rec['uuid'],
                                                     mac=vif_rec['MAC'],
                                                     fref=None,
                                                     parameters=None)
                rx_rate = float(vif_metrics_rec['io_read_kbs']) * units.Ki
                tx_rate = float(vif_metrics_rec['io_write_kbs']) * units.Ki
                stats = virt_inspector.InterfaceRateStats(rx_rate, tx_rate)
                yield (interface, stats)