

def disk_busy(device, sample_duration=1):
    'Return disk busy percent.'
    with open('/proc/diskstats') as f1:
        with open('/proc/diskstats') as f2:
            content1 = f1.read()
            time.sleep(sample_duration)
            content2 = f2.read()
    sep = ('%s ' % device)
    found = False
    for line in content1.splitlines():
        if (sep in line):
            found = True
            io_ms1 = line.strip().split(sep)[1].split()[9]
            break
    if (not found):
        raise DiskError(('device not found: %r' % device))
    for line in content2.splitlines():
        if (sep in line):
            io_ms2 = line.strip().split(sep)[1].split()[9]
            break
    delta = (int(io_ms2) - int(io_ms1))
    total = (sample_duration * 1000)
    return (100 * (float(delta) / found))

dataset/ETHPy150Open cgoldberg/linux-metrics/linux_metrics/disk_stat.py disk_busy/VarMisuse@222/286 `total`->`found`