def _extract_metrics(self, results, metrics, tag_by, wmi, tag_queries, constant_tags):
        if len(results) > 1 and tag_by is None:
            raise Exception('WMI query returned multiple rows but no `tag_by` value was given. '
                            'metrics=%s' % metrics)

        for res in results:
            tags = []

            # include any constant tags...
            if constant_tags:
                tags.extend(constant_tags)

            # if tag_queries is specified then get attributes from other classes and use as a tags
            if tag_queries:
                for query in tag_queries:
                    link_source_property = int(getattr(res, query[0]))
                    target_class = query[1]
                    link_target_class_property = query[2]
                    target_property = query[3]

                    link_results = \
                        wmi.query("SELECT {0} FROM {1} WHERE {2} = {3}"
                                  .format(target_property, target_class,
                                          link_target_class_property, link_source_property))

                    if len(link_results) != 1:
                        self.log.warning("Failed to find {0} for {1} {2}. No metrics gathered"
                                         .format(target_class, link_target_class_property,
                                                 link_source_property))
                        continue

                    link_value = str(getattr(link_results[0], target_property)).lower()
                    tags.append("{0}:{1}".format(target_property.lower(),
                                "_".join(link_value.split())))

            # Grab the tag from the result if there's a `tag_by` value (e.g.: "name:jenkins")
            # Strip any #instance off the value when `tag_queries` is set (gives us unique tags)
            if tag_by:
                tag_value = str(getattr(res, tag_by)).lower()
                if tag_queries and tag_value.find("#") > 0:
                    tag_value = tag_value[:tag_value.find("#")]
                tags.append('%s:%s' % (tag_by.lower(), tag_value))

            if len(tags) == 0:
                tags = None

            for wmi_property, name, mtype in metrics:
                if wmi_property == UP_METRIC:
                    # Special-case metric will just submit 1 for every value
                    # returned in the result.
                    val = 1
                elif getattr(res, wmi_property):
                    val = float(getattr(res, wmi_property))
                else:
                    self.log.warning("When extracting metrics with wmi, found a null value"
                                     " for property '{0}'. Metric type of property is {1}."
                                     .format(wmi_property, mtype))
                    continue

                # Submit the metric to Datadog
                try:
                    func = getattr(self, mtype)
                except __HOLE__:
                    raise Exception('Invalid metric type: {0}'.format(mtype))

                func(name, val, tags=tags)
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/wmi_check.py/WMICheck._extract_metrics