Python Script-Query disk read and write times information

Source: Internet
Author: User

The test system is: Centos 6.7

The Python version is: 3.6.4

Scripting Features: View information about read and write and time of specified disk

#!/usr/bin/env python3from Collections Import Namedtupledisk = 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 (' Disk read/write: {0} '). Format (disk_info.write_count))    print (' Number of disk writes: {0} '. Format (int (disk_info.write_sections) *)    print (' Disk Write time: {0} '. Format (disk_info.time_spent_write)) if __name__ = = ' __main__ ':    Main ()

  

  

  

Python Script-Query disk read and write times information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.