(
        self, name, metric, send_histograms_buckets=True, custom_tags=None, 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, name, metric, send_histograms_buckets=True, custom_tags=None, hostname=None
    ):
        """
        Extracts metrics from a prometheus histogram and sends them as gauges
        """
        if custom_tags is None:
            custom_tags = []
        # histograms do not have a value attribute
        val = getattr(metric, self.METRIC_TYPES[4]).sample_count
        if self._is_value_valid(val):
            if send_histograms_buckets:
                self._submit_gauge("{}.count".format(name), val, metric, custom_tags=custom_tags + ["upper_bound:none"])
            else:
                self._submit_gauge("{}.count".format(name), val, metric, custom_tags)
        else:
            self.log.debug("Metric value is not supported for metric %s.count.", name)
        val = getattr(metric, self.METRIC_TYPES[4]).sample_sum
        if self._is_value_valid(val):
            self._submit_gauge("{}.sum".format(name), val, metric, custom_tags)
        else:
            self.log.debug("Metric value is not supported for metric %s.sum.", name)
        if send_histograms_buckets:
            for bucket in getattr(metric, self.METRIC_TYPES[4]).bucket:
                val = bucket.cumulative_count
                limit = bucket.upper_bound
                if self._is_value_valid(val):
                    self._submit_gauge(
                        "{}.count".format(name),
                        val,
                        metric,
                        custom_tags=custom_tags + ["upper_bound:{}".format(limit)],
                        hostname=hostname,
                    )
                else:
                    self.log.debug("Metric value is not supported for metric %s.count.", name)
def _submit_gauges_from_histogram ( self , name , metric , send_histograms_buckets = True , custom_tags = None , hostname = None ) : if custom_tags is None : custom_tags = [ ] # histograms do not have a value attribute val = getattr ( metric , self . METRIC_TYPES [ 4 ] ) . sample_count if self . _is_value_valid ( val ) : if send_histograms_buckets : self . _submit_gauge ( "{}.count" . format ( name ) , val , metric , custom_tags = custom_tags + [ "upper_bound:none" ] ) else : self . _submit_gauge ( "{}.count" . format ( name ) , val , metric , custom_tags ) else : self . log . debug ( "Metric value is not supported for metric %s.count." , name ) val = getattr ( metric , self . METRIC_TYPES [ 4 ] ) . sample_sum if self . _is_value_valid ( val ) : self . _submit_gauge ( "{}.sum" . format ( name ) , val , metric , custom_tags ) else : self . log . debug ( "Metric value is not supported for metric %s.sum." , name ) if send_histograms_buckets : for bucket in getattr ( metric , self . METRIC_TYPES [ 4 ] ) . bucket : val = bucket . cumulative_count limit = bucket . upper_bound if self . _is_value_valid ( val ) : self . _submit_gauge ( "{}.count" . format ( name ) , val , metric , custom_tags = custom_tags + [ "upper_bound:{}" . format ( limit ) ] , hostname = hostname , ) else : self . log . debug ( "Metric value is not supported for metric %s.count." , name )