(self, metric_name, metric, scraper_config, hostname=None)
Extracts metrics from a prometheus histogram and sends them as gauges
Extracts metrics from a prometheus histogram and sends them as gauges
Extracts metrics from a prometheus histogram and sends them as gauges
def _submit_gauges_from_histogram(self, metric_name, metric, scraper_config, hostname=None):
        """
        Extracts metrics from a prometheus histogram and sends them as gauges
        """
        if scraper_config['non_cumulative_buckets']:
            self._decumulate_histogram_buckets(metric)
        for sample in metric.samples:
            val = sample[self.SAMPLE_VALUE]
            if not self._is_value_valid(val):
                self.log.debug("Metric value is not supported for metric %s", sample[self.SAMPLE_NAME])
                continue
            if self._ignore_metrics_by_label(scraper_config, metric_name, sample):
                continue
            custom_hostname = self._get_hostname(hostname, sample, scraper_config)
            if sample[self.SAMPLE_NAME].endswith("_sum") and not scraper_config['send_distribution_buckets']:
                tags = self._metric_tags(metric_name, val, sample, scraper_config, hostname)
                self._submit_distribution_count(
                    scraper_config['send_distribution_sums_as_monotonic'],
                    scraper_config['send_monotonic_with_gauge'],
                    "{}.sum".format(self._metric_name_with_namespace(metric_name, scraper_config)),
                    val,
                    tags=tags,
                    hostname=custom_hostname,
                    flush_first_value=scraper_config['_flush_first_value'],
                )
            elif sample[self.SAMPLE_NAME].endswith("_count") and not scraper_config['send_distribution_buckets']:
                tags = self._metric_tags(metric_name, val, sample, scraper_config, hostname)
                if scraper_config['send_histograms_buckets']:
                    tags.append("upper_bound:none")
                self._submit_distribution_count(
                    scraper_config['send_distribution_counts_as_monotonic'],
                    scraper_config['send_monotonic_with_gauge'],
                    "{}.count".format(self._metric_name_with_namespace(metric_name, scraper_config)),
                    val,
                    tags=tags,
                    hostname=custom_hostname,
                    flush_first_value=scraper_config['_flush_first_value'],
                )
            elif scraper_config['send_histograms_buckets'] and sample[self.SAMPLE_NAME].endswith("_bucket"):
                if scraper_config['send_distribution_buckets']:
                    self._submit_sample_histogram_buckets(metric_name, sample, scraper_config, hostname)
                elif "Inf" not in sample[self.SAMPLE_LABELS]["le"] or scraper_config['non_cumulative_buckets']:
                    sample[self.SAMPLE_LABELS]["le"] = str(float(sample[self.SAMPLE_LABELS]["le"]))
                    tags = self._metric_tags(metric_name, val, sample, scraper_config, hostname)
                    self._submit_distribution_count(
                        scraper_config['send_distribution_counts_as_monotonic'],
                        scraper_config['send_monotonic_with_gauge'],
                        "{}.count".format(self._metric_name_with_namespace(metric_name, scraper_config)),
                        val,
                        tags=tags,
                        hostname=custom_hostname,
                        flush_first_value=scraper_config['_flush_first_value'],
                    )
def _submit_gauges_from_histogram ( self , metric_name , metric , scraper_config , hostname = None ) : if scraper_config [ 'non_cumulative_buckets' ] : self . _decumulate_histogram_buckets ( metric ) for sample in metric . samples : val = sample [ self . SAMPLE_VALUE ] if not self . _is_value_valid ( val ) : self . log . debug ( "Metric value is not supported for metric %s" , sample [ self . SAMPLE_NAME ] ) continue if self . _ignore_metrics_by_label ( scraper_config , metric_name , sample ) : continue custom_hostname = self . _get_hostname ( hostname , sample , scraper_config ) if sample [ self . SAMPLE_NAME ] . endswith ( "_sum" ) and not scraper_config [ 'send_distribution_buckets' ] : tags = self . _metric_tags ( metric_name , val , sample , scraper_config , hostname ) self . _submit_distribution_count ( scraper_config [ 'send_distribution_sums_as_monotonic' ] , scraper_config [ 'send_monotonic_with_gauge' ] , "{}.sum" . format ( self . _metric_name_with_namespace ( metric_name , scraper_config ) ) , val , tags = tags , hostname = custom_hostname , flush_first_value = scraper_config [ '_flush_first_value' ] , ) elif sample [ self . SAMPLE_NAME ] . endswith ( "_count" ) and not scraper_config [ 'send_distribution_buckets' ] : tags = self . _metric_tags ( metric_name , val , sample , scraper_config , hostname ) if scraper_config [ 'send_histograms_buckets' ] : tags . append ( "upper_bound:none" ) self . _submit_distribution_count ( scraper_config [ 'send_distribution_counts_as_monotonic' ] , scraper_config [ 'send_monotonic_with_gauge' ] , "{}.count" . format ( self . _metric_name_with_namespace ( metric_name , scraper_config ) ) , val , tags = tags , hostname = custom_hostname , flush_first_value = scraper_config [ '_flush_first_value' ] , ) elif scraper_config [ 'send_histograms_buckets' ] and sample [ self . SAMPLE_NAME ] . endswith ( "_bucket" ) : if scraper_config [ 'send_distribution_buckets' ] : self . _submit_sample_histogram_buckets ( metric_name , sample , scraper_config , hostname ) elif "Inf" not in sample [ self . SAMPLE_LABELS ] [ "le" ] or scraper_config [ 'non_cumulative_buckets' ] : sample [ self . SAMPLE_LABELS ] [ "le" ] = str ( float ( sample [ self . SAMPLE_LABELS ] [ "le" ] ) ) tags = self . _metric_tags ( metric_name , val , sample , scraper_config , hostname ) self . _submit_distribution_count ( scraper_config [ 'send_distribution_counts_as_monotonic' ] , scraper_config [ 'send_monotonic_with_gauge' ] , "{}.count" . format ( self . _metric_name_with_namespace ( metric_name , scraper_config ) ) , val , tags = tags , hostname = custom_hostname , flush_first_value = scraper_config [ '_flush_first_value' ] , )