Python脚本 - 查询磁盘的读写次数信息
测试系统为:Centos 6.7
Python版本为: 3.6.4
脚本功能:查看指定磁盘的读写及时间等相关信息
#!/usr/bin/env python3
from collections import namedtuple
Disk = namedtuple('Disk','major_number minor_number device_name read_count read_merged_count read_sections time_spent_reading write_count write_merged_count write_sections time_spent_write io_requests time_spent_doing_io weighted_time_spent_doing_do')
def get_disk_info(device):
with open('/proc/diskstats') as f:
for line in f:
if line.split()[2] == device:
return Disk(*line.split())
raise RuntimeError('device ({0}) not found!'.format(device))
def main():
disk_info = get_disk_info('sda1')
# print(disk_info)
print('磁盘读写次数:{0}'.format(disk_info.write_count))
print('磁盘写字节数:{0}'.format(int(disk_info.write_sections) * 512))
print('磁盘写时间:{0}'.format(disk_info.time_spent_write))
if __name__ == '__main__':
main()
所有巧合的是要么是上天注定要么是一个人偷偷的在努力。

浙公网安备 33010602011771号