首页 > 编程语言 > 详细

Python脚本 - 查询磁盘的读写次数信息

时间:2018-01-07 23:11:09      阅读:219      评论:0      收藏:0      [点我收藏+]

测试系统为: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()

  

  

  

Python脚本 - 查询磁盘的读写次数信息

原文:https://www.cnblogs.com/dachenzi/p/8232385.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!