(self, buf)
return metrics, mode
Parse `mntr` command's content.
        `buf` is a readable file-like object

        Returns: a tuple (metrics, mode)
        if mode == 'inactive', metrics will be None
Parse `mntr` command's content.
        `buf` is a readable file-like object
Parse mntr command s content . buf is a readable file - like object
def parse_mntr(self, buf):
        """
        Parse `mntr` command's content.
        `buf` is a readable file-like object

        Returns: a tuple (metrics, mode)
        if mode == 'inactive', metrics will be None
        """
        buf.seek(0)
        first = buf.readline()  # First is version string or error
        if first == 'This ZooKeeper instance is not currently serving requests':
            return None, 'inactive'

        metrics = []
        mode = 'inactive'
        for line in buf:
            try:
                tags = []
                m = re.match(self.METRIC_TAGGED_PATTERN, line)
                if m:
                    key, tag_name, tag_val, value = m.groups()
                    tags.append('{}:{}'.format(tag_name, tag_val))
                else:
                    try:
                        key, value = line.split()
                    except ValueError as e:
                        self.log.debug("Unexpected 'mntr' output `%s`: %s", line, str(e))
                        continue

                if key == "zk_server_state":
                    mode = value.lower()
                    continue

                # we are parsing version from the `stat` output for now
                if key == 'zk_version':
                    continue

                metric_name = self.normalize_metric_label(key)
                metric_type = "rate" if key in self._MNTR_RATES else "gauge"

                if value == 'NaN':
                    self.log.debug('Metric value "%s" is not supported for metric %s', value, key)
                    continue
                else:
                    metric_value = int(float(value))

                metrics.append(ZKMetric(metric_name, metric_value, metric_type, tags))

            except ValueError as e:
                self.log.warning("Cannot format `mntr` value from `%s`: %s", line, str(e))

            except Exception:
                self.log.exception("Unexpected exception occurred while parsing `mntr` command content:\n%s", buf)

        return metrics, mode
def parse_mntr ( self , buf ) : buf . seek ( 0 ) first = buf . readline ( ) # First is version string or error if first == 'This ZooKeeper instance is not currently serving requests' : return None , 'inactive' metrics = [ ] mode = 'inactive' for line in buf : try : tags = [ ] m = re . match ( self . METRIC_TAGGED_PATTERN , line ) if m : key , tag_name , tag_val , value = m . groups ( ) tags . append ( '{}:{}' . format ( tag_name , tag_val ) ) else : try : key , value = line . split ( ) except ValueError as e : self . log . debug ( "Unexpected 'mntr' output `%s`: %s" , line , str ( e ) ) continue if key == "zk_server_state" : mode = value . lower ( ) continue # we are parsing version from the `stat` output for now if key == 'zk_version' : continue metric_name = self . normalize_metric_label ( key ) metric_type = "rate" if key in self . _MNTR_RATES else "gauge" if value == 'NaN' : self . log . debug ( 'Metric value "%s" is not supported for metric %s' , value , key ) continue else : metric_value = int ( float ( value ) ) metrics . append ( ZKMetric ( metric_name , metric_value , metric_type , tags ) ) except ValueError as e : self . log . warning ( "Cannot format `mntr` value from `%s`: %s" , line , str ( e ) ) except Exception : self . log . exception ( "Unexpected exception occurred while parsing `mntr` command content:\n%s" , buf ) return metrics , mode