(self)
Build query specs using MORs and metrics metadata.
Build query specs using MORs and metrics metadata.
Build query specs using MORs and metrics metadata .
def make_query_specs(self):
        # type: () -> Iterable[List[vim.PerformanceManager.QuerySpec]]
        """
        Build query specs using MORs and metrics metadata.
        """
        server_current_time = self.api.get_current_time()
        self.log.debug("Server current datetime: %s", server_current_time)
        for resource_type in self._config.collected_resource_types:
            mors = self.infrastructure_cache.get_mors(resource_type)
            counters = self.metrics_metadata_cache.get_metadata(resource_type)
            metric_ids = []  # type: List[vim.PerformanceManager.MetricId]
            for counter_key, metric_name in iteritems(counters):
                # PerformanceManager.MetricId `instance` kwarg:
                # - An asterisk (*) to specify all instances of the metric for the specified counterId
                # - Double-quotes ("") to specify aggregated statistics
                # More info https://code.vmware.com/apis/704/vsphere/vim.PerformanceManager.MetricId.html
                if should_collect_per_instance_values(self._config, metric_name, resource_type):
                    instance = "*"
                else:
                    instance = ''

                metric_ids.append(vim.PerformanceManager.MetricId(counterId=counter_key, instance=instance))

            for batch in self.make_batch(mors, metric_ids, resource_type):
                query_specs = []
                for mor, metrics in iteritems(batch):
                    query_spec = vim.PerformanceManager.QuerySpec()  # type: vim.PerformanceManager.QuerySpec
                    query_spec.entity = mor
                    query_spec.metricId = metrics
                    if resource_type in REALTIME_RESOURCES:
                        query_spec.intervalId = REALTIME_METRICS_INTERVAL_ID
                        query_spec.maxSample = 1  # Request a single datapoint
                    else:
                        # We cannot use `maxSample` for historical metrics, let's specify a timewindow that will
                        # contain at least one element
                        query_spec.startTime = server_current_time - dt.timedelta(hours=2)
                    query_specs.append(query_spec)
                if query_specs:
                    yield query_specs
def make_query_specs ( self ) : # type: () -> Iterable[List[vim.PerformanceManager.QuerySpec]] server_current_time = self . api . get_current_time ( ) self . log . debug ( "Server current datetime: %s" , server_current_time ) for resource_type in self . _config . collected_resource_types : mors = self . infrastructure_cache . get_mors ( resource_type ) counters = self . metrics_metadata_cache . get_metadata ( resource_type ) metric_ids = [ ] # type: List[vim.PerformanceManager.MetricId] for counter_key , metric_name in iteritems ( counters ) : # PerformanceManager.MetricId `instance` kwarg: # - An asterisk (*) to specify all instances of the metric for the specified counterId # - Double-quotes ("") to specify aggregated statistics # More info https://code.vmware.com/apis/704/vsphere/vim.PerformanceManager.MetricId.html if should_collect_per_instance_values ( self . _config , metric_name , resource_type ) : instance = "*" else : instance = '' metric_ids . append ( vim . PerformanceManager . MetricId ( counterId = counter_key , instance = instance ) ) for batch in self . make_batch ( mors , metric_ids , resource_type ) : query_specs = [ ] for mor , metrics in iteritems ( batch ) : query_spec = vim . PerformanceManager . QuerySpec ( ) # type: vim.PerformanceManager.QuerySpec query_spec . entity = mor query_spec . metricId = metrics if resource_type in REALTIME_RESOURCES : query_spec . intervalId = REALTIME_METRICS_INTERVAL_ID query_spec . maxSample = 1 # Request a single datapoint else : # We cannot use `maxSample` for historical metrics, let's specify a timewindow that will # contain at least one element query_spec . startTime = server_current_time - dt . timedelta ( hours = 2 ) query_specs . append ( query_spec ) if query_specs : yield query_specs