import time


def get_dpu_metrics(dpu_data, ts=None):
    """
    Return a list of DPU metrics.

    Expects a dict of DPU items returned from ``get_dpu_data``.
    """
    ts = ts or time.time()

    output = []

    for name, data in dpu_data.items():
        output.append((
            'datasift.dpu.streams.{}.dpu'.format(name), (ts, data['dpu'])))
        output.append((
            'datasift.dpu.streams.{}.count'.format(name),
            (ts, data['detail']['in']['count'])))

        for stream_name, stream_data in (
            data['detail']['in']['targets'].items()
        ):
            stream_name = stream_name.replace('.', '-')
            output.append((
                'datasift.dpu.streams.{}.targets.{}.dpu'.format(
                    name, stream_name),
                (ts, stream_data['dpu'])))
            output.append((
                'datasift.dpu.streams.{}.targets.{}.count'.format(
                    name, stream_name),
                (ts, stream_data['count'])))

    return output