(self, response)
Parse the MetricFamily from a valid requests.Response object to provide a MetricFamily object (see [0])

        The text format uses iter_lines() generator.

        The protobuf format directly parse the response.content property searching for Prometheus messages of type
        MetricFamily [0] delimited by a varint32 [1] when the content-type is a `application/vnd.google.protobuf`.

        [0] https://github.com/prometheus/client_model/blob/086fe7ca28bde6cec2acd5223423c1475a362858/metrics.proto#L76-%20%20L81  # noqa: E501
        [1] https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/AbstractMessageLite#writeDelimitedTo(java.io.OutputStream)  # noqa: E501

        :param response: requests.Response
        :return: metrics_pb2.MetricFamily()
Parse the MetricFamily from a valid requests.Response object to provide a MetricFamily object (see [0])
Parse the MetricFamily from a valid requests . Response object to provide a MetricFamily object ( see [ 0 ] )
def parse_metric_family(self, response):
        """
        Parse the MetricFamily from a valid requests.Response object to provide a MetricFamily object (see [0])

        The text format uses iter_lines() generator.

        The protobuf format directly parse the response.content property searching for Prometheus messages of type
        MetricFamily [0] delimited by a varint32 [1] when the content-type is a `application/vnd.google.protobuf`.

        [0] https://github.com/prometheus/client_model/blob/086fe7ca28bde6cec2acd5223423c1475a362858/metrics.proto#L76-%20%20L81  # noqa: E501
        [1] https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/AbstractMessageLite#writeDelimitedTo(java.io.OutputStream)  # noqa: E501

        :param response: requests.Response
        :return: metrics_pb2.MetricFamily()
        """
        if 'application/vnd.google.protobuf' in response.headers['Content-Type']:
            n = 0
            buf = response.content
            while n < len(buf):
                msg_len, new_pos = _DecodeVarint32(buf, n)
                n = new_pos
                msg_buf = buf[n : n + msg_len]
                n += msg_len

                message = metrics_pb2.MetricFamily()
                message.ParseFromString(msg_buf)
                message.name = self.remove_metric_prefix(message.name)

                # Lookup type overrides:
                if self.type_overrides and message.name in self.type_overrides:
                    new_type = self.type_overrides[message.name]
                    if new_type in self.METRIC_TYPES:
                        message.type = self.METRIC_TYPES.index(new_type)
                    else:
                        self.log.debug("type override %s for %s is not a valid type name", new_type, message.name)
                yield message

        elif 'text/plain' in response.headers['Content-Type']:
            input_gen = response.iter_lines(chunk_size=self.REQUESTS_CHUNK_SIZE, decode_unicode=True)
            if self._text_filter_blacklist:
                input_gen = self._text_filter_input(input_gen)

            messages = defaultdict(list)  # map with the name of the element (before the labels)
            # and the list of occurrences with labels and values

            obj_map = {}  # map of the types of each metrics
            obj_help = {}  # help for the metrics
            for metric in text_fd_to_metric_families(input_gen):
                metric.name = self.remove_metric_prefix(metric.name)
                metric_name = "%s_bucket" % metric.name if metric.type == "histogram" else metric.name
                metric_type = self.type_overrides.get(metric_name, metric.type)
                if metric_type == "untyped" or metric_type not in self.METRIC_TYPES:
                    continue

                for sample in metric.samples:
                    if (sample[0].endswith("_sum") or sample[0].endswith("_count")) and metric_type in [
                        "histogram",
                        "summary",
                    ]:
                        messages[sample[0]].append({"labels": sample[1], 'value': sample[2]})
                    else:
                        messages[metric_name].append({"labels": sample[1], 'value': sample[2]})

                obj_map[metric.name] = metric_type
                obj_help[metric.name] = metric.documentation

            for _m in obj_map:
                if _m in messages or (obj_map[_m] == 'histogram' and ('{}_bucket'.format(_m) in messages)):
                    yield self._extract_metric_from_map(_m, messages, obj_map, obj_help)
        else:
            raise UnknownFormatError('Unsupported content-type provided: {}'.format(response.headers['Content-Type']))
def parse_metric_family ( self , response ) : if 'application/vnd.google.protobuf' in response . headers [ 'Content-Type' ] : n = 0 buf = response . content while n < len ( buf ) : msg_len , new_pos = _DecodeVarint32 ( buf , n ) n = new_pos msg_buf = buf [ n : n + msg_len ] n += msg_len message = metrics_pb2 . MetricFamily ( ) message . ParseFromString ( msg_buf ) message . name = self . remove_metric_prefix ( message . name ) # Lookup type overrides: if self . type_overrides and message . name in self . type_overrides : new_type = self . type_overrides [ message . name ] if new_type in self . METRIC_TYPES : message . type = self . METRIC_TYPES . index ( new_type ) else : self . log . debug ( "type override %s for %s is not a valid type name" , new_type , message . name ) yield message elif 'text/plain' in response . headers [ 'Content-Type' ] : input_gen = response . iter_lines ( chunk_size = self . REQUESTS_CHUNK_SIZE , decode_unicode = True ) if self . _text_filter_blacklist : input_gen = self . _text_filter_input ( input_gen ) messages = defaultdict ( list ) # map with the name of the element (before the labels) # and the list of occurrences with labels and values obj_map = { } # map of the types of each metrics obj_help = { } # help for the metrics for metric in text_fd_to_metric_families ( input_gen ) : metric . name = self . remove_metric_prefix ( metric . name ) metric_name = "%s_bucket" % metric . name if metric . type == "histogram" else metric . name metric_type = self . type_overrides . get ( metric_name , metric . type ) if metric_type == "untyped" or metric_type not in self . METRIC_TYPES : continue for sample in metric . samples : if ( sample [ 0 ] . endswith ( "_sum" ) or sample [ 0 ] . endswith ( "_count" ) ) and metric_type in [ "histogram" , "summary" , ] : messages [ sample [ 0 ] ] . append ( { "labels" : sample [ 1 ] , 'value' : sample [ 2 ] } ) else : messages [ metric_name ] . append ( { "labels" : sample [ 1 ] , 'value' : sample [ 2 ] } ) obj_map [ metric . name ] = metric_type obj_help [ metric . name ] = metric . documentation for _m in obj_map : if _m in messages or ( obj_map [ _m ] == 'histogram' and ( '{}_bucket' . format ( _m ) in messages ) ) : yield self . _extract_metric_from_map ( _m , messages , obj_map , obj_help ) else : raise UnknownFormatError ( 'Unsupported content-type provided: {}' . format ( response . headers [ 'Content-Type' ] ) )