'Schema of a dogstatsd packet:
<name>:<value>|<metric_type>|@<sample_rate>|#<tag1_name>:<tag1_value>,<tag2_name>:<tag2_value>:<value>|<metric_type>...'

def parse_metric_packet(self, packet):

    parsed_packets = []
    name_and_metadata = packet.split(':', 1)
    if (len(name_and_metadata) != 2):
        raise Exception((u'Unparseable    metric    packet:    %s' % packet))
    name = name_and_metadata[0]
    broken_split = name_and_metadata[1].split(':')
    data = []
    partial_datum = None
    for token in broken_split:
        if (partial_datum is None):
            partial_datum = token
        elif ('|' not in token):
            partial_datum += (':' + token)
        else:
            data.append(partial_datum)
            partial_datum = token
    data.append(partial_datum)
    for datum in data:
        value_and_metadata = datum.split('|')
        if (len(value_and_metadata) < 2):
            raise Exception((u'Unparseable    metric    packet:    %s' % packet))
        raw_value = value_and_metadata[0]
        metric_type = value_and_metadata[1]
        if (metric_type in self.ALLOW_STRINGS):
            value = raw_value
        elif (metric_type in self.IGNORE_TYPES):
            continue
        else:
            try:
                value = int(raw_value)
            except ValueError:
                try:
                    value = float(raw_value)
                except ValueError:
                    raise Exception((u'Metric    value    must    be    a    number:    %s,    %s' % (name, raw_value)))
        sample_rate = 1
        tags = None
        try:
            for m in value_and_metadata[2:]:
                if (m[0] == '@'):
                    sample_rate = float(m[1:])
                    sample_rate = (1 if ((sample_rate < 0) or (sample_rate > 1)) else sample_rate)
                elif (m[0] == '#'):
                    tags = tuple(sorted(m[1:].split(',')))
        except IndexError:
            log.warning(u'Incorrect    metric    metadata:    metric_name:%s,    metadata:%s', name, u'    '.join(value_and_metadata[2:]))
        parsed_packets.append((name, value, metric_type, tags, sample_rate))
    return parsed_packets
