(cls, string)
Parse a string and create a metric
Parse a string and create a metric
Parse a string and create a metric
def parse(cls, string):
        """
        Parse a string and create a metric
        """
        match = re.match(r'^(?P<name>[A-Za-z0-9\.\-_]+)\s+' +
                         '(?P<value>[0-9\.]+)\s+' +
                         '(?P<timestamp>[0-9\.]+)(\n?)$',
                         string)
        try:
            groups = match.groupdict()
            # TODO: get precision from value string
            return Metric(groups['name'],
                          groups['value'],
                          float(groups['timestamp']))
        except:
            raise DiamondException(
                "Metric could not be parsed from string: %s." % string)
def parse ( cls , string ) : match = re . match ( r'^(?P<name>[A-Za-z0-9\.\-_]+)\s+' + '(?P<value>[0-9\.]+)\s+' + '(?P<timestamp>[0-9\.]+)(\n?)$' , string ) try : groups = match . groupdict ( ) # TODO: get precision from value string return Metric ( groups [ 'name' ] , groups [ 'value' ] , float ( groups [ 'timestamp' ] ) ) except : raise DiamondException ( "Metric could not be parsed from string: %s." % string )