(self, metric, scraper_config)
Sum values by allowed tags and submit counts as gauges.
Sum values by allowed tags and submit counts as gauges.
Sum values by allowed tags and submit counts as gauges .
def sum_values_by_tags(self, metric, scraper_config):
        """Sum values by allowed tags and submit counts as gauges."""
        config = self.object_count_params[metric.name]
        metric_name = "{}.{}".format(scraper_config['namespace'], config['metric_name'])
        object_counter = Counter()

        for sample in metric.samples:
            tags = []
            for l in config['allowed_labels']:
                tag = self._label_to_tag(l, sample[self.SAMPLE_LABELS], scraper_config)
                if tag is None:
                    tag = self._format_tag(l, "unknown", scraper_config)
                tags.append(tag)
            tags += scraper_config['custom_tags']
            object_counter[tuple(sorted(tags))] += sample[self.SAMPLE_VALUE]

        for tags, count in iteritems(object_counter):
            self.gauge(metric_name, count, tags=list(tags))
def sum_values_by_tags ( self , metric , scraper_config ) : config = self . object_count_params [ metric . name ] metric_name = "{}.{}" . format ( scraper_config [ 'namespace' ] , config [ 'metric_name' ] ) object_counter = Counter ( ) for sample in metric . samples : tags = [ ] for l in config [ 'allowed_labels' ] : tag = self . _label_to_tag ( l , sample [ self . SAMPLE_LABELS ] , scraper_config ) if tag is None : tag = self . _format_tag ( l , "unknown" , scraper_config ) tags . append ( tag ) tags += scraper_config [ 'custom_tags' ] object_counter [ tuple ( sorted ( tags ) ) ] += sample [ self . SAMPLE_VALUE ] for tags , count in iteritems ( object_counter ) : self . gauge ( metric_name , count , tags = list ( tags ) )