• 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()
    

      

      

      

  • 相关阅读:
    2016第13周四
    2016第13周周三
    2016第13周二
    2016第13周一
    2016第12周日
    2016第11周五
    2016第11周四
    前端的自我成长
    Java单例模式和volatile关键字
    大约 Apple Metal API 一些想法
  • 原文地址:https://www.cnblogs.com/dachenzi/p/8232385.html
Copyright © 2020-2023  润新知