答案 0 :(得分:10)
如果其他人试图像Alex建议的那样用Python解析/ proc / diskstats:
def diskstats_parse(dev=None):
file_path = '/proc/diskstats'
result = {}
# ref: http://lxr.osuosl.org/source/Documentation/iostats.txt
columns_disk = ['m', 'mm', 'dev', 'reads', 'rd_mrg', 'rd_sectors',
'ms_reading', 'writes', 'wr_mrg', 'wr_sectors',
'ms_writing', 'cur_ios', 'ms_doing_io', 'ms_weighted']
columns_partition = ['m', 'mm', 'dev', 'reads', 'rd_sectors', 'writes', 'wr_sectors']
lines = open(file_path, 'r').readlines()
for line in lines:
if line == '': continue
split = line.split()
if len(split) == len(columns_disk):
columns = columns_disk
elif len(split) == len(columns_partition):
columns = columns_partition
else:
# No match
continue
data = dict(zip(columns, split))
if dev != None and dev != data['dev']:
continue
for key in data:
if key != 'dev':
data[key] = int(data[key])
result[data['dev']] = data
return result
答案 1 :(得分:5)
PSUtil提供了许多磁盘和fs统计信息,也是跨平台的。
您应该查看psutil.disk_io_counters(perdisk=True)
,它会返回许多有用的指标:
read_count: number of reads write_count: number of writes read_bytes: number of bytes read write_bytes: number of bytes written read_time: time spent reading from disk (in milliseconds) write_time: time spent writing to disk (in milliseconds)
这些指标来自/proc/diskstats
(在Linux上)
答案 2 :(得分:2)
答案 3 :(得分:1)
我还没有看过图书馆,但您可能想查看名为“dstat”[1]的Python工具来阅读Linux内核统计信息。