def count_objects_by_tags(self, metric, scraper_config):
        """ Count objects by whitelisted 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 = [
                self._label_to_tag(l, sample[self.SAMPLE_LABELS], scraper_config) for l in config['allowed_labels']
            ] + 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))