windows模拟linux命令iostat的显示

简介:
  1. # -*- coding: gbk -*- 
  2.  
  3. import win32com.client 
  4. import time 
  5.  
  6. def disk_status(): 
  7.     try
  8.         while 1
  9.             strComputer = "." 
  10.             objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator"
  11.             objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2"
  12.             colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk"
  13.             print "time:" + time.strftime("%Y-%m-%d %H:%M:%S"
  14.             print "Device:" +'\t' + "tps" +'\t' + "kB_read/s" +'\t' + "kB_wrtn/s" +'\t' + "kB_read" +'\t' + "kB_wrtn" +'\t' +"Disk_free" 
  15.             for objItem in colItems: 
  16.                 if objItem.Name != '_Total'
  17.                     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  
  18.                         
  19.                     #Device: 显示磁盘名称 
  20.                     #tps: 表示每秒钟输出到物理磁盘的传输次数。一次传输就是一个对物理磁盘的 I/O 请求。多个逻辑请求可被并为对磁盘的一个单一 I/O 请求。传输具有中等的大小。 
  21.                     #kB_read/s: 每秒从磁盘读取的数据量,单位为KB。 
  22.                     #kB_wrtn/s: 每秒从写入磁盘的数据量,单位为KB。 
  23.                     #Kb_read: 读取的 KB 总数。  
  24.                     #Kb_wrtn: 写入的 KB 总数。 
  25.                     #DiskTransfersPerSec:每秒磁盘传输次数。 
  26.                     #DiskReadBytesPerSec:每秒从磁盘读取得数据量,单位为Byte。 
  27.                     #DiskWriteBytesPerSec:每秒从磁盘写取得数据量,单位为Byte。 
  28.                     #PercentFreeSpace:可用磁盘百分比 
  29.             print '' 
  30.             time.sleep(2)  
  31.     except (EOFError,KeyboardInterrupt): 
  32.         pass 
  33. if __name__ == '__main__'
  34.     disk_status() 
 本文转自 lover007 51CTO博客,原文链接:http://blog.51cto.com/wangwei007/741083 ,如需转载请自行联系原作者

相关文章
|
1月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025080401 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025080401 (Linux, Windows) - 专业渗透测试框架
67 0
|
1月前
|
安全 Linux iOS开发
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
191 0
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
|
1月前
|
安全 Linux 生物认证
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
47 0
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
|
1月前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
109 0
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
|
1月前
|
NoSQL IDE MongoDB
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
120 0
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
2月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
641 13
|
2月前
|
安全 Linux iOS开发
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
311 0
Burp Suite Professional 2025.7 (macOS, Linux, Windows) - Web 应用安全、测试和扫描
|
1月前
|
编解码 Ubuntu Linux
时隔半年,Linux 性能重新超越 Windows 11
用户可以访问 OpenBenchmarking.org 页面查看 Windows 和 Linux 之间所有 103 项基准测试的完整结果。
55 0
|
1月前
|
Ubuntu Linux Shell
手把手教你安装适用于Linux的Windows子系统——Ubuntu
重启完成,你看看重新打开Ubuntu是不是发生了变化,等待几分钟,系统配置完成,根据提示设置用户名和密码即可