(self, wmi_sampler, tag_by, tag_queries, constant_tags)
return extracted_metrics
Extract and tag metrics from the WMISampler.

        Raise when multiple WMIObject were returned by the sampler with no `tag_by` specified.

        Returns: List of WMIMetric
        ```
        [
            WMIMetric("freemegabytes", 19742, ["name:_total"]),
            WMIMetric("avgdiskbytesperwrite", 1536, ["name:c:"]),
        ]
        ```
Extract and tag metrics from the WMISampler.
Extract and tag metrics from the WMISampler .
def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags):
        # type: (WMISampler, str, List[List[str]], List[str]) -> List[WMIMetric]
        """
        Extract and tag metrics from the WMISampler.

        Raise when multiple WMIObject were returned by the sampler with no `tag_by` specified.

        Returns: List of WMIMetric
        ```
        [
            WMIMetric("freemegabytes", 19742, ["name:_total"]),
            WMIMetric("avgdiskbytesperwrite", 1536, ["name:c:"]),
        ]
        ```
        """
        if len(wmi_sampler) > 1 and not tag_by:
            raise MissingTagBy(
                u"WMI query returned multiple rows but no `tag_by` value was given."
                " class={wmi_class} - properties={wmi_properties} - filters={filters}".format(
                    wmi_class=wmi_sampler.class_name,
                    wmi_properties=wmi_sampler.property_names,
                    filters=wmi_sampler.filters,
                )
            )

        extracted_metrics = []
        tag_by = tag_by.lower()

        for wmi_obj in wmi_sampler:
            tags = list(constant_tags) if constant_tags else []

            # Tag with `tag_queries` parameter
            for query in tag_queries:
                try:
                    tags.append(self._get_tag_query_tag(wmi_sampler, wmi_obj, query))
                except TagQueryUniquenessFailure:
                    continue

            for wmi_property, wmi_value in iteritems(wmi_obj):
                # skips any property not in arguments since SWbemServices.ExecQuery will return key prop properties
                # https://msdn.microsoft.com/en-us/library/aa393866(v=vs.85).aspx

                # skip wmi_property "foo,bar"; there will be a separate wmi_property for each "foo" and "bar"
                if ',' in wmi_property:
                    continue

                normalized_wmi_property = wmi_property.lower()
                for s in wmi_sampler.property_names:
                    if normalized_wmi_property in s.lower():
                        # wmi_property: "foo" should be found in property_names ["foo,bar", "name"]
                        break
                else:
                    continue
                # Tag with `tag_by` parameter
                for t in tag_by.split(','):
                    t = t.strip()
                    if wmi_property == t:
                        tag_value = str(wmi_value).lower()
                        if tag_queries and tag_value.find("#") > 0:
                            tag_value = tag_value[: tag_value.find("#")]

                        tags.append("{name}:{value}".format(name=t, value=tag_value))
                        continue

                # No metric extraction on 'Name' and properties in tag_by
                if wmi_property == 'name' or normalized_wmi_property in tag_by.lower():
                    continue

                try:
                    extracted_metrics.append(WMIMetric(wmi_property, float(wmi_value), tags))
                except ValueError:
                    self.log.warning(
                        u"When extracting metrics with WMI, found a non digit value for property '%s'.", wmi_property
                    )
                    continue
                except TypeError:
                    self.log.warning(u"When extracting metrics with WMI, found a missing property '%s'", wmi_property)
                    continue
        return extracted_metrics
def _extract_metrics ( self , wmi_sampler , tag_by , tag_queries , constant_tags ) : # type: (WMISampler, str, List[List[str]], List[str]) -> List[WMIMetric] if len ( wmi_sampler ) > 1 and not tag_by : raise MissingTagBy ( u"WMI query returned multiple rows but no `tag_by` value was given." " class={wmi_class} - properties={wmi_properties} - filters={filters}" . format ( wmi_class = wmi_sampler . class_name , wmi_properties = wmi_sampler . property_names , filters = wmi_sampler . filters , ) ) extracted_metrics = [ ] tag_by = tag_by . lower ( ) for wmi_obj in wmi_sampler : tags = list ( constant_tags ) if constant_tags else [ ] # Tag with `tag_queries` parameter for query in tag_queries : try : tags . append ( self . _get_tag_query_tag ( wmi_sampler , wmi_obj , query ) ) except TagQueryUniquenessFailure : continue for wmi_property , wmi_value in iteritems ( wmi_obj ) : # skips any property not in arguments since SWbemServices.ExecQuery will return key prop properties # https://msdn.microsoft.com/en-us/library/aa393866(v=vs.85).aspx # skip wmi_property "foo,bar"; there will be a separate wmi_property for each "foo" and "bar" if ',' in wmi_property : continue normalized_wmi_property = wmi_property . lower ( ) for s in wmi_sampler . property_names : if normalized_wmi_property in s . lower ( ) : # wmi_property: "foo" should be found in property_names ["foo,bar", "name"] break else : continue # Tag with `tag_by` parameter for t in tag_by . split ( ',' ) : t = t . strip ( ) if wmi_property == t : tag_value = str ( wmi_value ) . lower ( ) if tag_queries and tag_value . find ( "#" ) > 0 : tag_value = tag_value [ : tag_value . find ( "#" ) ] tags . append ( "{name}:{value}" . format ( name = t , value = tag_value ) ) continue # No metric extraction on 'Name' and properties in tag_by if wmi_property == 'name' or normalized_wmi_property in tag_by . lower ( ) : continue try : extracted_metrics . append ( WMIMetric ( wmi_property , float ( wmi_value ) , tags ) ) except ValueError : self . log . warning ( u"When extracting metrics with WMI, found a non digit value for property '%s'." , wmi_property ) continue except TypeError : self . log . warning ( u"When extracting metrics with WMI, found a missing property '%s'" , wmi_property ) continue return extracted_metrics