def inspect_cpu_util(self, instance, duration=None): instance_name = get_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)
def inspect_cpu_util(self, instance, duration=None): vm_moid = self._ops.get_vm_moid(instance.id) if vm_moid is None: raise virt_inspector.InstanceNotFoundException( 'VM %s not found in VMware Vsphere' % instance.id) cpu_util_counter_id = self._ops.get_perf_counter_id( VC_AVERAGE_CPU_CONSUMED_CNTR) cpu_util = self._ops.query_vm_aggregate_stats( vm_moid, cpu_util_counter_id, duration) # For this counter vSphere returns values scaled-up by 100, since the # corresponding API can't return decimals, but only longs. # For e.g. if the utilization is 12.34%, the value returned is 1234. # Hence, dividing by 100. cpu_util = cpu_util / 100 return virt_inspector.CPUUtilStats(util=cpu_util)