(self, instance, query_specs)
Task that collects the metrics listed in the morlist for one MOR
Task that collects the metrics listed in the morlist for one MOR
Task that collects the metrics listed in the morlist for one MOR
def _collect_metrics_async(self, instance, query_specs):
        """Task that collects the metrics listed in the morlist for one MOR"""
        # ## <TEST-INSTRUMENTATION>
        t = Timer()
        # ## </TEST-INSTRUMENTATION>
        i_key = self._instance_key(instance)
        server_instance = self._get_server_instance(instance)
        perfManager = server_instance.content.perfManager
        results = perfManager.QueryPerf(query_specs)
        if results:
            for mor_perfs in results:
                mor_name = str(mor_perfs.entity)
                try:
                    mor = self.mor_cache.get_mor(i_key, mor_name)
                except MorNotFoundError:
                    self.log.error(
                        "Trying to get metrics from object %s deleted from the cache, skipping. "
                        "Consider increasing the parameter `clean_morlist_interval` to avoid that",
                        mor_name,
                    )
                    continue

                for result in mor_perfs.value:
                    counter_id = result.id.counterId
                    if not self.metadata_cache.contains(i_key, counter_id):
                        self.log.debug(
                            "Skipping value for counter %s, because there is no metadata about it",
                            ensure_unicode(counter_id),
                        )
                        continue

                    # Metric types are absolute, delta, and rate
                    metric_name = self.metadata_cache.get_metadata(i_key, result.id.counterId).get('name')

                    if self.in_compatibility_mode(instance):
                        if metric_name not in ALL_METRICS:
                            self.log.debug("Skipping unknown `%s` metric.", ensure_unicode(metric_name))
                            continue

                    if not result.value:
                        self.log.debug("Skipping `%s` metric because the value is empty", ensure_unicode(metric_name))
                        continue

                    instance_name = result.id.instance or "none"
                    # Get the most recent value that isn't negative
                    valid_values = [v for v in result.value if v >= 0]
                    if not valid_values:
                        continue
                    value = self._transform_value(instance, result.id.counterId, valid_values[-1])

                    hostname = mor['hostname']

                    tags = ['instance:{}'.format(ensure_unicode(instance_name))]
                    if not hostname:  # no host tags available
                        tags.extend(mor['tags'])
                    else:
                        hostname = to_string(hostname)
                        if self.excluded_host_tags:
                            tags.extend(mor["excluded_host_tags"])

                    tags.extend(instance.get('tags', []))

                    # vsphere "rates" should be submitted as gauges (rate is
                    # precomputed).
                    self.gauge("vsphere.{}".format(ensure_unicode(metric_name)), value, hostname=hostname, tags=tags)

        # ## <TEST-INSTRUMENTATION>
        custom_tags = instance.get('tags', []) + ['instance:{}'.format(i_key)]
        self.histogram('datadog.agent.vsphere.metric_colection.time', t.total(), tags=custom_tags)
def _collect_metrics_async ( self , instance , query_specs ) : # ## <TEST-INSTRUMENTATION> t = Timer ( ) # ## </TEST-INSTRUMENTATION> i_key = self . _instance_key ( instance ) server_instance = self . _get_server_instance ( instance ) perfManager = server_instance . content . perfManager results = perfManager . QueryPerf ( query_specs ) if results : for mor_perfs in results : mor_name = str ( mor_perfs . entity ) try : mor = self . mor_cache . get_mor ( i_key , mor_name ) except MorNotFoundError : self . log . error ( "Trying to get metrics from object %s deleted from the cache, skipping. " "Consider increasing the parameter `clean_morlist_interval` to avoid that" , mor_name , ) continue for result in mor_perfs . value : counter_id = result . id . counterId if not self . metadata_cache . contains ( i_key , counter_id ) : self . log . debug ( "Skipping value for counter %s, because there is no metadata about it" , ensure_unicode ( counter_id ) , ) continue # Metric types are absolute, delta, and rate metric_name = self . metadata_cache . get_metadata ( i_key , result . id . counterId ) . get ( 'name' ) if self . in_compatibility_mode ( instance ) : if metric_name not in ALL_METRICS : self . log . debug ( "Skipping unknown `%s` metric." , ensure_unicode ( metric_name ) ) continue if not result . value : self . log . debug ( "Skipping `%s` metric because the value is empty" , ensure_unicode ( metric_name ) ) continue instance_name = result . id . instance or "none" # Get the most recent value that isn't negative valid_values = [ v for v in result . value if v >= 0 ] if not valid_values : continue value = self . _transform_value ( instance , result . id . counterId , valid_values [ - 1 ] ) hostname = mor [ 'hostname' ] tags = [ 'instance:{}' . format ( ensure_unicode ( instance_name ) ) ] if not hostname : # no host tags available tags . extend ( mor [ 'tags' ] ) else : hostname = to_string ( hostname ) if self . excluded_host_tags : tags . extend ( mor [ "excluded_host_tags" ] ) tags . extend ( instance . get ( 'tags' , [ ] ) ) # vsphere "rates" should be submitted as gauges (rate is # precomputed). self . gauge ( "vsphere.{}" . format ( ensure_unicode ( metric_name ) ) , value , hostname = hostname , tags = tags ) # ## <TEST-INSTRUMENTATION> custom_tags = instance . get ( 'tags' , [ ] ) + [ 'instance:{}' . format ( i_key ) ] self . histogram ( 'datadog.agent.vsphere.metric_colection.time' , t . total ( ) , tags = custom_tags )