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