<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def returner(ret):
    '''
    Parse the return data and return metrics to Librato.
    '''
    librato_conn = _get_librato(ret)

    q = librato_conn.new_queue()

    if ret['fun'] == 'state.highstate':
        log.debug('Found returned Highstate data.')
        # Calculate the runtimes and number of failed states.
        stats = _calculate_runtimes(ret['return'])
        log.debug('Batching Metric retcode with %s', ret['retcode'])
        q.add('saltstack.highstate.retcode',
              ret['retcode'], tags={'Name': ret['id']})

        log.debug(
            'Batching Metric num_failed_jobs with %s',
            stats['num_failed_states']
        )
        q.add('saltstack.highstate.failed_states',
              stats['num_failed_states'], tags={'Name': ret['id']})

        log.debug(
            'Batching Metric num_passed_states with %s',
            stats['num_passed_states']
        )
        q.add('saltstack.highstate.passed_states',
              stats['num_passed_states'], tags={'Name': ret['id']})

        log.debug('Batching Metric runtime with %s', stats['runtime'])
        q.add('saltstack.highstate.runtime',
              stats['runtime'], tags={'Name': ret['id']})

        log.debug(
            'Batching Metric runtime with %s',
            stats['num_failed_states'] + stats['num_passed_states']
        )
        q.add('saltstack.highstate.total_states', stats[
              'num_failed_states'] + stats['num_passed_states'], tags={'Name': ret['id']})

    log.info('Sending metrics to Librato.')
    q.submit()