import re
import time


def disk(machinename, sshcli):
    """
    Gets disk metrics for machine
        :param machinename: monitored machine name to add to result dict
        :param sshcli: SSHClient to the monitored machine
        :return: Metrics as a dict
    """
    stdin, stdout, stderr = sshcli.exec_command("vmstat -d -n")
    # Skip header
    stdout.readline()
    stdout.readline()

    disks = []
    line = stdout.readline()
    while line:
        data = re.split(r'[ ]+', line.strip())
        if not re.match(r'ram|loop', data[0]):
            disks.append({data[0]: data[1:11]})
        line = stdout.readline()

    return dict({
        "type":       "disk",
        "machine":    machinename,
        "ts":         time.time(),
        "disks":      disks
    })