The script is as follows:
#!/usr/bin/env python #coding:utf-8 import win32com.client import time def disk_status(): try: while 1: strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk") print "time:" + time.strftime("%Y-%m-%d %H:%M:%S") print "Device:" +'\t' + "tps" +'\t' + "kB_read/s" +'\t' + "kB_wrtn/s" +'\t' + "kB_read" +'\t' + "kB_wrtn" +'\t' +"Disk_free" for objItem in colItems: if objItem.Name != '_Total': print objItem.Name +'\t' + str(objItem.DiskTransfersPersec) +'\t' + "%0.1f" % (float(objItem.DiskReadBytesPersec)/1024) +'\t' + '\t' + "%0.1f" % (float(objItem.DiskWriteBytesPersec)/1024) +'\t' + '\t' + "%0.1f" % (float(objItem.DiskReadsPersec)/1024) +'\t' + "%0.1f" % (float(objItem.DiskWritesPersec)/1024) +'\t' + "%0.0f%%" % objItem.PercentFreeSpace #Device: show disk name #tps: Indicates the number of transfers per second output to the physical disk. A transfer is an I / O request to a physical disk. Multiple logical requests can be combined into a single I/O request to disk. Transfers are of medium size. #kB_read / s: The amount of data read from disk per second, in KB. #kB_wrtn / s: The amount of data written to disk per second, in KB. #Kb_read: Total KB read. #Kb_wrtn: The total number of KB written. #DiskTransfersPerSec: The number of disk transfers per second. #DiskReadBytesPerSec: The amount of data read from the disk per second, in Bytes. #DiskWriteBytesPerSec: The amount of data written from the disk per second, in Bytes. #PercentFreeSpace: Percent free disk print '' time.sleep(2) except (EOFError,KeyboardInterrupt): pass if __name__ == '__main__': disk_status()
Results of the:
time:2018-05-06 12:04:32 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn Disk_free C: 171 437.6 700.2 0.1 0.1 60% D: 0 0.0 0.0 0.0 0.0 4% E: 0 0.0 0.0 0.0 0.0 28% F: 0 0.0 0.0 0.0 0.0 16% G: 0 0.0 0.0 0.0 0.0 31% H: 0 0.0 0.0 0.0 0.0 31% HarddiskVolume1 0 0.0 0.0 0.0 0.0 97 % HarddiskVolume14 0 0.0 0.0 0.0 0.0 47 % HarddiskVolume15 0 0.0 0.0 0.0 0.0 96 % HarddiskVolume17 0 0.0 0.0 0.0 0.0 96 % HarddiskVolume19 0 0.0 0.0 0.0 0.0 96 % HarddiskVolume21 0 0.0 0.0 0.0 0.0 0.0 96 % HarddiskVolume23 0 0.0 0.0 0.0 0.0 96 % HarddiskVolume5 0 0.0 0.0 0.0 0.0 41 % HarddiskVolume6 0 0.0 0.0 0.0 0.0 0.0 17 %
Reference: http://blog.51cto.com/wangwei007/741083
Install win32com.client :
https://github.com/mhammond/pywin32/releases